Class NodeSubProblemComparator<T>

java.lang.Object
org.ddolib.ddo.core.mdd.NodeSubProblemComparator<T>
Type Parameters:
T - the type of state contained in the subproblems
All Implemented Interfaces:
Comparator<NodeSubProblem<T>>

public final class NodeSubProblemComparator<T> extends Object implements Comparator<NodeSubProblem<T>>
Comparator for NodeSubProblem instances that sorts them first by their node value, and then by the state using a provided StateRanking if the values are equal.

This class implements a decorator pattern, allowing a StateRanking to be used as a tie-breaker when node values are identical. It is useful for prioritizing subproblems in search or decision diagram algorithms.

  • Constructor Details

    • NodeSubProblemComparator

      public NodeSubProblemComparator(StateRanking<T> delegate)
      Constructs a new comparator that uses the given ranking as a tie-breaker.
      Parameters:
      delegate - the StateRanking used to compare states when node values are equal
  • Method Details

    • compare

      public int compare(NodeSubProblem<T> o1, NodeSubProblem<T> o2)
      Compares two NodeSubProblem instances.

      First, compares by the node value. If the values are equal, the comparison is delegated to the StateRanking in reversed order.

      Specified by:
      compare in interface Comparator<T>
      Parameters:
      o1 - the first subproblem to compare
      o2 - the second subproblem to compare
      Returns:
      a negative integer, zero, or a positive integer as the first subproblem is less than, equal to, or greater than the second