Skip to content

Commit

Permalink
Improve footprint logic
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Nov 26, 2024
1 parent cb8eab3 commit bb9e95e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions rosomaxa/src/population/rosomaxa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ where

fn select<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
match &self.phase {
RosomaxaPhases::Initial { solutions } => Box::new(solutions.iter()),
RosomaxaPhases::Exploration { network, coordinates, selection_size, statistics, .. } => {
let random = self.environment.random.as_ref();

Expand Down Expand Up @@ -169,7 +170,6 @@ where
)
}
RosomaxaPhases::Exploitation { selection_size, .. } => Box::new(self.elite.select().take(*selection_size)),
_ => Box::new(self.elite.select()),
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ where

match &mut self.phase {
RosomaxaPhases::Initial { solutions: individuals } => {
if individuals.len() >= 4 {
if individuals.len() >= self.config.selection_size {
let mut network = Self::create_network(
&self.external_ctx,
self.objective.clone(),
Expand Down
15 changes: 9 additions & 6 deletions vrp-core/src/construction/features/known_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ impl FeatureObjective for KnownEdgeObjective {
insertion_ctx.solution.state.get_footprint_cost().copied().unwrap_or_else(|| {
debug_assert!(self.keep_solution_fitness);

// NOTE: use log2 to reduce sensitivity on solution fitness perturbations.
// NOTE: use sqrt/round to reduce sensitivity on solution fitness perturbations
insertion_ctx
.solution
.state
.get_footprint()
.map_or(Cost::default(), |footprint| footprint.estimate_solution(&insertion_ctx.solution) as Cost)
.log2()
.sqrt()
.round()
})
}

Expand All @@ -49,14 +50,16 @@ impl FeatureObjective for KnownEdgeObjective {
let prev = activity_ctx.prev.place.location;
let target = activity_ctx.target.place.location;

let prev_to_target = footprint.estimate_edge(prev, target) as Cost;
// NOTE: scale down values to reduce sensitivity on solution fitness perturbations
let prev_to_target = (footprint.estimate_edge(prev, target) as Cost).sqrt().round();
let target_to_next = activity_ctx
.next
.as_ref()
.map_or(0., |next| footprint.estimate_edge(target, next.place.location) as Cost);
.map_or(0., |next| footprint.estimate_edge(target, next.place.location) as Cost)
.sqrt()
.round();

// NOTE: use division by 10 to reduce sensitivity on insertion cost perturbations.
((prev_to_target + target_to_next) / 10.).round()
prev_to_target + target_to_next
})
}
}
Expand Down
13 changes: 6 additions & 7 deletions vrp-core/src/solver/heuristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,13 @@ mod builder {
problem: Arc<Problem>,
environment: Arc<Environment>,
) -> InitialOperators<RefinementContext, GoalContext, InsertionContext> {
type VrpInitialOperator = dyn InitialOperator<Context = RefinementContext, Objective = GoalContext, Solution = InsertionContext>
+ Send
+ Sync;

let random = environment.random.clone();
let wrap: fn(
Arc<dyn Recreate>,
) -> Box<
dyn InitialOperator<Context = RefinementContext, Objective = GoalContext, Solution = InsertionContext>
+ Send
+ Sync,
> = |recreate| Box::new(RecreateInitialOperator::new(recreate));
let wrap: fn(Arc<dyn Recreate>) -> Box<VrpInitialOperator> =
|recreate| Box::new(RecreateInitialOperator::new(recreate));

std::iter::once({
// main stable constructive heuristics
Expand Down

0 comments on commit bb9e95e

Please sign in to comment.