Module org.cicirello.chips_n_salsa
Package org.cicirello.search.ss
Class HybridConstructiveHeuristic<T extends Copyable<T>>
java.lang.Object
org.cicirello.search.ss.HybridConstructiveHeuristic<T>
 Type Parameters:
T
 The type of Partial object for which this HybridConstructiveHeuristic guides construction, which is assumed to be an object that is a sequence of integers (e.g., vector of integers, permutation, or some other indexable type that stores integers).
 All Implemented Interfaces:
Splittable<ConstructiveHeuristic<T>>
,ConstructiveHeuristic<T>
public final class HybridConstructiveHeuristic<T extends Copyable<T>>
extends Object
implements ConstructiveHeuristic<T>
A HybridConstructiveHeuristic maintains a list of
ConstructiveHeuristic
objects for a
problem, for use in a multiheuristic stochastic sampling search, where each full iteration of the
stochastic sampler uses a single heuristic for all decisions, but where a different heuristic is
chosen for each iteration.
The HybridConstructiveHeuristic supports the following heuristic selection strategies:
 Choose a heuristic uniformly at random at the start of the iteration.
 Use a round robin strategy that uses the heuristics in order as determined by the order they were passed to the constructor, cycling around to the start of the list when necessary.
 Choose a heuristic using a weighted random decision, where each heuristic has an associated weight. For example, if the weight of heuristic 1 is 2 and the weight of heuristic 2 is 3, then on average you can expect 2 out of every 5 iterations to use heuristic 1, and 3 out of every 5 iterations to use heuristic 2.
See the documentation of the various constructors to make your choice of which of these strategies to use.

Constructor Summary
ConstructorDescriptionHybridConstructiveHeuristic
(List<? extends ConstructiveHeuristic<T>> heuristics) Constructs the HybridConstructiveHeuristic, where the heuristic is chosen uniformly at random at the start of each iteration of the stochastic sampler (i.e., each timecreateIncrementalEvaluation()
is called).HybridConstructiveHeuristic
(List<? extends ConstructiveHeuristic<T>> heuristics, boolean roundRobin) Constructs the HybridConstructiveHeuristic, where the heuristic is either chosen uniformly at random at the start of each iteration of the stochastic sampler (i.e., each timecreateIncrementalEvaluation()
is called), or using the round robin strategy.HybridConstructiveHeuristic
(List<? extends ConstructiveHeuristic<T>> heuristics, int[] weights) Constructs the HybridConstructiveHeuristic, where the heuristic is chosen using a weighted random decision at the start of each iteration of the stochastic sampler (i.e., each timecreateIncrementalEvaluation()
is called). 
Method Summary
Modifier and TypeMethodDescriptionint
Gets the required length of complete solutions to the problem instance for which this constructive heuristic is configured.This method handles choosing the heuristic for the next iteration of the stochastic sampling search, and then delegates the usual function of this method to the chosen heuristic.createPartial
(int n) Creates an empty Partial solution, which will be incrementally transformed into a complete solution of a specified length.Gets a reference to the instance of the optimization problem that is the subject of this heuristic.double
h
(Partial<T> p, int element, IncrementalEvaluation<T> incEval) Heuristically evaluates the possible addition of an element to the end of a Partial.split()
Generates a functionally identical copy of this object, for use in multithreaded implementations of search algorithms.

Constructor Details

HybridConstructiveHeuristic
Constructs the HybridConstructiveHeuristic, where the heuristic is chosen uniformly at random at the start of each iteration of the stochastic sampler (i.e., each timecreateIncrementalEvaluation()
is called). Parameters:
heuristics
 A list of ConstructiveHeuristic, all of which must be configured to solve the same problem instance. The list of heuristics must be nonempty. Throws:
IllegalArgumentException
 if not all of the heuristics are configured for the same problem instance.IllegalArgumentException
 if heuristics.size() equals 0.

HybridConstructiveHeuristic
public HybridConstructiveHeuristic(List<? extends ConstructiveHeuristic<T>> heuristics, boolean roundRobin) Constructs the HybridConstructiveHeuristic, where the heuristic is either chosen uniformly at random at the start of each iteration of the stochastic sampler (i.e., each timecreateIncrementalEvaluation()
is called), or using the round robin strategy. Parameters:
heuristics
 A list of ConstructiveHeuristic, all of which must be configured to solve the same problem instance. The list of heuristics must be nonempty.roundRobin
 If true, then each timecreateIncrementalEvaluation()
