Class MKSRanking

java.lang.Object
org.ddolib.examples.mks.MKSRanking
All Implemented Interfaces:
Comparator<MKSState>, StateRanking<MKSState>

public class MKSRanking extends Object implements StateRanking<MKSState>
Ranking strategy for multi-dimensional Knapsack (MKS) states.

This class implements StateRanking and provides a method to compare two MKS states based on the average remaining capacity across all knapsack dimensions. States with smaller average remaining capacity are considered "smaller" in the ranking.

  • Constructor Details

    • MKSRanking

      public MKSRanking()
  • Method Details

    • compare

      public int compare(MKSState o1, MKSState o2)
      Compares two MKS states based on their average remaining capacities.

      The average capacity of each state is computed by summing all dimension capacities and dividing by the number of dimensions. Comparison is then performed using Double.compare(double, double).

      Specified by:
      compare in interface Comparator<MKSState>
      Parameters:
      o1 - the first MKS state
      o2 - the second MKS state
      Returns:
      a negative integer, zero, or a positive integer as the first state has less than, equal to, or greater average capacity than the second state