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

    Modifier and Type
    Method
    Description
    int
    Compares this SolutionCostPair with the specified SolutionCostPair for order.
    boolean
    Checks whether the cost of the solution contained in this SolutionCostPair is integer valued.
    boolean
    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.
    boolean
    equals(Object other)
     
    int
    Gets the cost contained in this solution cost pair as an int.
    double
    Gets the cost contained in this solution cost pair as a double.
    Gets the solution in this solution cost pair.
    int
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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 Details

    • 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 interface Comparable<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
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object