@@ 0,0 1,132 @@
+use std::convert::Infallible;
+
+use eoa_lib::{constraints::LowerThanConstraintFunction, fitness::FitnessFunction};
+use nalgebra::{OVector, SVector};
+
+pub struct ArbitraryFitness<const SIZE: usize> {
+ fun: Box<dyn Fn(SVector<f64, SIZE>) -> f64>
+}
+
+impl<const SIZE: usize> ArbitraryFitness<SIZE> {
+ pub fn new(fun: Box<dyn Fn(SVector<f64, SIZE>) -> f64>) -> Self {
+ Self {
+ fun
+ }
+ }
+}
+
+impl<const SIZE: usize> FitnessFunction for ArbitraryFitness<SIZE> {
+ type In = SVector<f64, SIZE>;
+ type Out = f64;
+ type Err = Infallible;
+
+ fn fit(&self, inp: &Self::In) -> Result<Self::Out, Self::Err> {
+ Ok((self.fun)(*inp))
+ }
+}
+
+fn problem_g06() -> (ArbitraryFitness<2>, [LowerThanConstraintFunction<SVector<f64, 2>, f64>; 2], f64) {
+ (
+ ArbitraryFitness::new(
+ Box::new(|vec| (vec[0] - 10.0).powi(3) + (vec[1] - 20.0).powi(3))
+ ),
+ [
+ LowerThanConstraintFunction::new(
+ Box::new(|vec| -(vec[0] - 5.0).powi(2) - (vec[1] - 5.0).powi(2) + 100.0)
+ ),
+ LowerThanConstraintFunction::new(
+ Box::new(|vec| (vec[0] - 6.0).powi(2) + (vec[1] - 5.0).powi(2) - 82.81)
+ ),
+ ],
+ -6961.8137558015
+ )
+}
+
+fn problem_g08(eps: f64) -> (ArbitraryFitness<2>, [LowerThanConstraintFunction<SVector<f64, 2>, f64>; 2], f64) {
+ (
+ ArbitraryFitness::new(
+ Box::new(|vec| {
+ let num = (2.0 * std::f64::consts::PI * vec[0]).sin().powi(3)
+ * (2.0 * std::f64::consts::PI * vec[1]).sin();
+ let den = vec[0].powi(3) * (vec[0] + vec[1]);
+ -num / den
+ })
+ ),
+ [
+ LowerThanConstraintFunction::new(
+ Box::new(move |vec| {
+ let x1 = vec[0];
+ let x2 = vec[1];
+ x1.powi(2) - x2 + 1.0
+ })
+ ),
+ LowerThanConstraintFunction::new(
+ Box::new(move |vec| {
+ let x1 = vec[0];
+ let x2 = vec[1];
+ 1.0 - x1 + (x2 - 4.0).powi(2)
+ })
+ ),
+ ],
+ -0.0958250414180359
+ )
+}
+
+pub fn problem_g11(eps: f64) -> (ArbitraryFitness<2>, [LowerThanConstraintFunction<SVector<f64, 2>, f64>; 2], f64) {
+ (
+ ArbitraryFitness::new(
+ Box::new(|vec| {
+ // Minimize f(x) = x1^2 + (x2 - 1)^2
+ vec[0].powi(2) + (vec[1] - 1.0).powi(2)
+ })
+ ),
+ [
+ // Equality h(x) = x2 - x1^2 = 0
+ // Transformed 1: h - eps >= 0 => -(h - eps) <= 0
+ LowerThanConstraintFunction::new(
+ Box::new(move |vec| {
+ let h = vec[1] - vec[0].powi(2);
+ h - eps
+ })
+ ),
+ // Transformed 2: eps - h >= 0 => -(eps - h) <= 0
+ LowerThanConstraintFunction::new(
+ Box::new(move |vec| {
+ let h = vec[1] - vec[0].powi(2);
+ eps - h
+ })
+ ),
+ ],
+ 0.7499 // Best known optimum
+ )
+}
+
+pub fn problem_g24() -> (ArbitraryFitness<2>, [LowerThanConstraintFunction<SVector<f64, 2>, f64>; 2], f64) {
+ (
+ ArbitraryFitness::new(
+ Box::new(|vec| {
+ // Minimize f(x) = -x1 - x2
+ -vec[0] - vec[1]
+ })
+ ),
+ [
+ // g1(x) = -2x1^4 + 8x1^3 - 8x1^2 + x2 - 2 <= 0
+ LowerThanConstraintFunction::new(
+ Box::new(|vec| {
+ -2.0 * vec[0].powi(4) + 8.0 * vec[0].powi(3) - 8.0 * vec[0].powi(2) + vec[1] - 2.0
+ })
+ ),
+ // g2(x) = -4x1^4 + 32x1^3 - 88x1^2 + 96x1 + x2 - 36 <= 0
+ LowerThanConstraintFunction::new(
+ Box::new(|vec| {
+ -4.0 * vec[0].powi(4) + 32.0 * vec[0].powi(3) - 88.0 * vec[0].powi(2) + 96.0 * vec[0] + vec[1] - 36.0
+ })
+ ),
+ ],
+ -5.50801327159536 // Best known optimum
+ )
+}
+
+fn main() {
+ println!("Hello, world!");
+}