Module org.cicirello.chips_n_salsa
Package org.cicirello.search.operators
Interface IterableMutationOperator<T>
- Type Parameters:
T
- The type of object used to represent candidate solutions to the problem.
- All Superinterfaces:
MutationOperator<T>
,Splittable<MutationOperator<T>>
- All Known Implementing Classes:
AdjacentSwapMutation
,BlockInterchangeMutation
,BlockMoveMutation
,DefiniteBitFlipMutation
,InsertionMutation
,ReversalMutation
,RotationMutation
,SwapMutation
,TwoChangeMutation
,WindowLimitedBlockMoveMutation
,WindowLimitedInsertionMutation
,WindowLimitedReversalMutation
,WindowLimitedSwapMutation
Implement the IterableMutationOperator interface to define a mutation operator that enables
iterating systematically over the neighbors of a candidate solution, like one would do in a hill
climber.
Example 1: Here is an example of its use. In this first example, we iterate over all
neighbors. At the completion of this block, the state of x will be as of the most recent call to
setSavepoint()
or its original state if that method was never called.
T x = some object of type T.
IterableMutationOperator<T> mutation = ....
MutationIterator iter = mutation.iterator(x);
while (iter.hasNext()) {
iter.nextMutant();
if (new state of x is one we'd like to be able to revert to) {
iter.setSavepoint();
}
}
// This next statement rolls x back to the last savepoint.
iter.rollback();
Example 2: In this next example, we iterate over neighbors only until we find one we like.
T x = some object of type T.
IterableMutationOperator<T> mutation = ....
MutationIterator iter = mutation.iterator(x);
boolean foundOneToKeep = false;
while (iter.hasNext()) {
iter.nextMutant();
if (new state of x is one we'd like to keep) {
foundOneToKeep = true;
break;
}
}
if (!foundOneToKeep) iter.rollback();
-
Method Summary
Modifier and TypeMethodDescriptionCreates and returns aMutationIterator
that can be used to systematically iterate over all of the direct neighbors (i.e., a single mutation step away) of a candidate solution, as one might do in a hill climber.split()
Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms.Methods inherited from interface org.cicirello.search.operators.MutationOperator
mutate
-
Method Details
-
iterator
Creates and returns aMutationIterator
that can be used to systematically iterate over all of the direct neighbors (i.e., a single mutation step away) of a candidate solution, as one might do in a hill climber.- Parameters:
c
- The candidate solution subject to the mutation. Calling methods of theMutationIterator
that is returned changes the state of that candidate solution. See the documentation of those methods for details of how such changes may occur.- Returns:
- A MutationIterator for iterating over the direct neighbors of a candidate solution.
-
split
IterableMutationOperator<T> 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<T>
- 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.
-