is called, the HybridConstructiveHeuristic cycles to the next heuristic systematically. Otherwise, if false, it chooses uniformly at random. Throws:
IllegalArgumentException
 if not all of the heuristics are configured for the same problem instance.IllegalArgumentException
 if heuristics.size() equals 0.

HybridConstructiveHeuristic
public HybridConstructiveHeuristic(List<? extends ConstructiveHeuristic<T>> heuristics, int[] weights) Constructs the HybridConstructiveHeuristic, where the heuristic is chosen using a weighted random decision at the start of each iteration of the stochastic sampler (i.e., each timecreateIncrementalEvaluation()
is called). If this constructor is used, it will choose a heuristic using a weighted random decision, where each heuristic has an associated weight. For example, if the weight of heuristic 1 is 2 and the weight of heuristic 2 is 3, then on average you can expect 2 out of every 5 iterations to use heuristic 1, and 3 out of every 5 iterations to use heuristic 2. Parameters:
heuristics
 A list of ConstructiveHeuristics, all of which must be configured to solve the same problem instance. The list of heuristics must be nonempty.weights
 An array of weights, which must be the same length as heuristics. Each weight corresponds to the heuristic in the same position in the sequence. All weights must be positive. Throws:
IllegalArgumentException
 if not all of the heuristics are configured for the same problem instance.IllegalArgumentException
 if heuristics.size() equals 0.IllegalArgumentException
 if heuristics.size() is not equal to weights.length.IllegalArgumentException
 if there exists an i, such that weights[i] < 1.


Method Details

split
Description copied from interface:ConstructiveHeuristic
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.The default implementation simply returns this, which is appropriate in all cases where an instance of the heuristic can be safely shared by multiple threads.
 Specified by:
split
in interfaceConstructiveHeuristic<T extends Copyable<T>>
 Specified by:
split
in interfaceSplittable<T extends Copyable<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.

createIncrementalEvaluation
This method handles choosing the heuristic for the next iteration of the stochastic sampling search, and then delegates the usual function of this method to the chosen heuristic. See theConstructiveHeuristic
interface for full details of the functionality of this method. Specified by:
createIncrementalEvaluation
in interfaceConstructiveHeuristic<T extends Copyable<T>>
 Returns:
 An IncrementalEvaluation for an empty Partial to be used for incrementally computing
any data required by the
h(org.cicirello.search.ss.Partial<T>, int, org.cicirello.search.ss.IncrementalEvaluation<T>)
method.

h
Description copied from interface:ConstructiveHeuristic
Heuristically evaluates the possible addition of an element to the end of a Partial. Higher evaluations imply that the element is a better choice for the next element to add. For example, if you evaluate two elements, x and y, with h, and h returns a higher value for y than for x, then this means that y is believed to be the better choice according to the heuristic. Implementations of this interface must ensure that h always returns a positive result. This is because stochastic sampling algorithms such as HBSS and VBSS assume that the constructive heuristic returns only positive values. Specified by:
h
in interfaceConstructiveHeuristic<T extends Copyable<T>>
 Parameters:
p
 The current state of the Partialelement
 The element under consideration for adding to the PartialincEval
 An IncrementalEvaluation of p. This method assumes that incEval is of the same runtime type as the object returned byConstructiveHeuristic.createIncrementalEvaluation()
. Returns:
 The heuristic evaluation of the hypothetical addition of element to the end of p. The higher the evaluation, the more important the heuristic believes that element should be added next. The intention is to compare the value returned with the heuristic evaluations of other elements. Individual results in isolation are not necessarily meaningful.

createPartial
Description copied from interface:ConstructiveHeuristic
Creates an empty Partial solution, which will be incrementally transformed into a complete solution of a specified length. Specified by:
createPartial
in interfaceConstructiveHeuristic<T extends Copyable<T>>
 Parameters:
n
 the desired length of the final complete solution. Returns:
 an empty Partial solution

completeLength
public int completeLength()Description copied from interface:ConstructiveHeuristic
Gets the required length of complete solutions to the problem instance for which this constructive heuristic is configured. Specified by:
completeLength
in interfaceConstructiveHeuristic<T extends Copyable<T>>
 Returns:
 length of solutions to the problem instance for which this heuristic is configured

getProblem
Description copied from interface:ConstructiveHeuristic
Gets a reference to the instance of the optimization problem that is the subject of this heuristic. Specified by:
getProblem
in interfaceConstructiveHeuristic<T extends Copyable<T>>
 Returns:
 the instance of the optimization problem that is the subject of this heuristic.
