Skip to content

Commit

Permalink
Fix an issue in experimental objective (plus some refactorings)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Jan 29, 2024
1 parent d54ac56 commit d097820
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 32 deletions.
5 changes: 2 additions & 3 deletions vrp-core/src/construction/features/fast_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 5 additions & 8 deletions vrp-core/src/models/problem/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,9 @@ impl Jobs {
impl PartialEq<Job> 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),
}
}
}
Expand All @@ -280,12 +279,10 @@ impl Hash for Job {
fn hash<H: Hasher>(&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);
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions vrp-core/src/models/solution/route.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 0 additions & 9 deletions vrp-core/src/utils/comparison.rs

This file was deleted.

3 changes: 0 additions & 3 deletions vrp-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
// Reimport rosomaxa utils
pub use rosomaxa::utils::*;

mod comparison;
pub use self::comparison::*;

mod types;
pub use self::types::Either;

0 comments on commit d097820

Please sign in to comment.