Interface OptimizationProblem<T extends Copyable<T>>

Type Parameters:
T - The type of object used to represent candidate solutions to the problem.
All Superinterfaces:
Problem<T>
All Known Implementing Classes:
CostFunctionScaler, ForresterEtAl2008, GramacyLee2012, HollandRoyalRoad, Mix, PermutationToBitVectorProblem.DoubleCost, Plateaus, PolynomialRootFinding, RandomTSPMatrix.Double, Trap, TSP.Double, TSP.DoubleMatrix

public interface OptimizationProblem<T extends Copyable<T>> extends Problem<T>

The OptimizationProblem interface provides search algorithms with a way to interact with an instance of an optimization problem without the need to know the specifics of the problem (e.g., real-valued function optimization, traveling salesperson, bin packing, etc).

Classes that implement this interface should implement the value(T) method such that it returns the actual optimization objective value, and should implement the cost(T) method such that lower values are better. For a minimization problem, these two methods can be implemented the same, while for a maximization problem, the cost(T) method represents a transformation from maximization to minimization. This enables search algorithms to be implemented without the need to know if the problem is inherently minimization or maximization. That is, a search algorithm can treat every problem as minimization using the cost(T) method. Upon completion, results can then be reported in terms of the actual optimization objective function, via the value(T) method.

Implementers of this interface should implement the minCost method to return a lower bound on the minimum cost across all possible solutions to the problem instance. Implementations should be fast (preferably constant time), and need not be tight. The purpose of this method is to enable a search algorithm to know if further search is futile (e.g., if it actually finds a solution whose cost is equal to the bound on the minimum theoretical cost). For a problem with non-negative costs, a very simple implementation might simply return 0. The default implementation returns Double.NEGATIVE_INFINITY and is appropriate for a case where bounding the minimum cost may require too much time and where costs may be negative.

  • Method Summary

    Modifier and Type
    Method
    Description
    double
    cost(T candidate)
    Computes the cost of a candidate solution to the problem instance.
    default double
    costAsDouble(T candidate)
    Computes the cost of a candidate solution to the problem instance.
    Computes the cost of a candidate solution to the problem instance.
    default boolean
    isMinCost(double cost)
    Checks if a given cost value is equal to the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.
    default double
    A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.
    double
    value(T candidate)
    Computes the value of the candidate solution within the usual constraints and interpretation of the problem.
  • Method Details

    • cost

      double cost(T candidate)
      Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.
      Parameters:
      candidate - The candidate solution to evaluate.
      Returns:
      The cost of the candidate solution. Lower cost means better solution.
    • minCost

      default double minCost()
      A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution. The default implementation returns Double.NEGATIVE_INFINITY.
      Returns:
      A lower bound on the minimum theoretical cost of the problem instance.
    • isMinCost

      default boolean isMinCost(double cost)
      Checks if a given cost value is equal to the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.
      Parameters:
      cost - The cost to check.
      Returns:
      true if cost is equal to the minimum theoretical cost,
    • value

      double value(T candidate)
      Computes the value of the candidate solution within the usual constraints and interpretation of the problem.
      Parameters:
      candidate - The candidate solution to evaluate.
      Returns:
      The actual optimization value of the candidate solution.
    • getSolutionCostPair

      default SolutionCostPair<T> getSolutionCostPair(T candidate)
      Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.

      The default implementation delegates work to the cost(T) method, which is the desired behavior in most (probably all) cases. You will not likely need to override this default behavior.

      Specified by:
      getSolutionCostPair in interface Problem<T extends Copyable<T>>
      Parameters:
      candidate - The candidate solution to evaluate.
      Returns:
      A SolutionCostPair object containing the candidate solution and the cost of that candidate solution. Lower cost means better solution.
    • costAsDouble

      default double costAsDouble(T candidate)
      Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution. Note that subinterfaces provide methods for computing the cost as more specific types (e.g., as an int).

      The default implementation delegates work to the cost(T) method. You should not need to override this default behavior.

      Specified by:
      costAsDouble in interface Problem<T extends Copyable<T>>
      Parameters:
      candidate - The candidate solution to evaluate.
      Returns:
      The cost of the candidate solution as a value of type double. Lower cost means better solution.