Skip to content

Commit

Permalink
Update toolchain and fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Jan 12, 2025
1 parent 051d40d commit f47b809
Show file tree
Hide file tree
Showing 37 changed files with 79 additions and 84 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.83-alpine AS Builder
FROM rust:1.84-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 rosomaxa/src/evolution/strategies/iterative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where

loop {
let is_terminated = termination.is_termination(&mut heuristic_ctx);
let is_quota_reached = heuristic_ctx.environment().quota.as_ref().map_or(false, |q| q.is_reached());
let is_quota_reached = heuristic_ctx.environment().quota.as_ref().is_some_and(|q| q.is_reached());

if is_terminated || is_quota_reached {
break;
Expand Down
2 changes: 1 addition & 1 deletion rosomaxa/src/termination/target_proximity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where

fn is_termination(&self, heuristic_ctx: &mut Self::Context) -> bool {
// use the first solution only for comparison
heuristic_ctx.ranked().next().map_or(false, |solution| {
heuristic_ctx.ranked().next().is_some_and(|solution| {
let distance = relative_distance(self.target_fitness.iter().cloned(), solution.fitness());
distance < self.distance_threshold
})
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/construction/clustering/vicinity/estimations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(crate) fn get_clusters(
let is_cluster_affected = cluster
.as_ref()
.and_then(|cluster| cluster.dimens().get_cluster_info())
.map_or(false, |cluster_jobs| cluster_jobs.iter().any(|info| used_jobs.contains(&info.job)));
.is_some_and(|cluster_jobs| cluster_jobs.iter().any(|info| used_jobs.contains(&info.job)));

if is_cluster_affected {
// NOTE force to rebuild cluster on next iteration
Expand Down Expand Up @@ -242,7 +242,7 @@ fn build_job_cluster(
.expect("cannot find movement info")
};

let is_max_jobs = |count| config.threshold.max_jobs_per_cluster.map_or(false, |max| max <= count);
let is_max_jobs = |count| config.threshold.max_jobs_per_cluster.is_some_and(|max| max <= count);

// allow jobs only from reachable candidates
let mut cluster_candidates = center_estimates
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/construction/enablers/multi_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl FeatureConstraint for MultiTripConstraint {
.target
.job
.as_ref()
.map_or(false, |job| intervals.is_marker_job(&Job::Single(job.clone())))
.is_some_and(|job| intervals.is_marker_job(&Job::Single(job.clone())))
{
match self.policy {
MarkerInsertionPolicy::Any => {}
Expand Down Expand Up @@ -180,7 +180,7 @@ impl FeatureState for MultiTripState {
if let Some(interval_fn) = route_intervals.get_interval_fn() {
let (route, state) = route_ctx.as_mut();
let intervals = get_route_intervals(route, |a| {
a.job.as_ref().map_or(false, |job| route_intervals.is_marker_job(&Job::Single(job.clone())))
a.job.as_ref().is_some_and(|job| route_intervals.is_marker_job(&Job::Single(job.clone())))
});

interval_fn.set_route_intervals(state, intervals);
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/construction/enablers/route_intervals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl RouteIntervals {
match self {
RouteIntervals::Single => false,
RouteIntervals::Multiple { is_marker_single_fn, .. } => {
job.as_single().map_or(false, |single| (is_marker_single_fn)(single))
job.as_single().is_some_and(|single| (is_marker_single_fn)(single))
}
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ impl RouteIntervals {
// Private API
impl RouteIntervals {
fn has_markers(&self, route_ctx: &RouteContext) -> bool {
self.get_marker_intervals(route_ctx).map_or(false, |intervals| intervals.len() > 1)
self.get_marker_intervals(route_ctx).is_some_and(|intervals| intervals.len() > 1)
}

fn filter_markers<'a>(&'a self, route: &'a Route, jobs: &'a [Job]) -> impl Iterator<Item = Job> + 'a {
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/construction/enablers/schedule_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn update_states(route_ctx: &mut RouteContext, activity: &(dyn ActivityCost), tr
waiting_times.reverse();

// NOTE: pop out state for arrival
if route.tour.end().map_or(false, |end| end.job.is_none()) {
if route.tour.end().is_some_and(|end| end.job.is_none()) {
latest_arrivals.pop();
waiting_times.pop();
}
Expand Down
7 changes: 3 additions & 4 deletions vrp-core/src/construction/features/breaks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl BreakFeatureBuilder {
let belongs_to_route_fn = self.belongs_to_route_fn.take().unwrap_or_else(|| {
Arc::new({
let is_break_single_fn = is_break_single_fn.clone();
move |_, job| job.as_single().map_or(false, |single| is_break_single_fn(single))
move |_, job| job.as_single().is_some_and(|single| is_break_single_fn(single))
})
});

Expand Down Expand Up @@ -200,7 +200,7 @@ impl FeatureObjective for OptionalBreakObjective {
fn estimate(&self, move_ctx: &MoveContext<'_>) -> Cost {
match move_ctx {
MoveContext::Route { job, .. } => {
if job.as_single().map_or(false, |single| (self.break_fns.is_break_single_fn)(single)) {
if job.as_single().is_some_and(|single| (self.break_fns.is_break_single_fn)(single)) {
1.
} else {
Cost::default()
Expand Down Expand Up @@ -265,8 +265,7 @@ impl<JT: JobContextTransition + Send + Sync> OptionalBreakState<JT> {
prev != current && break_single.places.first().and_then(|p| p.location).is_none();
let is_not_on_time = !is_on_proper_time(route_ctx, break_single, &activity.schedule)
|| !can_be_scheduled(route_ctx, break_single, &self.break_fns.policy_fn);
let is_ovrp_last =
route_ctx.route().tour.end().map_or(false, |end| std::ptr::eq(activity, end));
let is_ovrp_last = route_ctx.route().tour.end().is_some_and(|end| std::ptr::eq(activity, end));

if is_orphan || is_not_on_time || is_ovrp_last {
breaks.insert(Job::Single(break_single.clone()));
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/construction/features/capacity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ where
) -> Option<ConstraintViolation> {
let demand = self.get_demand(activity_ctx.target);

let violation = if activity_ctx.target.retrieve_job().map_or(false, |job| job.as_multi().is_some()) {
let violation = if activity_ctx.target.retrieve_job().is_some_and(|job| job.as_multi().is_some()) {
// NOTE multi job has dynamic demand which can go in another interval
if self.can_handle_demand_on_intervals(route_ctx, demand, Some(activity_ctx.index)) {
None
Expand All @@ -250,7 +250,7 @@ where
}

fn has_markers(&self, route_ctx: &RouteContext) -> bool {
self.route_intervals.get_marker_intervals(route_ctx).map_or(false, |intervals| intervals.len() > 1)
self.route_intervals.get_marker_intervals(route_ctx).is_some_and(|intervals| intervals.len() > 1)
}

fn can_handle_demand_on_intervals(
Expand Down
6 changes: 3 additions & 3 deletions vrp-core/src/construction/features/locked_jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ impl Rule {
/// Checks whether given job is in rule. Such jobs are inserted manually and should not by
/// prevented from insertion.
fn is_in_rule(&self, job: &Option<Job>) -> bool {
job.as_ref().map_or(false, |job| self.contains(job))
job.as_ref().is_some_and(|job| self.contains(job))
}

/// Checks whether a new job can be inserted between given prev/next according to after rule.
fn can_insert_after(&self, prev: &Option<Job>, next: &Option<Job>) -> bool {
prev.as_ref().map_or(false, |p| !self.contains(p) || *p == self.index.last)
prev.as_ref().is_some_and(|p| !self.contains(p) || *p == self.index.last)
&& next.as_ref().map_or(true, |n| !self.contains(n))
}

/// Checks whether a new job can be inserted between given prev/next according to before rule.
fn can_insert_before(&self, prev: &Option<Job>, next: &Option<Job>) -> bool {
next.as_ref().map_or(false, |n| !self.contains(n) || *n == self.index.first)
next.as_ref().is_some_and(|n| !self.contains(n) || *n == self.index.first)
&& prev.as_ref().map_or(true, |p| !self.contains(p))
}
}
9 changes: 4 additions & 5 deletions vrp-core/src/construction/features/recharge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl RechargeFeatureBuilder {
.unwrap_or_default();

(distance_limit_fn)(route_ctx.route().actor.as_ref())
.map_or(false, |threshold| current > threshold)
.is_some_and(|threshold| current > threshold)
})
.unwrap_or(false)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ impl RechargeFeatureBuilder {
+ get_distance(route_ctx.route(), left.end, right.start + 1);

(distance_limit_fn)(route_ctx.route().actor.as_ref())
.map_or(false, |threshold| new_distance <= threshold)
.is_some_and(|threshold| new_distance <= threshold)
}
}),
is_assignable_fn,
Expand Down Expand Up @@ -234,7 +234,7 @@ impl MultiTrip for RechargeableMultiTrip {
solution_ctx
.ignored
.iter()
.filter(|job| job.as_single().map_or(false, |single| (self.recharge_single_fn)(single)))
.filter(|job| job.as_single().is_some_and(|single| (self.recharge_single_fn)(single)))
.cloned()
.collect()
} else {
Expand Down Expand Up @@ -297,8 +297,7 @@ impl RechargeableMultiTrip {
.map(|end_idx| self.get_distance(route_ctx, end_idx))
.expect("invalid markers state");

let is_new_recharge =
activity_ctx.target.job.as_ref().map_or(false, |single| (self.recharge_single_fn)(single));
let is_new_recharge = activity_ctx.target.job.as_ref().is_some_and(|single| (self.recharge_single_fn)(single));

let is_violation = if is_new_recharge {
let ((prev_to_tar_distance, tar_to_next_distance), _) =
Expand Down
7 changes: 2 additions & 5 deletions vrp-core/src/construction/features/reloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ impl<T: SharedResource> SharedResourceConstraint<T> {
.and_then(|job| (self.resource_demand_fn)(job.as_ref()))
.unwrap_or_default();

if resource_available
.partial_cmp(&resource_demand)
.map_or(false, |ordering| ordering == Ordering::Less)
{
if resource_available.partial_cmp(&resource_demand) == Some(Ordering::Less) {
ConstraintViolation::skip(self.violation_code)
} else {
ConstraintViolation::success()
Expand Down Expand Up @@ -415,7 +412,7 @@ impl<T: SharedResource + Add<Output = T> + Sub<Output = T>> SharedResourceState<
route_ctx.state().get_reload_intervals().cloned().unwrap_or_default().into_iter().for_each(
|(start_idx, end_idx)| {
let activity = get_activity_by_idx(route_ctx.route(), start_idx);
let has_resource_demand = (self.resource_capacity_fn)(activity).map_or(false, |(_, _)| {
let has_resource_demand = (self.resource_capacity_fn)(activity).is_some_and(|(_, _)| {
(start_idx..=end_idx)
.filter_map(|idx| route_ctx.route().tour.get(idx))
.filter_map(|activity| activity.job.as_ref())
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/construction/features/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl TransportConstraint {

if actor.detail.time.end < prev.place.time.start
|| actor.detail.time.end < target.place.time.start
|| next.map_or(false, |next| actor.detail.time.end < next.place.time.start)
|| next.is_some_and(|next| actor.detail.time.end < next.place.time.start)
{
return ConstraintViolation::fail(self.time_window_code);
}
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/construction/heuristics/evaluators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl MultiContext {
activities: best.activities,
};

if result.violation.as_ref().map_or(false, |v| v.stopped) {
if result.violation.as_ref().is_some_and(|v| v.stopped) {
ControlFlow::Break(result)
} else {
ControlFlow::Continue(result)
Expand Down Expand Up @@ -490,7 +490,7 @@ impl MultiContext {
/// Checks whether insertion is failed.
#[inline]
fn is_failure(&self, index: usize) -> bool {
self.violation.as_ref().map_or(false, |v| v.stopped) || (self.start_index > index)
self.violation.as_ref().is_some_and(|v| v.stopped) || (self.start_index > index)
}
}

Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/construction/heuristics/insertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl InsertionHeuristic {
prepare_insertion_ctx(&mut insertion_ctx);

while !insertion_ctx.solution.required.is_empty()
&& !insertion_ctx.environment.quota.as_ref().map_or(false, |q| q.is_reached())
&& !insertion_ctx.environment.quota.as_ref().is_some_and(|q| q.is_reached())
{
job_selector.prepare(&mut insertion_ctx);
route_selector.prepare(&mut insertion_ctx);
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/models/common/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl Eq for MultiDimLoad {}

impl PartialEq for MultiDimLoad {
fn eq(&self, other: &Self) -> bool {
self.partial_cmp(other).map_or(false, |ordering| ordering == Ordering::Equal)
self.partial_cmp(other) == Some(Ordering::Equal)
}
}

Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/models/solution/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ impl Registry {
/// Removes an actor from the list of available actors.
/// Returns whether the actor was present in the registry.
pub fn use_actor(&mut self, actor: &Actor) -> bool {
self.index.get(actor).and_then(|idx| self.available.get_mut(idx)).map_or(false, |set| set.remove(actor))
self.index.get(actor).and_then(|idx| self.available.get_mut(idx)).is_some_and(|set| set.remove(actor))
}

/// Adds actor to the list of available actors.
/// Returns whether the actor was not present in the registry.
pub fn free_actor(&mut self, actor: &Arc<Actor>) -> bool {
self.index.get(actor).and_then(|idx| self.available.get_mut(idx)).map_or(false, |set| set.insert(actor.clone()))
self.index.get(actor).and_then(|idx| self.available.get_mut(idx)).is_some_and(|set| set.insert(actor.clone()))
}

/// Returns all actors.
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/models/solution/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Activity {

/// Checks whether activity has given job.
pub fn has_same_job(&self, job: &Job) -> bool {
self.retrieve_job().as_ref().map_or(false, |other| other == job)
self.retrieve_job().as_ref() == Some(job)
}

/// Returns job if activity has it.
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/solver/search/decompose_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl DecomposeSearch {
let insertion_ctx = refinement_ctx.selected().next().expect(GREEDY_ERROR);
let insertion_ctx = self.inner_search.search(&refinement_ctx, insertion_ctx);
let is_quota_reached =
refinement_ctx.environment.quota.as_ref().map_or(false, |quota| quota.is_reached());
refinement_ctx.environment.quota.as_ref().is_some_and(|quota| quota.is_reached());
refinement_ctx.add_solution(insertion_ctx);

if is_quota_reached {
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/src/solver/search/local/exchange_swap_star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn choose_best_result(
let (idx, result) = once(&in_place_result)
.chain(top_results.iter().filter(|result| {
// NOTE exclude results near in place result
result.as_success().map_or(false, |success| {
result.as_success().is_some_and(|success| {
success
.activities
.first()
Expand Down Expand Up @@ -291,7 +291,7 @@ fn try_exchange_jobs_in_routes(
result_selector: &(dyn ResultSelector),
) -> bool {
let quota = insertion_ctx.environment.quota.clone();
let is_quota_reached = move || quota.as_ref().map_or(false, |quota| quota.is_reached());
let is_quota_reached = move || quota.as_ref().is_some_and(|quota| quota.is_reached());

if is_quota_reached() {
return true;
Expand Down
2 changes: 1 addition & 1 deletion vrp-core/src/solver/search/utils/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn select_random_job(
loop {
let job = route_ctx.route().tour.get(ai).and_then(|a| a.retrieve_job());

if job.as_ref().map_or(false, job_filter) {
if job.as_ref().is_some_and(job_filter) {
return job;
}

Expand Down
2 changes: 1 addition & 1 deletion vrp-core/tests/helpers/solver/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn get_jobs_by_ids(insertion_ctx: &InsertionContext, job_ids: &[&str]) -> Ve

/// Returns a job by its id.
pub fn get_job_by_id<'a>(insertion_ctx: &'a InsertionContext, job_id: &str) -> Option<&'a Job> {
insertion_ctx.problem.jobs.all().iter().find(|job| job.dimens().get_job_id().map_or(false, |id| id == job_id))
insertion_ctx.problem.jobs.all().iter().find(|job| job.dimens().get_job_id().is_some_and(|id| id == job_id))
}

/// Gets all jobs with their id in a map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn get_check_insertion_fn(disallow_insertion_list: Vec<&str>) -> Arc<CheckInsert
let job_to_check = job.dimens().get_clustered_jobs().and_then(|merged| merged.last()).unwrap_or(job);
let id = job_to_check.dimens().get_job_id();

if id.map_or(false, |id| disallow_insertion_list.contains(id)) {
if id.is_some_and(|id| disallow_insertion_list.contains(id)) {
Err(ViolationCode::unknown())
} else {
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/tests/unit/construction/features/breaks_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct VehicleIdDimenKey;

fn create_break_feature() -> Feature {
fn is_break_job(single: &Single) -> bool {
single.dimens.get_value::<JobTypeDimenKey, String>().map_or(false, |job_type| job_type == "break")
single.dimens.get_value::<JobTypeDimenKey, String>().is_some_and(|job_type| job_type == "break")
}

BreakFeatureBuilder::new("break")
Expand All @@ -26,7 +26,7 @@ fn create_break_feature() -> Feature {
let job_vehicle_id = single.dimens.get_value::<VehicleIdDimenKey, String>();
let vehicle_id = route.actor.vehicle.dimens.get_vehicle_id();

job_vehicle_id.zip(vehicle_id).map_or(false, |(a, b)| a == b)
job_vehicle_id.zip(vehicle_id).is_some_and(|(a, b)| a == b)
})
.build()
.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions vrp-core/tests/unit/construction/features/recharge_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct JobTypeDimenKey;

fn create_recharge_feature(limit: Distance) -> Feature {
fn is_recharge_single(single: &Single) -> bool {
single.dimens.get_value::<JobTypeDimenKey, String>().map_or(false, |job_type| job_type == "recharge")
single.dimens.get_value::<JobTypeDimenKey, String>().is_some_and(|job_type| job_type == "recharge")
}

RechargeFeatureBuilder::new("recharge")
Expand All @@ -24,7 +24,7 @@ fn create_recharge_feature(limit: Distance) -> Feature {
.filter(|single| is_recharge_single(single))
.and_then(|single| single.dimens.get_value::<VehicleIdDimenKey, String>())
.zip(route.actor.vehicle.dimens.get_vehicle_id())
.map_or(false, |(a, b)| a == b)
.is_some_and(|(a, b)| a == b)
})
.build()
.unwrap()
Expand Down
6 changes: 3 additions & 3 deletions vrp-core/tests/unit/construction/features/reloads_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ fn belongs_to_route(route: &Route, job: &Job) -> bool {
.filter(|single| is_reload_single(single.as_ref()))
.and_then(|single| single.dimens.get_value::<VehicleIdDimenKey, String>())
.zip(route.actor.vehicle.dimens.get_vehicle_id())
.map_or(false, |(a, b)| a == b)
.is_some_and(|(a, b)| a == b)
}

fn is_reload_single(single: &Single) -> bool {
single.dimens.get_value::<JobTypeDimenKey, String>().map_or(false, |job_type| job_type == "reload")
single.dimens.get_value::<JobTypeDimenKey, String>().is_some_and(|job_type| job_type == "reload")
}

fn create_simple_reload_feature<T, F>(load_schedule_threshold: F) -> Feature
Expand Down Expand Up @@ -318,7 +318,7 @@ fn create_route_ctx(
.build();

let intervals = get_route_intervals(route_ctx.route(), {
move |activity| activity.job.as_ref().map_or(false, |job| is_reload_single(job))
move |activity| activity.job.as_ref().is_some_and(|job| is_reload_single(job))
});
route_ctx.state_mut().set_reload_intervals(intervals);

Expand Down
Loading

0 comments on commit f47b809

Please sign in to comment.