Module org.cicirello.chips_n_salsa
Package org.cicirello.search
Class SolutionCostPair<T extends Copyable<T>>
- java.lang.Object
-
- org.cicirello.search.SolutionCostPair<T>
-
- Type Parameters:
T
- The type of object the search is optimizing.
- All Implemented Interfaces:
Comparable<SolutionCostPair<T>>
public final class SolutionCostPair<T extends Copyable<T>> extends Object implements Comparable<SolutionCostPair<T>>
An object of this class encapsulates a solution with its corresponding cost value.
-
-
Constructor Summary
Constructors Constructor Description SolutionCostPair(T solution, double cost, boolean isKnownOptimal)
Constructs a SolutionCostPair with integer cost.SolutionCostPair(T solution, int cost, boolean isKnownOptimal)
Constructs a SolutionCostPair with integer cost.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(SolutionCostPair<T> other)
Compares this SolutionCostPair with the specified SolutionCostPair for order.boolean
containsIntCost()
Checks whether the cost of the solution contained in this SolutionCostPair is integer valued.boolean
containsKnownOptimal()
Checks if the solution contained in this object has a cost value equal to the theoretical minimum cost for the problem instance, such as if the cost is equal to a lower bound on the cost for the problem instance.int
getCost()
Gets the cost contained in this solution cost pair as an int.double
getCostDouble()
Gets the cost contained in this solution cost pair as a double.T
getSolution()
Gets the solution in this solution cost pair.
-
-
-
Constructor Detail
-
SolutionCostPair
public SolutionCostPair(T solution, int cost, boolean isKnownOptimal)
Constructs a SolutionCostPair with integer cost.- Parameters:
solution
- The solution.cost
- The cost of the solution.isKnownOptimal
- Pass true if this solution is known to be the optimal, and false otherwise.
-
SolutionCostPair
public SolutionCostPair(T solution, double cost, boolean isKnownOptimal)
Constructs a SolutionCostPair with integer cost.- Parameters:
solution
- The solution.cost
- The cost of the solution.isKnownOptimal
- Pass true if this solution is known to be the optimal, and false otherwise.
-
-
Method Detail
-
getCost
public int getCost()
Gets the cost contained in this solution cost pair as an int. Behavior is undefined if costs are floating-point values.- Returns:
- the cost
-
getCostDouble
public double getCostDouble()
Gets the cost contained in this solution cost pair as a double.- Returns:
- the cost of the current best solution
-
getSolution
public T getSolution()
Gets the solution in this solution cost pair.- Returns:
- the solution
-
containsIntCost
public boolean containsIntCost()
Checks whether the cost of the solution contained in this SolutionCostPair is integer valued.- Returns:
- true if the solution has integer valued cost, and false
otherwise. If this method returns false, then the behavior of the
getCost()
method is undefined.
-
containsKnownOptimal
public boolean containsKnownOptimal()
Checks if the solution contained in this object has a cost value equal to the theoretical minimum cost for the problem instance, such as if the cost is equal to a lower bound on the cost for the problem instance.- Returns:
- true if the solution is a known optimal, and false otherwise.
-
compareTo
public int compareTo(SolutionCostPair<T> other)
Compares this SolutionCostPair with the specified SolutionCostPair for order. Returns a negative integer, zero, or a positive integer as this SolutionCostPair has a cost that is less than, equal to, or greater than the cost of the specified SolutionCostPair.- Specified by:
compareTo
in interfaceComparable<T extends Copyable<T>>
- Parameters:
other
- The other SolutionCostPair with which to compare.- Returns:
- a negative integer, zero, or a positive integer as this SolutionCostPair has a cost that is less than, equal to, or greater than the cost of the specified SolutionCostPair
-
-