SolutionType - solution type for which this neighbourhood can be applied, required to extend Solutionpublic class CompositeNeighbourhood<SolutionType extends Solution> extends Object implements Neighbourhood<SolutionType>
| Constructor and Description |
|---|
CompositeNeighbourhood(List<? extends Neighbourhood<? super SolutionType>> neighbourhoods,
List<Double> neighbourhoodWeights)
Creates a composite neighbourhood consisting of the list of given neighbourhoods and specified weights.
|
| Modifier and Type | Method and Description |
|---|---|
List<Move<? super SolutionType>> |
getAllMoves(SolutionType solution)
Creates and returns the union of all moves generated by each of the contained neighbourhoods.
|
Move<? super SolutionType> |
getRandomMove(SolutionType solution,
Random rnd)
Produces a random move generated by one of the contained neighbourhoods based on the assigned weights.
|
String |
toString()
Create string representation that indicates the
contained neighbourhoods and respective weights.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetRandomMovepublic CompositeNeighbourhood(List<? extends Neighbourhood<? super SolutionType>> neighbourhoods, List<Double> neighbourhoodWeights)
null, should be of the same size and can
not contain any null elements. At least one neighbourhood should be given and all weights
should be strictly positive.neighbourhoods - list of neighbourhoodsneighbourhoodWeights - list of weights assigned to the neighbourhoods (same order as neighbourhoods)NullPointerException - if neighbourhoods or neighbourhoodWeights are
null or contain any null elementsIllegalArgumentException - if neighbourhoods and neighbourhoodWeights are
not of the same size or both empty, or if neighbourhoodWeights
contains any weight ≤ 0public Move<? super SolutionType> getRandomMove(SolutionType solution, Random rnd)
null.
Else, it selects a move through roulette selection based on the weights assigned at construction.getRandomMove in interface Neighbourhood<SolutionType extends Solution>solution - solution for which a move is generatedrnd - source of randomness used to generate random movenull if none of the
contained neighbourhoods are able to produce a random movepublic List<Move<? super SolutionType>> getAllMoves(SolutionType solution)
getAllMoves in interface Neighbourhood<SolutionType extends Solution>solution - solution for which all moves are generatedCopyright © 2016. All rights reserved.