Skip to content

Commit

Permalink
Update rust version to 1.83 and fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Nov 28, 2024
1 parent 069338a commit d11fb2a
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 117 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.82-alpine AS Builder
FROM rust:1.83-alpine AS Builder

LABEL maintainer="Ilya Builuk <[email protected]>" \
org.opencontainers.image.title="A Vehicle Routing Problem solver CLI" \
Expand Down
2 changes: 1 addition & 1 deletion experiments/heuristic-research/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'de> Deserialize<'de> for Coordinate {

struct CoordinateVisitor;

impl<'de> Visitor<'de> for CoordinateVisitor {
impl Visitor<'_> for CoordinateVisitor {
type Value = Coordinate;

fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
Expand Down
6 changes: 3 additions & 3 deletions experiments/heuristic-research/src/solver/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ where
self.inner.cmp(a, b)
}

fn select<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn select(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
Box::new(self.inner.select().inspect(|&individual| {
self.acquire().on_select.entry(self.generation).or_default().push(individual.into());
}))
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
self.inner.ranked()
}

fn all<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn all(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
self.inner.all()
}

Expand Down
2 changes: 1 addition & 1 deletion rosomaxa/src/algorithms/gsom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait Storage: Display + Send + Sync {
fn add(&mut self, input: Self::Item);

/// Returns iterator over all data.
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Item> + 'a>;
fn iter(&self) -> Box<dyn Iterator<Item = &'_ Self::Item> + '_>;

/// Removes and returns all data from the storage.
fn drain<R>(&mut self, range: R) -> Vec<Self::Item>
Expand Down
4 changes: 2 additions & 2 deletions rosomaxa/src/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ impl HeuristicContext for VectorContext {
self.inner_context.objective()
}

fn selected<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a> {
fn selected(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_> {
self.inner_context.population.select()
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a> {
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_> {
self.inner_context.population.ranked()
}

Expand Down
2 changes: 1 addition & 1 deletion rosomaxa/src/hyper/dynamic_selective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct SearchAction<'a, C, O, S> {
operator_name: String,
}

impl<'a, C, O, S> Clone for SearchAction<'a, C, O, S> {
impl<C, O, S> Clone for SearchAction<'_, C, O, S> {
fn clone(&self) -> Self {
Self { operator: self.operator.clone(), operator_name: self.operator_name.clone() }
}
Expand Down
10 changes: 5 additions & 5 deletions rosomaxa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#[cfg(test)]
#[path = "../tests/helpers/mod.rs"]
#[macro_use]
pub mod helpers;
pub(crate) mod helpers;

pub mod algorithms;
pub mod evolution;
Expand Down Expand Up @@ -89,10 +89,10 @@ pub trait HeuristicContext: Send + Sync {
fn objective(&self) -> &Self::Objective;

/// Returns selected solutions base on current context.
fn selected<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a>;
fn selected(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_>;

/// Returns subset of solutions within their rank sorted according their quality.
fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a>;
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_>;

/// Returns current statistic used to track the search progress.
fn statistics(&self) -> &HeuristicStatistics;
Expand Down Expand Up @@ -194,11 +194,11 @@ where
&self.objective
}

fn selected<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a> {
fn selected(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_> {
self.population.select()
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a> {
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_> {
self.population.ranked()
}

Expand Down
6 changes: 3 additions & 3 deletions rosomaxa/src/population/elitism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
self.objective.total_order(a, b)
}

fn select<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn select(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
let selection_size = match &self.speed {
Some(HeuristicSpeed::Slow { ratio, .. }) => (self.selection_size as Float * ratio).max(1.).round() as usize,
_ => self.selection_size,
Expand All @@ -88,11 +88,11 @@ where
}
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
Box::new(self.individuals.iter())
}

fn all<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn all(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
Box::new(self.individuals.iter())
}

Expand Down
6 changes: 3 additions & 3 deletions rosomaxa/src/population/greedy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ where
self.objective.total_order(a, b)
}

fn select<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn select(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
if let Some(best_known) = self.best_known.as_ref() {
Box::new(repeat(best_known).take(self.selection_size))
} else {
Box::new(empty())
}
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
Box::new(self.best_known.iter())
}

fn all<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn all(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
Box::new(self.best_known.iter())
}

Expand Down
12 changes: 6 additions & 6 deletions rosomaxa/src/population/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ pub trait HeuristicPopulation: Send + Sync {
fn add(&mut self, individual: Self::Individual) -> bool;

/// Informs population about new generation event. This is time for the population
/// to decide whether selection phase has to be changed.
/// to decide whether the selection phase has to be changed.
fn on_generation(&mut self, statistics: &HeuristicStatistics);

/// Compares two solutions the same way as population does.
/// Compares two solutions the same way as the population does.
fn cmp(&self, a: &Self::Individual, b: &Self::Individual) -> Ordering;

/// Selects parents from the population based on current selection phase.
fn select<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a>;
/// Selects parents from the population based on the current selection phase.
fn select(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_>;

/// Returns subset of individuals within their rank sorted according their quality.
fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a>;
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_>;

/// Returns all individuals in arbitrary order.
fn all<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a>;
fn all(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_>;

/// Returns population size.
fn size(&self) -> usize;
Expand Down
8 changes: 4 additions & 4 deletions rosomaxa/src/population/rosomaxa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
self.elite.cmp(a, b)
}

fn select<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn select(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
match &self.phase {
RosomaxaPhases::Initial { solutions } => Box::new(solutions.iter()),
RosomaxaPhases::Exploration { network, coordinates, selection_size, statistics, .. } => {
Expand Down Expand Up @@ -173,11 +173,11 @@ where
}
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
self.elite.ranked()
}

fn all<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
fn all(&self) -> Box<dyn Iterator<Item = &'_ Self::Individual> + '_> {
match &self.phase {
RosomaxaPhases::Exploration { network, .. } => {
Box::new(self.elite.all().chain(network.get_nodes().flat_map(|node| node.storage.population.all())))
Expand Down Expand Up @@ -472,7 +472,7 @@ where
self.population.add(input);
}

fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Item> + 'a> {
fn iter(&self) -> Box<dyn Iterator<Item = &'_ Self::Item> + '_> {
Box::new(self.population.ranked())
}

Expand Down
2 changes: 1 addition & 1 deletion rosomaxa/tests/helpers/algorithms/gsom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Storage for DataStorage {
self.data.push(input);
}

fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Item> + 'a> {
fn iter(&self) -> Box<dyn Iterator<Item = &'_ Self::Item> + '_> {
Box::new(self.data.iter())
}

Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/algorithms/structures/bitvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const BITS_IN_BLOCK: usize = std::mem::size_of::<u8>() * 8;

impl BitVec {
pub fn new(length: usize) -> Self {
let block_count = (length + BITS_IN_BLOCK - 1) / BITS_IN_BLOCK;
let block_count = length.div_ceil(BITS_IN_BLOCK);
Self { blocks: vec![0; block_count], length }
}

Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/construction/heuristics/insertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Ord for InsertionCost {
}
}

impl<'a, B> Add<B> for &'a InsertionCost
impl<B> Add<B> for &InsertionCost
where
B: Borrow<InsertionCost>,
{
Expand Down Expand Up @@ -187,7 +187,7 @@ where
}
}

impl<'a, B> Sub<B> for &'a InsertionCost
impl<B> Sub<B> for &InsertionCost
where
B: Borrow<InsertionCost>,
{
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/construction/heuristics/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pub fn group_routes_by_proximity(insertion_ctx: &InsertionContext) -> Vec<Vec<us

fn get_values_from_route_state<'a>(
insertion_ctx: &'a InsertionContext,
state_value_fn: impl Fn(&'a RouteState) -> Option<&Float> + 'a,
state_value_fn: impl Fn(&'a RouteState) -> Option<&'a Float> + 'a,
) -> impl Iterator<Item = Float> + 'a {
insertion_ctx
.solution
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/construction/heuristics/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl LegSelection {
};

let total_legs = route_ctx.route().tour.legs().size_hint().0;
let visit_legs = if total_legs > skip { total_legs - skip } else { 0 };
let visit_legs = total_legs.saturating_sub(skip);

if visit_legs < greedy_threshold {
None
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
#[cfg(test)]
#[path = "../tests/helpers/mod.rs"]
#[macro_use]
pub mod helpers;
pub(crate) mod helpers;

#[macro_use]
pub mod macros;
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/models/solution/tour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ impl Tour {
self.activities.iter_mut()
}

/// Returns all activities in tour for specific job.
pub fn job_activities<'a>(&'a self, job: &'a Job) -> impl Iterator<Item = &Activity> + 'a {
/// Returns all activities in tour for a specific job.
pub fn job_activities<'a>(&'a self, job: &'a Job) -> impl Iterator<Item = &'a Activity> + 'a {
self.activities.iter().filter(move |a| a.has_same_job(job))
}

Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ impl HeuristicContext for RefinementContext {
self.inner_context.objective()
}

fn selected<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a> {
fn selected(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_> {
self.inner_context.selected()
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Solution> + 'a> {
fn ranked(&self) -> Box<dyn Iterator<Item = &'_ Self::Solution> + '_> {
self.inner_context.ranked()
}

Expand Down
16 changes: 0 additions & 16 deletions vrp-core/tests/helpers/construction/heuristics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,18 @@ impl TestInsertionContextBuilder {
self
}

pub fn with_solution(&mut self, solution: SolutionContext) -> &mut Self {
self.solution = Some(solution);
self
}

pub fn with_registry(&mut self, registry: Registry) -> &mut Self {
let goal = self.ensure_problem().goal.as_ref();
self.ensure_solution().registry = RegistryContext::new(goal, registry);
self
}

pub fn with_registry_context(&mut self, registry: RegistryContext) -> &mut Self {
self.ensure_solution().registry = registry;
self
}

pub fn with_routes(&mut self, routes: Vec<RouteContext>) -> &mut Self {
self.ensure_solution().routes = routes;

self
}

pub fn with_required(&mut self, required: Vec<Job>) -> &mut Self {
self.ensure_solution().required = required;

self
}

pub fn with_unassigned(&mut self, required: Vec<(Job, UnassignmentInfo)>) -> &mut Self {
let solution = self.ensure_solution();

Expand Down
14 changes: 0 additions & 14 deletions vrp-core/tests/helpers/models/problem/fleet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ pub fn test_costs() -> Costs {
DEFAULT_VEHICLE_COSTS
}

pub fn fixed_costs() -> Costs {
Costs { fixed: 100.0, per_distance: 1.0, per_driving_time: 1.0, per_waiting_time: 1.0, per_service_time: 1.0 }
}

pub fn empty_costs() -> Costs {
Costs { fixed: 0.0, per_distance: 0.0, per_driving_time: 0.0, per_waiting_time: 0.0, per_service_time: 0.0 }
}
Expand Down Expand Up @@ -103,21 +99,11 @@ impl TestVehicleBuilder {
self
}

pub fn costs(&mut self, costs: Costs) -> &mut Self {
self.0.costs = costs;
self
}

pub fn details(&mut self, details: Vec<VehicleDetail>) -> &mut Self {
self.0.details = details;
self
}

pub fn property<K: 'static, T: 'static + Sync + Send>(&mut self, value: T) -> &mut Self {
self.0.dimens.set_value::<K, _>(value);
self
}

pub fn dimens_mut(&mut self) -> &mut Dimensions {
&mut self.0.dimens
}
Expand Down
10 changes: 0 additions & 10 deletions vrp-core/tests/helpers/models/solution/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ impl RouteBuilder {
self
}

pub fn with_activity<F>(&mut self, configure: F) -> &mut Self
where
F: FnOnce(&mut Activity),
{
let mut activity = test_activity();
configure(&mut activity);
self.0.tour.insert_last(activity);
self
}

pub fn build(&mut self) -> Route {
std::mem::replace(&mut self.0, RouteBuilder::default().0)
}
Expand Down
2 changes: 1 addition & 1 deletion vrp-pragmatic/src/checker/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn check_shift_limits(context: &CheckerContext) -> GenericResult<()> {

let extra_activities = if shift.end.is_some() { 2 } else { 1 };
let tour_activities = tour.stops.iter().flat_map(|stop| stop.activities()).count();
let tour_activities = if tour_activities > extra_activities { tour_activities - extra_activities } else { 0 };
let tour_activities = tour_activities.saturating_sub(extra_activities);

if tour_activities > tour_size_limit {
return Err(format!(
Expand Down
2 changes: 1 addition & 1 deletion vrp-scientific/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#[cfg(test)]
#[path = "../tests/helpers/mod.rs"]
#[macro_use]
pub mod helpers;
pub(crate) mod helpers;

#[cfg(test)]
#[path = "../tests/integration/known_problems_test.rs"]
Expand Down
Loading

0 comments on commit d11fb2a

Please sign in to comment.