Skip to main content

total_violation

Function total_violation 

pub fn total_violation(constraints: &[f64]) -> f64
Expand description

The total constraint violation: the sum of the positive parts.

This is what ranks two infeasible solutions against each other under constrained_dominates: the one that is closer to the feasible region wins, which is what drives an infeasible population toward feasibility instead of leaving it to drift.

Satisfied constraints contribute nothing (they are not rewarded — a solution deep inside the feasible region does not get to out-rank one merely inside it on that basis). A NaN value yields +∞: a constraint that could not be evaluated is treated as maximally violated, so it cannot slip through as “contributes zero” the way a naive if v > 0.0 sum would let it.

use atune_core::pareto::total_violation;

assert_eq!(total_violation(&[-5.0, 0.0]), 0.0);
assert_eq!(total_violation(&[2.0, -1.0, 0.5]), 2.5);
assert_eq!(total_violation(&[f64::NAN, -1.0]), f64::INFINITY);