Skip to content

Commit

Permalink
Consider negative and positive zero in objective layer
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Nov 10, 2024
1 parent 60a1f26 commit 8c71a61
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rosomaxa/src/algorithms/gsom/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ where

/// Returns max unified distance of the network.
pub fn max_unified_distance(&self) -> Float {
self.get_nodes().map(|node| node.unified_distance(self, 1)).max_by(|a, b| a.total_cmp(b)).unwrap_or(0.)
self.get_nodes().map(|node| node.unified_distance(self, 1)).max_by(|a, b| a.total_cmp(b)).unwrap_or_default()
}

/// Trains network on an input.
Expand Down
2 changes: 1 addition & 1 deletion rosomaxa/src/termination/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ where
}

fn estimate(&self, heuristic_ctx: &Self::Context) -> Float {
self.terminations.iter().map(|t| t.estimate(heuristic_ctx)).max_by(|a, b| a.total_cmp(b)).unwrap_or(0.)
self.terminations.iter().map(|t| t.estimate(heuristic_ctx)).max_by(|a, b| a.total_cmp(b)).unwrap_or_default()
}
}
8 changes: 7 additions & 1 deletion vrp-core/src/models/goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ impl GoalBuilder {
let fitness_a = objectives[0].fitness(a);
let fitness_b = objectives[0].fitness(b);

fitness_a.total_cmp(&fitness_b)
// NOTE total_cmp distinguishes between positive zero and negative zero while
// logically they are the same in this context
if fitness_a == 0. && fitness_b == 0. {
Ordering::Equal
} else {
fitness_a.total_cmp(&fitness_b)
}
}),
Arc::new(|objectives, move_ctx| objectives[0].estimate(move_ctx)),
vec![objective],
Expand Down

0 comments on commit 8c71a61

Please sign in to comment.