Skip to content

Commit

Permalink
Improve tolerance support in fast service feature
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Dec 12, 2023
1 parent 37f05fa commit 6144ce2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion vrp-core/tests/helpers/models/solution/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl RouteStateBuilder {
}

pub fn build(&mut self) -> RouteState {
std::mem::replace(&mut self.state, RouteState::default())
std::mem::take(&mut self.state)
}
}

Expand Down
25 changes: 22 additions & 3 deletions vrp-pragmatic/src/format/problem/goal_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ fn get_objective_features(
Objective::TourOrder => {
create_tour_order_soft_feature("tour_order", TOUR_ORDER_KEY, get_tour_order_fn())
}
Objective::FastService => get_fast_service_feature("fast_service", blocks, props),
Objective::FastService { tolerance } => {
get_fast_service_feature("fast_service", blocks, props, *tolerance)
}
})
.collect()
})
Expand Down Expand Up @@ -266,6 +268,7 @@ fn get_fast_service_feature(
name: &str,
blocks: &ProblemBlocks,
props: &ProblemProperties,
tolerance: Option<f64>,
) -> Result<Feature, GenericError> {
let (transport, activity) = (blocks.transport.clone(), blocks.activity.clone());
if props.has_reloads {
Expand All @@ -277,6 +280,7 @@ fn get_fast_service_feature(
create_simple_reload_route_intervals(Box::new(move |capacity: &MultiDimLoad| {
*capacity * RELOAD_THRESHOLD
})),
tolerance,
FAST_SERVICE_KEY,
)
} else {
Expand All @@ -287,15 +291,30 @@ fn get_fast_service_feature(
create_simple_reload_route_intervals(Box::new(move |capacity: &SingleDimLoad| {
*capacity * RELOAD_THRESHOLD
})),
tolerance,
FAST_SERVICE_KEY,
)
}
} else {
let route_intervals = Arc::new(NoRouteIntervals::default());
if props.has_multi_dimen_capacity {
create_fast_service_feature::<MultiDimLoad>(name, transport, activity, route_intervals, FAST_SERVICE_KEY)
create_fast_service_feature::<MultiDimLoad>(
name,
transport,
activity,
route_intervals,
tolerance,
FAST_SERVICE_KEY,
)
} else {
create_fast_service_feature::<SingleDimLoad>(name, transport, activity, route_intervals, FAST_SERVICE_KEY)
create_fast_service_feature::<SingleDimLoad>(
name,
transport,
activity,
route_intervals,
tolerance,
FAST_SERVICE_KEY,
)
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion vrp-pragmatic/src/format/problem/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,11 @@ pub enum Objective {

/// An objective to prefer jobs to be served as soon as possible.
#[serde(rename(deserialize = "fast-service", serialize = "fast-service"))]
FastService,
FastService {
/// An objective tolerance specifies how different objective values have to be
/// to consider them different. Relative distance metric is used.
tolerance: Option<f64>,
},
}

/// Specifies balance objective options. At the moment, it uses coefficient of variation as
Expand Down
2 changes: 1 addition & 1 deletion vrp-pragmatic/src/validation/objectives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn check_e1601_duplicate_objectives(objectives: &[&Objective]) -> Result<(), For
BalanceDuration { .. } => acc.entry("balance-duration"),
CompactTour { .. } => acc.entry("compact-tour"),
TourOrder => acc.entry("tour-order"),
FastService => acc.entry("fast-service"),
FastService { .. } => acc.entry("fast-service"),
}
.and_modify(|count| *count += 1)
.or_insert(1_usize);
Expand Down

0 comments on commit 6144ce2

Please sign in to comment.