use crate::genetic::{D01, IndividualSOO};
use crate::operators::selection::{DuelResult, SelectionOperator};
use crate::random::RandomGenerator;
#[derive(Debug, Clone)]
pub struct RankSelection;
impl SelectionOperator for RankSelection {
type FDim = ndarray::Ix1;
fn tournament_duel<'a, ConstrDim>(
&self,
p1: &IndividualSOO<'a, ConstrDim>,
p2: &IndividualSOO<'a, ConstrDim>,
_rng: &mut impl RandomGenerator,
) -> DuelResult
where
ConstrDim: D01,
{
if let result @ DuelResult::LeftWins | result @ DuelResult::RightWins =
Self::feasibility_dominates(p1, p2)
{
return result;
}
match p1.rank.cmp(&p2.rank) {
std::cmp::Ordering::Less => return DuelResult::LeftWins,
std::cmp::Ordering::Greater => return DuelResult::RightWins,
std::cmp::Ordering::Equal => return DuelResult::Tie,
}
}
}