Class UndoableRandomValueChangeMutation<T extends IntegerValued>
 java.lang.Object

 org.cicirello.search.operators.integers.RandomValueChangeMutation<T>

 org.cicirello.search.operators.integers.UndoableRandomValueChangeMutation<T>

 Type Parameters:
T
 The specific IntegerValued type.
 All Implemented Interfaces:
Splittable<MutationOperator<T>>
,MutationOperator<T>
,UndoableMutationOperator<T>
public final class UndoableRandomValueChangeMutation<T extends IntegerValued> extends RandomValueChangeMutation<T> implements UndoableMutationOperator<T>
This mutation operator (supporting the undo operation) is for integer valued representations, and replaces an integer value with a different random integer value from the domain. The domain is specified with an interval: [a, b]. The parameter p specifies the probability of mutating an integer. E.g., if theIntegerValued
object undergoing mutation has n integers, then on average themutate(T)
method will mutate k=n*p of those integers. The k integers chosen for mutation are chosen uniformly at random. For each of those k integers, the new value is chosen uniformly at random from [a, b] but excluding its current value. For example, let [a, b]=[0,4], and consider mutating an integer v whose value is currently v=3. The new value for v will be chosen uniformly at random from the set {0, 1, 2, 4}. Note that when a=0 and b=1, this mutation operator becomes equivalent to the traditional bitflip mutation commonly used in genetic algorithms when solutions are represented as bit strings, although use of this class and theIntegerValued
class for that purpose is not recommended as there are much more efficient ways of representing strings of bits (e.g., using bit level operators).


Constructor Summary
Constructors Constructor Description UndoableRandomValueChangeMutation(int a, int b)
Constructs a UndoableRandomValueChangeMutation operator that always mutates exactly one integer from the IntegerValued.UndoableRandomValueChangeMutation(int a, int b, double p)
Constructs a UndoableRandomValueChangeMutation operator.UndoableRandomValueChangeMutation(int a, int b, double p, int k)
Constructs a UndoableRandomValueChangeMutation operator.

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
Indicates whether some other object is equal to this one.void
mutate(T c)
Mutates a candidate solution to a problem, by randomly modifying its state.UndoableRandomValueChangeMutation<T>
split()
Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms.void
undo(T c)
Returns a candidate solution to its previous state prior to the most recent mutation performed.
Methods inherited from class org.cicirello.search.operators.integers.RandomValueChangeMutation
hashCode




Constructor Detail

UndoableRandomValueChangeMutation
public UndoableRandomValueChangeMutation(int a, int b)
Constructs a UndoableRandomValueChangeMutation operator that always mutates exactly one integer from the IntegerValued. If the IntegerValued is a univariate, then it mutates the one and only one integer. If it is a multivariate, then one integer parameter is chosen for mutation uniformly at random. Parameters:
a
 The lower bound of the domain from which to choose random values.b
 The upper bound of the domain from which to choose random values. b must be greater than a (i.e., there must be at least 2 values in the domain). Throws:
IllegalArgumentException
 if a ≥ b.

UndoableRandomValueChangeMutation
public UndoableRandomValueChangeMutation(int a, int b, double p)
Constructs a UndoableRandomValueChangeMutation operator. If the IntegerValued undergoing mutation contains n integer parameters, then this mutation operator will mutate n*p of those integers on average during calls tomutate(T)
. Since this is a randomized process, it is possible that no integers will be mutated during a call to mutate (e.g., if p is low relative to n). Parameters:
a
 The lower bound of the domain from which to choose random values.b
 The upper bound of the domain from which to choose random values. b must be greater than a (i.e., there must be at least 2 values in the domain).p
 The probability of mutating an individual integer. Negative p are treated as p=0. If p is greater than 1, it is treated as p=1.

UndoableRandomValueChangeMutation
public UndoableRandomValueChangeMutation(int a, int b, double p, int k)
Constructs a UndoableRandomValueChangeMutation operator. If the IntegerValued undergoing mutation contains n integer parameters, then this mutation operator will mutate n*p of those integers on average during calls tomutate(T)
, but will definitely mutate at least k of them. Use this constructor if you want to insure that every call tomutate(T)
changes the IntegerValued undergoing mutation by specifying a minimum k to mutate. Parameters:
a
 The lower bound of the domain from which to choose random values.b
 The upper bound of the domain from which to choose random values. b must be greater than a (i.e., there must be at least 2 values in the domain).p
 The probability of mutating an individual integer. Negative p are treated as p=0. If p is greater than 1, it is treated as p=1.k
 The minimum number of integer parameters of the IntegerValued undergoing mutation to mutate during calls to themutate(T)
method. Negative k are treated as k=0. Throws:
IllegalArgumentException
 if a ≥ b or if p is negative.


Method Detail

mutate
public void mutate(T c)
Description copied from interface:MutationOperator
Mutates a candidate solution to a problem, by randomly modifying its state. The mutant that is produced is in the local neighborhood of the original candidate solution. Specified by:
mutate
in interfaceMutationOperator<T extends IntegerValued>
 Overrides:
mutate
in classRandomValueChangeMutation<T extends IntegerValued>
 Parameters:
c
 The candidate solution subject to the mutation. This method changes the state of c.

undo
public void undo(T c)
Description copied from interface:UndoableMutationOperator
Returns a candidate solution to its previous state prior to the most recent mutation performed.
For example, consider the following. Let c' be the current state of c. Let c'' be the state of c after mutate(c); If we then call undo(c), the state of c should revert back to c'.
The behavior of undo is undefined if c is altered by some other process between the calls to mutate and undo. The behavior is also undefined if a different candidate is given to undo then the last given to mutate. For example, if the following two statements are executed, mutate(c); undo(d);, the effect on d is undefined as it wasn't the most recently mutated candidate solution.
 Specified by:
undo
in interfaceUndoableMutationOperator<T extends IntegerValued>
 Parameters:
c
 The candidate solution to revert.

split
public UndoableRandomValueChangeMutation<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 extends IntegerValued>
 Specified by:
split
in interfaceUndoableMutationOperator<T extends IntegerValued>
 Overrides:
split
in classRandomValueChangeMutation<T extends IntegerValued>
 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.

equals
public boolean equals(Object other)
Description copied from class:RandomValueChangeMutation
Indicates whether some other object is equal to this one. The objects are equal if they are the same type of operator with the same parameters. Overrides:
equals
in classRandomValueChangeMutation<T extends IntegerValued>
 Parameters:
other
 the object with which to compare Returns:
 true if and only if the objects are equal

