Skip to content

Commit 10316a0

Browse files
Apply minor improvements
1 parent 33e496b commit 10316a0

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

vrp-core/src/construction/features/capacity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ where
230230
) -> Option<ConstraintViolation> {
231231
let demand = self.get_demand(activity_ctx.target);
232232

233-
let violation = if activity_ctx.target.retrieve_job().is_some_and(|job| job.as_multi().is_some()) {
233+
let violation = if activity_ctx.target.has_parent_job() {
234234
// NOTE multi job has dynamic demand which can go in another interval
235235
if self.can_handle_demand_on_intervals(route_ctx, demand, Some(activity_ctx.index)) {
236236
None

vrp-core/src/models/problem/jobs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ impl Multi {
197197
single.dimens.get_value::<JobLink, Weak<Multi>>().and_then(|w| w.upgrade())
198198
}
199199

200+
/// Returns `true` if given single job is a child of multi job.
201+
pub(crate) fn is_child(single: &Single) -> bool {
202+
single.dimens.get_value::<JobLink, Weak<Multi>>().is_some()
203+
}
204+
200205
/// Wraps given multi job into [`Arc`] adding reference to it from all sub-jobs.
201206
fn bind(mut multi: Self) -> Arc<Self> {
202207
Arc::new_cyclic(|weak_multi| {

vrp-core/src/models/solution/route.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,18 @@ impl Activity {
112112

113113
/// Checks whether activity has given job.
114114
pub fn has_same_job(&self, job: &Job) -> bool {
115-
self.retrieve_job().as_ref() == Some(job)
115+
match (job, self.job.as_ref()) {
116+
(Job::Single(left), Some(right)) => Arc::ptr_eq(left, right),
117+
(Job::Multi(multi), Some(single)) => {
118+
Multi::roots(single).is_some_and(|single_parent| Arc::ptr_eq(multi, &single_parent))
119+
}
120+
_ => false,
121+
}
122+
}
123+
124+
/// Checks whether activity job has a parent multi job.
125+
pub fn has_parent_job(&self) -> bool {
126+
self.job.as_ref().map_or(false, |single| Multi::is_child(single))
116127
}
117128

118129
/// Returns job if activity has it.

0 commit comments

Comments
 (0)