- All Implemented Interfaces:
- Enclosing class:
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
BitVectorsearch operators to solve problems defined over the space of
Permutationobjects. It can also be used as an
Initializerof 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.
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.
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
cost(BitVector candidate)Computes the cost of a candidate solution to the problem instance.
costAsDouble(BitVector candidate)Computes the cost of a candidate solution to the problem instance.
isMinCost(int 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.
minCost()A lower bound on the minimum theoretical cost across all possible solutions to the problem instance, where lower cost implies better solution.
split()Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms.
value(BitVector candidate)Computes the value of the candidate solution within the usual constraints and interpretation of the problem.
Methods inherited from class org.cicirello.search.problems.PermutationToBitVectorProblem
createCandidateSolution, supportedBitVectorLength, toPermutation
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public IntegerCost(IntegerCostOptimizationProblem<Permutation> problem, int permutationLength)Initializes the mapping between Permutation problem and BitVector problem for a specific permutation length.
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.
IllegalArgumentException- if permutationLength is less than 1.
public PermutationToBitVectorProblem.IntegerCost split()Description copied from interface:
SplittableGenerates 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
Copyableinterface. 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:
- 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.
public int cost(BitVector candidate)Computes the cost of a candidate solution to the problem instance. The lower the cost, the more optimal the candidate solution.
public double costAsDouble(BitVector 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
IntegerCostOptimizationProblem.cost(T)method. You should not need to override this default behavior.
- Specified by:
- Specified by:
candidate- The candidate solution to evaluate.
- The cost of the candidate solution as a value of type double. Lower cost means better solution.
public boolean isMinCost(int cost)
public int 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 Integer.MIN_VALUE.
public int value(BitVector candidate)