diff --git a/vrp-core/src/construction/features/fast_service.rs b/vrp-core/src/construction/features/fast_service.rs index 6a46199a7..8c951de75 100644 --- a/vrp-core/src/construction/features/fast_service.rs +++ b/vrp-core/src/construction/features/fast_service.rs @@ -248,9 +248,8 @@ impl FeatureState for FastServiceState { }) .collect(); - if !multi_job_ranges.is_empty() { - route_ctx.state_mut().put_route_state(self.state_keys[0], multi_job_ranges); - } + // NOTE: always override existing state to avoid stale information about multi-jobs + route_ctx.state_mut().put_route_state(self.state_keys[0], multi_job_ranges); } fn accept_solution_state(&self, solution_ctx: &mut SolutionContext) { diff --git a/vrp-core/src/models/problem/jobs.rs b/vrp-core/src/models/problem/jobs.rs index f83511724..403a708d7 100644 --- a/vrp-core/src/models/problem/jobs.rs +++ b/vrp-core/src/models/problem/jobs.rs @@ -266,10 +266,9 @@ impl Jobs { impl PartialEq for Job { fn eq(&self, other: &Job) -> bool { match (&self, other) { - (Job::Single(_), Job::Multi(_)) => false, - (Job::Multi(_), Job::Single(_)) => false, - (Job::Single(lhs), Job::Single(rhs)) => std::ptr::eq(lhs.as_ref(), rhs.as_ref()), - (Job::Multi(lhs), Job::Multi(rhs)) => std::ptr::eq(lhs.as_ref(), rhs.as_ref()), + (Job::Single(_), Job::Multi(_)) | (Job::Multi(_), Job::Single(_)) => false, + (Job::Single(lhs), Job::Single(rhs)) => Arc::ptr_eq(lhs, rhs), + (Job::Multi(lhs), Job::Multi(rhs)) => Arc::ptr_eq(lhs, rhs), } } } @@ -280,12 +279,10 @@ impl Hash for Job { fn hash(&self, state: &mut H) { match self { Job::Single(single) => { - let address = single.as_ref() as *const Single; - address.hash(state); + Arc::as_ptr(single).hash(state); } Job::Multi(multi) => { - let address = multi.as_ref() as *const Multi; - address.hash(state); + Arc::as_ptr(multi).hash(state); } } } diff --git a/vrp-core/src/models/solution/route.rs b/vrp-core/src/models/solution/route.rs index 2721c3c36..9a537d7f2 100644 --- a/vrp-core/src/models/solution/route.rs +++ b/vrp-core/src/models/solution/route.rs @@ -1,7 +1,7 @@ use crate::models::common::{Distance, Duration, Location, Schedule, TimeWindow}; use crate::models::problem::{Actor, Job, Multi, Single}; use crate::models::solution::Tour; -use crate::utils::{compare_shared, short_type_name}; +use crate::utils::short_type_name; use rosomaxa::prelude::compare_floats; use std::cmp::Ordering; use std::fmt::{Debug, Formatter}; @@ -113,14 +113,7 @@ impl Activity { /// Checks whether activity has given job. pub fn has_same_job(&self, job: &Job) -> bool { - match self.retrieve_job() { - Some(j) => match (&j, job) { - (Job::Multi(lhs), Job::Multi(rhs)) => compare_shared(lhs, rhs), - (Job::Single(lhs), Job::Single(rhs)) => compare_shared(lhs, rhs), - _ => false, - }, - _ => false, - } + self.retrieve_job().as_ref().map_or(false, |other| other == job) } /// Returns job if activity has it. diff --git a/vrp-core/src/utils/comparison.rs b/vrp-core/src/utils/comparison.rs deleted file mode 100644 index 183c5b430..000000000 --- a/vrp-core/src/utils/comparison.rs +++ /dev/null @@ -1,9 +0,0 @@ -/// Various helpers -use std::sync::Arc; - -/// Compares pointers from shared objects. -pub fn compare_shared(left: &Arc, right: &Arc) -> bool { - let left: *const T = left.as_ref(); - let right: *const T = right.as_ref(); - left == right -} diff --git a/vrp-core/src/utils/mod.rs b/vrp-core/src/utils/mod.rs index f161a0ff9..a4ee0d922 100644 --- a/vrp-core/src/utils/mod.rs +++ b/vrp-core/src/utils/mod.rs @@ -3,8 +3,5 @@ // Reimport rosomaxa utils pub use rosomaxa::utils::*; -mod comparison; -pub use self::comparison::*; - mod types; pub use self::types::Either;