Skip to content

Commit

Permalink
Refactor objectives to avoid NSGA-II
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed May 31, 2024
1 parent e53bb74 commit a670b89
Show file tree
Hide file tree
Showing 52 changed files with 220 additions and 1,167 deletions.
3 changes: 1 addition & 2 deletions docs/src/internals/algorithms/heuristics.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ Currently available heuristics:
Each heuristic accepts one of solutions from the population (not necessary the best known) and tries to improve it (or diversify).
During one of refinement iterations, many solutions are picked at the same time and many heuristics are called then in parallel.
Such incremental step is called a `generation`. Once it is completed, all found solutions are introduced to the population,
which decides how to store them. With elitism/rosomaxa population types, to order solution from Pareto optimal front,
`Non-Dominated Sorting Genetic Algorithm II` is used.
which decides how to store them.

[Related documentation](https://docs.rs/vrp-core/latest/vrp_core/solver/search/index.html)

Expand Down
1 change: 0 additions & 1 deletion docs/src/internals/algorithms/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ An incomplete list of important references:
- Thibaut Vidal: `Hybrid Genetic Search for the CVRP: Open-Source Implementation and SWAP* Neighborhood`
- Richard F. Hartl, Thibaut Vidal: `Workload Equity in Vehicle Routing Problems: A Survey and Analysis`

- K. Deb; A. Pratap; S. Agarwal; T. Meyarivan: `A fast and elitist multiobjective genetic algorithm: NSGA-II`
- Damminda Alahakoon, Saman K Halgamuge, Srinivasan Bala: `Dynamic self-organizing maps with controlled growth for knowledge discovery`
- Daniel J. Russo, Benjamin Van Roy, Abbas Kazerouni, Ian Osband and Zheng Wen: `A Tutorial on Thompson Sampling` https://web.stanford.edu/~bvr/pubs/TS_Tutorial.pdf

Expand Down
3 changes: 1 addition & 2 deletions docs/src/internals/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ right side
* objective
* kind
*_ multi (NSGA-II)
*_ hierarchical
*_ lexicographical
* types
*_ minimize/maximize routes
*_ minimize cost
Expand Down
2 changes: 1 addition & 1 deletion experiments/heuristic-research/src/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn get_population<O, S>(
) -> Box<dyn HeuristicPopulation<Objective = O, Individual = S> + Send + Sync>
where
O: HeuristicObjective<Solution = S> + Shuffled + 'static,
S: HeuristicSolution + RosomaxaWeighted + DominanceOrdered + 'static,
S: HeuristicSolution + RosomaxaWeighted + 'static,
{
match population_type {
"greedy" => Box::new(ProxyPopulation::new(Greedy::new(objective, 1, None))),
Expand Down
14 changes: 7 additions & 7 deletions experiments/heuristic-research/src/solver/proxies.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::*;
use rosomaxa::example::VectorSolution;
use rosomaxa::population::{DominanceOrdered, RosomaxaWeighted, Shuffled};
use rosomaxa::population::{RosomaxaWeighted, Shuffled};
use rosomaxa::prelude::*;
use std::any::TypeId;
use std::cmp::Ordering;
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<'a> TryFrom<&'a str> for ExperimentData {

impl<S> From<&S> for ObservationData
where
S: HeuristicSolution + RosomaxaWeighted + DominanceOrdered + 'static,
S: HeuristicSolution + RosomaxaWeighted + 'static,
{
fn from(solution: &S) -> Self {
if TypeId::of::<S>() == TypeId::of::<VectorSolution>() {
Expand Down Expand Up @@ -85,7 +85,7 @@ pub struct ProxyPopulation<P, O, S>
where
P: HeuristicPopulation<Objective = O, Individual = S> + 'static,
O: HeuristicObjective<Solution = S> + Shuffled + 'static,
S: HeuristicSolution + RosomaxaWeighted + DominanceOrdered + 'static,
S: HeuristicSolution + RosomaxaWeighted + 'static,
{
generation: usize,
inner: P,
Expand All @@ -95,7 +95,7 @@ impl<P, O, S> ProxyPopulation<P, O, S>
where
P: HeuristicPopulation<Objective = O, Individual = S> + 'static,
O: HeuristicObjective<Solution = S> + Shuffled + 'static,
S: HeuristicSolution + RosomaxaWeighted + DominanceOrdered + 'static,
S: HeuristicSolution + RosomaxaWeighted + 'static,
{
/// Creates a new instance of `ProxyPopulation`.
pub fn new(inner: P) -> Self {
Expand All @@ -112,7 +112,7 @@ impl<P, O, S> HeuristicPopulation for ProxyPopulation<P, O, S>
where
P: HeuristicPopulation<Objective = O, Individual = S> + 'static,
O: HeuristicObjective<Solution = S> + Shuffled,
S: HeuristicSolution + RosomaxaWeighted + DominanceOrdered,
S: HeuristicSolution + RosomaxaWeighted,
{
type Objective = O;
type Individual = S;
Expand Down Expand Up @@ -153,7 +153,7 @@ where
}))
}

fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = (&Self::Individual, usize)> + 'a> {
fn ranked<'a>(&'a self) -> Box<dyn Iterator<Item = &Self::Individual> + 'a> {
self.inner.ranked()
}

Expand All @@ -174,7 +174,7 @@ impl<P, O, S> Display for ProxyPopulation<P, O, S>
where
P: HeuristicPopulation<Objective = O, Individual = S> + 'static,
O: HeuristicObjective<Solution = S> + Shuffled + 'static,
S: HeuristicSolution + RosomaxaWeighted + DominanceOrdered + 'static,
S: HeuristicSolution + RosomaxaWeighted + 'static,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
Expand Down
6 changes: 3 additions & 3 deletions experiments/heuristic-research/src/solver/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Coordinate, MatrixData};
use rosomaxa::algorithms::gsom::NetworkState;
use rosomaxa::population::{DominanceOrdered, Rosomaxa, RosomaxaWeighted, Shuffled};
use rosomaxa::population::{Rosomaxa, RosomaxaWeighted, Shuffled};
use rosomaxa::prelude::*;
use serde::{Deserialize, Serialize};
use std::any::TypeId;
Expand Down Expand Up @@ -44,10 +44,10 @@ pub fn get_population_state<P, O, S>(population: &P) -> PopulationState
where
P: HeuristicPopulation<Objective = O, Individual = S> + 'static,
O: HeuristicObjective<Solution = S> + Shuffled + 'static,
S: HeuristicSolution + RosomaxaWeighted + DominanceOrdered + 'static,
S: HeuristicSolution + RosomaxaWeighted + 'static,
{
let fitness_values =
population.ranked().next().map(|(solution, _)| solution.fitness().collect::<Vec<_>>()).unwrap_or_default();
population.ranked().next().map(|solution| solution.fitness().collect::<Vec<_>>()).unwrap_or_default();

if TypeId::of::<P>() == TypeId::of::<Rosomaxa<O, S>>() {
let rosomaxa = unsafe { std::mem::transmute::<&P, &Rosomaxa<O, S>>(population) };
Expand Down
1 change: 0 additions & 1 deletion rosomaxa/src/algorithms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
pub mod gsom;
pub mod math;
pub mod nsga2;
pub mod rl;
82 changes: 0 additions & 82 deletions rosomaxa/src/algorithms/nsga2/crowding_distance.rs

This file was deleted.

33 changes: 0 additions & 33 deletions rosomaxa/src/algorithms/nsga2/mod.rs

This file was deleted.

Loading

0 comments on commit a670b89

Please sign in to comment.