Skip to content

Commit

Permalink
Apply minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Sep 18, 2024
1 parent 2fdcea8 commit 6a314a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions vrp-core/src/construction/heuristics/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ impl RegistryContext {
self.registry.use_actor(actor).then(|| self.index.get(actor).map(|route_ctx| route_ctx.deep_copy())).flatten()
}

/// Marks route as used.
/// Returns true if route was not used before.
pub fn use_route(&mut self, route_ctx: &RouteContext) -> bool {
self.registry.use_actor(&route_ctx.route.actor)
}

/// Return back route to be reused again.
/// Returns whether the route was not present in the registry.
pub fn free_route(&mut self, route: RouteContext) -> bool {
Expand Down
5 changes: 2 additions & 3 deletions vrp-core/src/solver/search/decompose_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,15 @@ fn merge_best(
let mut accumulated = accumulated;
let dest_solution = &mut accumulated.solution;

// NOTE theoretically, we can avoid deep copy here, but this would require extension in Population trait
// NOTE theoretically, we can avoid deep copy here, but this would require an extension in Population trait
dest_solution.routes.extend(source_solution.routes.iter().map(|route_ctx| route_ctx.deep_copy()));
dest_solution.ignored.extend(source_solution.ignored.iter().cloned());
dest_solution.required.extend(source_solution.required.iter().cloned());
dest_solution.locked.extend(source_solution.locked.iter().cloned());
dest_solution.unassigned.extend(source_solution.unassigned.iter().map(|(k, v)| (k.clone(), v.clone())));

source_solution.routes.iter().for_each(|route_ctx| {
// NOTE ideally route shouldn't go nowhere, but it is fine in that case
assert!(dest_solution.registry.get_route(&route_ctx.route().actor).is_some());
assert!(dest_solution.registry.use_route(route_ctx), "attempt to use route more than once");
});

accumulated
Expand Down

0 comments on commit 6a314a5

Please sign in to comment.