1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
use crate::{
  gp::{MpDefinitions, MpVec, MphDefinitions, MphVec},
  Obj, ObjDirection,
};
use core::{cmp::Ordering, ops::RangeInclusive};

type DummyMpTy =
  MpVec<[RangeInclusive<f64>; 2], (ObjDirection, fn(&[f64; 2]) -> f64), f64, [f64; 2]>;
type DummyMphTy = MphVec<
  [RangeInclusive<f64>; 2],
  fn(&[f64; 2]) -> usize,
  (ObjDirection, fn(&[f64; 2]) -> f64),
  f64,
  [f64; 2],
>;

/// Verifies if the set of the first values dominates the set of the second values.
pub fn verify_pareto_dominance<O, OR, S, T>(
  objs_defs: &[O],
  first_values: &[T],
  second_values: &[T],
) -> Ordering
where
  O: Obj<OR, S>,
  T: PartialOrd,
{
  let iter = first_values
    .iter()
    .zip(second_values)
    .enumerate()
    .map(|(idx, (a, b))| (objs_defs[idx].obj_direction(), a, b));
  let mut has_at_least_one_better_value = false;
  for (od, first, second) in iter {
    match od.is_better(first, second) {
      Some(Ordering::Greater) => {
        has_at_least_one_better_value = true;
      }
      Some(Ordering::Less) => return Ordering::Less,
      Some(_) | None => {}
    };
  }
  if has_at_least_one_better_value {
    Ordering::Greater
  } else {
    Ordering::Equal
  }
}

fn obj(_: &[f64; 2]) -> f64 {
  0.0
}

fn hc(_: &[f64; 2]) -> usize {
  0
}

pub fn dummy_mp() -> DummyMpTy {
  MpVec::with_capacity(
    MpDefinitions {
      domain: [0.0..=0.0, 0.0..=0.0],
      hard_cstrs: Default::default(),
      name: Default::default(),
      objs: alloc::vec![(ObjDirection::Min, obj), (ObjDirection::Min, obj),],
      soft_cstrs: Default::default(),
    },
    4,
  )
}

pub fn dummy_mp_with_solutions() -> DummyMpTy {
  let mut problem = dummy_mp();
  problem
    .rslts_mut()
    .constructor()
    .or_os_iter([4.0, 8.0].iter().cloned(), [2.0, 2.0])
    .or_os_iter([8.0, 8.0].iter().cloned(), [3.0, 3.0])
    .or_os_iter([8.0, 12.0].iter().cloned(), [4.0, 4.0])
    .or_os_iter([12.0, 12.0].iter().cloned(), [5.0, 5.0]);
  problem
}

pub fn dummy_mph() -> DummyMphTy {
  MphVec::with_capacity(
    MphDefinitions {
      domain: [0.0..=0.0, 0.0..=0.0],
      hard_cstrs: alloc::vec![hc, hc],
      name: Default::default(),
      objs: alloc::vec![(ObjDirection::Min, obj), (ObjDirection::Min, obj)],
      soft_cstrs: Default::default(),
    },
    4,
  )
}

pub fn dummy_mph_with_solutions() -> DummyMphTy {
  let mut problem = dummy_mph();
  problem
    .rslts_mut()
    .constructor()
    .or_hcos_iter([1, 2].iter().cloned(), [4.0, 8.0].iter().cloned(), [2.0, 2.0])
    .or_hcos_iter([1, 2].iter().cloned(), [8.0, 8.0].iter().cloned(), [3.0, 3.0])
    .or_hcos_iter([1, 2].iter().cloned(), [8.0, 12.0].iter().cloned(), [4.0, 4.0])
    .or_hcos_iter([1, 2].iter().cloned(), [12.0, 12.0].iter().cloned(), [5.0, 5.0]);
  problem
}