Skip to content

Commit

Permalink
Merge pull request #18 from s-simoncelli/plot-crate
Browse files Browse the repository at this point in the history
Plot crate
  • Loading branch information
s-simoncelli authored Aug 15, 2024
2 parents edb7948 + f408220 commit 897e9a4
Show file tree
Hide file tree
Showing 94 changed files with 13,517 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target
.idea
.env
*.o
*.a
.DS_Store
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ license = "GPL-3.0-only"

[workspace]
resolver = "2"
members = ["optirustic-macros", "hv-fonseca-et-al-2006-sys", "hv-wfg-sys"]
default-members = ["optirustic-macros", "hv-fonseca-et-al-2006-sys", "hv-wfg-sys"]
members = ["libs/optirustic-macros", "libs/hv-fonseca-et-al-2006-sys", "libs/hv-wfg-sys"]
default-members = ["libs/optirustic-macros", "libs/hv-fonseca-et-al-2006-sys", "libs/hv-wfg-sys"]
exclude = ["optirustic-py"]

[lib]
name = "optirustic"
Expand All @@ -30,9 +31,9 @@ rayon = "1.10.0"
env_logger = "0.11.3"
chrono = { version = "0.4.38", features = ["serde"] }
ordered-float = "4.2.0"
optirustic-macros = { path = "optirustic-macros", version = "0.1.0" }
hv-fonseca-et-al-2006-sys = { path = "hv-fonseca-et-al-2006-sys", version = "2.0.2-rc.2" }
hv-wfg-sys = { path = "hv-wfg-sys", version = "0.1.1" }
optirustic-macros = { path = "libs/optirustic-macros", version = "0.1.0" }
hv-fonseca-et-al-2006-sys = { path = "libs/hv-fonseca-et-al-2006-sys", version = "2.0.2-rc.2" }
hv-wfg-sys = { path = "libs/hv-wfg-sys", version = "0.1.1" }
plotters = { version = "0.3.6", optional = true }
nalgebra = "0.33.0"

Expand All @@ -50,4 +51,4 @@ rustdoc-args = ["--html-in-header", "src/katex-header.html"]

# Run test with optimisation to speed up tests solving optimisation problems.
[profile.test]
opt-level = 3
opt-level = 3
69 changes: 69 additions & 0 deletions examples/nsga3_dtlz1_8obj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use std::env;
use std::error::Error;
use std::path::PathBuf;

use log::LevelFilter;

use optirustic::algorithms::{
Algorithm, MaxGeneration, NSGA3Arg, Nsga3NumberOfIndividuals, StoppingConditionType, NSGA3,
};
use optirustic::core::builtin_problems::DTLZ1Problem;
use optirustic::operators::{PolynomialMutationArgs, SimulatedBinaryCrossoverArgs};
use optirustic::utils::{NumberOfPartitions, TwoLayerPartitions};

/// Solve the DTLZ1 problem from Deb et al. (2013) with 8 objectives.
///
/// Make sure to compile this in release mode to speed up the calculation:
///
/// `cargo run --example nsga3_dtlz1_8obj --release`
fn main() -> Result<(), Box<dyn Error>> {
// Add log
env_logger::builder().filter_level(LevelFilter::Info).init();

// see Table I
let number_objectives = 8;
let k: usize = 5;
let number_variables: usize = number_objectives + k - 1; // M + k - 1 with k = 5 (Section Va)
let problem = DTLZ1Problem::create(number_variables, number_objectives)?;
// The number of partitions used in the paper when from section 5
let number_of_partitions = NumberOfPartitions::TwoLayers(TwoLayerPartitions {
boundary_layer: 3,
inner_layer: 2,
scaling: None,
});
// number of individuals - from Table I
let pop_size: usize = 156;

// see Table II
let crossover_operator_options = SimulatedBinaryCrossoverArgs {
distribution_index: 30.0,
..SimulatedBinaryCrossoverArgs::default()
};
// eta_m = 20 - probability 1/n_vars
let mutation_operator_options = PolynomialMutationArgs::default(&problem);

let args = NSGA3Arg {
number_of_individuals: Nsga3NumberOfIndividuals::Custom(pop_size),
number_of_partitions,
crossover_operator_options: Some(crossover_operator_options),
mutation_operator_options: Some(mutation_operator_options),
stopping_condition: StoppingConditionType::MaxGeneration(MaxGeneration(750)),
parallel: None,
export_history: None,
seed: Some(1),
};

// Initialise the algorithm
let mut algo = NSGA3::new(problem, args).unwrap();

// Run the algorithm
algo.run()?;

// Export the last results to a JSON file
let destination = PathBuf::from(&env::current_dir().unwrap())
.join("examples")
.join("results");
algo.save_to_json(&destination, Some("DTLZ1_8obj"))?;

Ok(())
}
Loading

0 comments on commit 897e9a4

Please sign in to comment.