Package org.ddolib.ddo.core.mdd
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 Summary
ConstructorsConstructorDescriptionNodeSubProblemComparator(StateRanking<T> delegate) Constructs a new comparator that uses the given ranking as a tie-breaker. -
Method Summary
Modifier and TypeMethodDescriptionintcompare(NodeSubProblem<T> o1, NodeSubProblem<T> o2) Compares twoNodeSubProbleminstances.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
NodeSubProblemComparator
Constructs a new comparator that uses the given ranking as a tie-breaker.- Parameters:
delegate- theStateRankingused to compare states when node values are equal
-
-
Method Details
-
compare
Compares twoNodeSubProbleminstances.First, compares by the node value. If the values are equal, the comparison is delegated to the
StateRankingin reversed order.- Specified by:
comparein interfaceComparator<T>- Parameters:
o1- the first subproblem to compareo2- 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
-