-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate problem changes from PR draft #137
- Loading branch information
Showing
110 changed files
with
1,974 additions
and
70,859 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,34 @@ | ||
[package] | ||
authors = ["Leopold Luley <[email protected]>"] | ||
edition = "2021" | ||
name = "mahf" | ||
version = "0.1.0" | ||
authors = ["Leopold Luley <[email protected]>", "Helena Stegherr <[email protected]>", "Jonathan Wurth <[email protected]>"] | ||
edition = "2021" | ||
description = "A framework for modular construction and evaluation of metaheuristics." | ||
readme = "README.md" | ||
license = "GPL-3.0-or-later" | ||
repository = "https://github.com/mahf-opt/mahf" | ||
keywords = ["heuristic", "metaheuristic", "optimization"] | ||
categories = ["science", "algorithms"] | ||
|
||
[dependencies] | ||
anyhow = "1.0.51" | ||
ciborium = "0.2.0" | ||
coco-rs = "0.6" | ||
derive_more = { version = "0.99.17", features = ["deref", "deref_mut"]} | ||
embed-doc-image = "0.1.4" | ||
erased-serde = "0.3.16" | ||
float_eq = "0.7.0" | ||
num_cpus = "1.13.0" | ||
pest = "2.1.3" | ||
pest_consume = "1.1.1" | ||
pest_derive = "2.1.0" | ||
rand = "0.8.4" | ||
rand_distr = "0.4.2" | ||
ron = "0.7.0" | ||
rprompt = "1.0.5" | ||
serde = {version = "1.0.131", features = ["derive"]} | ||
better_any = { version = "0.2.0", features = ["derive"] } | ||
thiserror = "1.0.40" | ||
eyre = "0.6.8" | ||
color-eyre = "0.6.2" | ||
trait-set = "0.3.0" | ||
dyn-clone = "1.0.9" | ||
serde = { version = "1.0.160", features = ["derive"] } | ||
erased-serde = "0.3.25" | ||
derive_more = { version = "0.99.17", features = ["deref", "deref_mut", "add", "mul", "not"] } | ||
rand = "0.8.5" | ||
rand_distr = "0.4.3" | ||
dyn-clone = "1.0.11" | ||
derivative = "2.2.0" | ||
ciborium = "0.2.0" | ||
serde_json = "1.0.96" | ||
rayon = "1.7.0" | ||
test-case = "3.1.0" | ||
float_eq = "1.0.1" | ||
contracts = "0.6.3" | ||
itertools = "0.10.5" | ||
better_any = { version = "0.2.0", features = ["derive"] } | ||
scoped_threadpool = "0.1.9" | ||
|
||
[dev-dependencies] | ||
proptest = "1.0.0" | ||
|
||
[build-dependencies] | ||
cc = "1.0.72" | ||
ron = "0.8.0" | ||
indicatif = { version = "0.17.4", features = ["rayon"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use mahf::prelude::*; | ||
use mahf::problems::KnownOptimumProblem; | ||
use mahf::SingleObjective; | ||
use std::ops::Range; | ||
|
||
pub struct Sphere { | ||
pub dim: usize, | ||
} | ||
|
||
impl Sphere { | ||
pub fn new(dim: usize) -> Self { | ||
Self { dim } | ||
} | ||
} | ||
|
||
impl problems::Problem for Sphere { | ||
type Encoding = Vec<f64>; | ||
type Objective = SingleObjective; | ||
|
||
fn name(&self) -> &str { | ||
"Sphere" | ||
} | ||
} | ||
|
||
impl problems::VectorProblem for Sphere { | ||
type Element = f64; | ||
|
||
fn dimension(&self) -> usize { | ||
self.dim | ||
} | ||
} | ||
|
||
impl problems::LimitedVectorProblem for Sphere { | ||
fn domain(&self) -> Vec<Range<Self::Element>> { | ||
std::iter::repeat(-1.0..1.0).take(self.dim).collect() | ||
} | ||
} | ||
|
||
impl problems::ObjectiveFunction for Sphere { | ||
fn objective(solution: &Self::Encoding) -> Self::Objective { | ||
solution | ||
.iter() | ||
.map(|x| x.powi(2)) | ||
.sum::<f64>() | ||
.try_into() | ||
.unwrap() | ||
} | ||
} | ||
|
||
impl KnownOptimumProblem for Sphere { | ||
fn known_optimum(&self) -> SingleObjective { | ||
0.0.try_into().unwrap() | ||
} | ||
} | ||
|
||
fn main() { | ||
// Specify the problem: Sphere function with 10 dimensions. | ||
let problem: Sphere = Sphere::new(/*dim: */ 10); | ||
// Specify the metaheuristic: Particle Swarm Optimization (pre-implemented in MAHF). | ||
let config: Configuration<Sphere> = pso::real_pso( | ||
/*params: */ | ||
pso::RealProblemParameters { | ||
num_particles: 20, | ||
weight: 1.0, | ||
c_one: 1.0, | ||
c_two: 1.0, | ||
v_max: 1.0, | ||
}, | ||
/*termination: */ | ||
termination::FixedIterations::new(/*max_iterations: */ 500) | ||
& termination::DistanceToOpt::new(0.01), | ||
); | ||
|
||
// Execute the metaheuristic on the problem with a random seed. | ||
let state: State<Sphere> = config.optimize(&problem); | ||
|
||
// Print the results. | ||
println!("Found Individual: {:?}", state.best_individual().unwrap()); | ||
println!("This took {} iterations.", state.iterations()); | ||
println!("Global Optimum: {:?}", problem.known_optimum()); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.