Module org.cicirello.chips_n_salsa
Package org.cicirello.search.problems
Class PermutationToBitVectorProblem.DoubleCost
java.lang.Object
org.cicirello.search.problems.PermutationToBitVectorProblem
org.cicirello.search.problems.PermutationToBitVectorProblem.DoubleCost
- All Implemented Interfaces:
Splittable<Initializer<BitVector>>
,Initializer<BitVector>
,OptimizationProblem<BitVector>
,Problem<BitVector>
- Enclosing class:
- PermutationToBitVectorProblem
public static final class PermutationToBitVectorProblem.DoubleCost
extends PermutationToBitVectorProblem
implements OptimizationProblem<BitVector>
This class implements a mapping between Permutation problems and BitVector problems, where cost
values are of type double. 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.cicirello.search.problems.PermutationToBitVectorProblem
PermutationToBitVectorProblem.DoubleCost, PermutationToBitVectorProblem.IntegerCost
-
Constructor Summary
ConstructorDescriptionDoubleCost
(OptimizationProblem<Permutation> problem, int permutationLength) Initializes the mapping between Permutation problem and BitVector problem for a specific permutation length. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Computes the cost of a candidate solution to the problem instance.double
costAsDouble
(BitVector candidate) Computes the cost of a candidate solution to the problem instance.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.double
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.double
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
Methods inherited from interface org.cicirello.search.problems.OptimizationProblem
getSolutionCostPair
-
Constructor Details
-
DoubleCost
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 theCopyable
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 interfaceSplittable<Initializer<BitVector>>
- Overrides:
split
in classPermutationToBitVectorProblem
- 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
Description copied from interface:OptimizationProblem
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 interfaceOptimizationProblem<BitVector>
- Parameters:
candidate
- The candidate solution to evaluate.- Returns:
- The cost of the candidate solution. Lower cost means better solution.
-
costAsDouble
Description copied from interface:OptimizationProblem
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
OptimizationProblem.cost(T)
method. You should not need to override this default behavior.- Specified by:
costAsDouble
in interfaceOptimizationProblem<BitVector>
- Specified by:
costAsDouble
in interfaceProblem<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(double cost) Description copied from interface:OptimizationProblem
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 interfaceOptimizationProblem<BitVector>
- Parameters:
cost
- The cost to check.- Returns:
- true if cost is equal to the minimum theoretical cost,
-
minCost
public double minCost()Description copied from interface:OptimizationProblem
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.- Specified by:
minCost
in interfaceOptimizationProblem<BitVector>
- Returns:
- A lower bound on the minimum theoretical cost of the problem instance.
-
value
Description copied from interface:OptimizationProblem
Computes the value of the candidate solution within the usual constraints and interpretation of the problem.- Specified by:
value
in interfaceOptimizationProblem<BitVector>
- Parameters:
candidate
- The candidate solution to evaluate.- Returns:
- The actual optimization value of the candidate solution.
-