Class PermutationToBitVectorProblem.IntegerCost

java.lang.Object
org.cicirello.search.problems.PermutationToBitVectorProblem
org.cicirello.search.problems.PermutationToBitVectorProblem.IntegerCost
All Implemented Interfaces:
Splittable<Initializer<BitVector>>, Initializer<BitVector>, IntegerCostOptimizationProblem<BitVector>, Problem<BitVector>
Enclosing class:
PermutationToBitVectorProblem

public static final class PermutationToBitVectorProblem.IntegerCost extends PermutationToBitVectorProblem implements IntegerCostOptimizationProblem<BitVector>

This class implements a mapping between Permutation problems and BitVector problems, where cost values are of type int. This enables using BitVector search operators to solve problems defined over the space of Permutation objects. It can also be used as an Initializer of BitVectors by search algorithms to ensure that the search is using BitVectors of the appropriate length to represent permutations of the desired length for the problem you are solving. In fact, to ensure that your search is using the correct bit length, you should use this as your Initializer.

The superclass, PermutationToBitVectorProblem, handles the transformation between BitVectors and Permutations. See that class's documentation for the details of how a BitVector is interpreted as a Permutation.

  • Constructor Details

    • IntegerCost

      public IntegerCost(IntegerCostOptimizationProblem<Permutation> problem, int permutationLength)
      Initializes the mapping between Permutation problem and BitVector problem for a specific permutation length.
      Parameters:
      problem - The original Permutation problem.
      permutationLength - The length of the permutations under optimization, in number of elements. This is NOT the length of the BitVectors. For example, if the problem is the Traveling Salesperson, and if the instance has 100 cities, then you would pass 100 for this parameter.
      Throws:
      IllegalArgumentException - if permutationLength is less than 1.
  • Method Details

    • split

      Description copied from interface: Splittable
      Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms. The state of the object that is returned may or may not be identical to that of the original. Thus, this is a distinct concept from the functionality of the Copyable interface. Classes that implement this interface must ensure that the object returned performs the same functionality, and that it does not share any state data that would be either unsafe or inefficient for concurrent access by multiple threads. The split method is allowed to simply return the this reference, provided that it is both safe and efficient for multiple threads to share a single copy of the Splittable object. The intention is to provide a multithreaded search with the capability to provide spawned threads with their own distinct search operators. Such multithreaded algorithms can call the split method for each thread it spawns to generate a functionally identical copy of the operator, but with independent state.
      Specified by:
      split in interface Splittable<Initializer<BitVector>>
      Overrides:
      split in class PermutationToBitVectorProblem
      Returns:
      A functionally identical copy of the object, or a reference to this if it is both safe and efficient for multiple threads to share a single instance of this Splittable object.
    • cost

      public int cost(BitVector candidate)
      Description copied from interface: IntegerCostOptimizationProblem
      Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.
      Specified by:
      cost in interface IntegerCostOptimizationProblem<BitVector>
      Parameters:
      candidate - The candidate solution to evaluate.
      Returns:
      The cost of the candidate solution. Lower cost means better solution.
    • costAsDouble

      public double costAsDouble(BitVector candidate)
      Description copied from interface: IntegerCostOptimizationProblem
      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 IntegerCostOptimizationProblem.cost(T) method. You should not need to override this default behavior.

      Specified by:
      costAsDouble in interface IntegerCostOptimizationProblem<BitVector>
      Specified by:
      costAsDouble in interface Problem<BitVector>
      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.
    • isMinCost

      public boolean isMinCost(int cost)
      Description copied from interface: IntegerCostOptimizationProblem
      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.
      Specified by:
      isMinCost in interface IntegerCostOptimizationProblem<BitVector>
      Parameters:
      cost - The cost to check.
      Returns:
      true if cost is equal to the minimum theoretical cost,
    • minCost

      public int minCost()
      Description copied from interface: IntegerCostOptimizationProblem
      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 Integer.MIN_VALUE.
      Specified by:
      minCost in interface IntegerCostOptimizationProblem<BitVector>
      Returns:
      A lower bound on the minimum theoretical cost of the problem instance.
    • value

      public int value(BitVector candidate)
      Description copied from interface: IntegerCostOptimizationProblem
      Computes the value of the candidate solution within the usual constraints and interpretation of the problem.
      Specified by:
      value in interface IntegerCostOptimizationProblem<BitVector>
      Parameters:
      candidate - The candidate solution to evaluate.
      Returns:
      The actual optimization value of the candidate solution.