@@ 127,16 127,16 @@ pub fn problem_g05() -> ConstrainedProblem<4, 5> {
LowerThanConstraintFunction::new(Box::new(|vec| -vec[3] + vec[2] - 0.55)),
LowerThanConstraintFunction::new(Box::new(|vec| -vec[2] + vec[3] - 0.55)),
LowerThanConstraintFunction::new(Box::new(|vec| {
- 1000.0 * (-vec[2] - 0.25).sin() + 1000.0 * (-vec[3] - 0.25) - vec[0] + 894.8
+ 1000.0 * (-vec[2] - 0.25).sin() + 1000.0 * (-vec[3] - 0.25).sin() - vec[0] + 894.8
})),
LowerThanConstraintFunction::new(Box::new(|vec| {
1000.0 * (vec[2] - 0.25).sin()
- + 1000.0 * (vec[2] - vec[3] - 0.25)
+ + 1000.0 * (vec[2] - vec[3] - 0.25).sin()
- vec[1]
+ 894.8
})),
LowerThanConstraintFunction::new(Box::new(|vec| {
- 1000.0 * (vec[2] - 0.25).sin() + 1000.0 * (vec[3] - vec[2] - 0.25) + 1294.8
+ 1000.0 * (vec[3] - 0.25).sin() + 1000.0 * (vec[3] - vec[2] - 0.25).sin() + 1294.8
})),
],
bounds: (
@@ 370,4 370,38 @@ pub struct NsgaConfig {
pub parents_count: usize,
pub iterations: usize,
pub mutation_std_dev: f64,
-}>
\ No newline at end of file
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use nalgebra::SVector;
+ use eoa_lib::constraints::ConstraintFunction;
+
+ #[test]
+ fn test_g05_optimal_feasibility() {
+ let problem = problem_g05();
+ let optimal_solution = SVector::<f64, 4>::from([
+ 679.945148297028709,
+ 1026.06697600004691,
+ 0.118876369094410433,
+ -0.39623348521517826,
+ ]);
+
+ let epsilon = 1e-4; // Tolerance for floating point comparisons
+
+ for (i, constraint) in problem.constraints.iter().enumerate() {
+ let evaluation = constraint.evaluate(&optimal_solution).unwrap();
+ // For inequality constraints g(x) <= 0, we check if evaluation <= epsilon
+ // For equality constraints h(x) = 0, which are transformed to |h(x)| - eps <= 0,
+ // we check if evaluation <= epsilon
+ assert!(
+ evaluation <= epsilon,
+ "Constraint {} (g05) failed: Expected evaluation <= {}, got {}",
+ i + 1,
+ epsilon,
+ evaluation
+ );
+ }
+ }
+}