public class SingleSwapNeighbourhood extends SubsetNeighbourhood
A subset neighbourhood that generates swap moves only (see SwapMove
). A swap move is a subtype of
SubsetMove
. When applying swap moves generated by this neighbourhood to a given subset solution, the set
of selected IDs will always remain of the same size. Therefore, this neighbourhood is only suited for fixed size
subset selection. If desired, a set of fixed IDs can be provided which are not allowed to be swapped.
Note that this neighbourhood is thread-safe: it can be safely used to concurrently generate moves in different searches running in separate threads.
Constructor and Description |
---|
SingleSwapNeighbourhood()
Creates a basic single swap neighbourhood.
|
SingleSwapNeighbourhood(Set<Integer> fixedIDs)
Creates a single swap neighbourhood with a given set of fixed IDs which are not allowed to be swapped.
|
Modifier and Type | Method and Description |
---|---|
List<SubsetMove> |
getAllMoves(SubsetSolution solution)
Generates a list of all possible swap moves that transform the given subset solution by removing a single ID from
the current selection and replacing it with a new ID which is currently not selected.
|
SubsetMove |
getRandomMove(SubsetSolution solution,
Random rnd)
Generates a random swap move for the given subset solution that removes a single ID from the set of currently selected IDs,
and replaces it with a random ID taken from the set of currently unselected IDs.
|
getAddCandidates, getRemoveCandidates
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRandomMove
public SingleSwapNeighbourhood()
public SingleSwapNeighbourhood(Set<Integer> fixedIDs)
fixedIDs
- set of fixed IDs which are not allowed to be swappedpublic SubsetMove getRandomMove(SubsetSolution solution, Random rnd)
null
is returned.solution
- solution for which a random swap move is generatedrnd
- source of randomness used to generate random movenull
if no swap move can be generatedpublic List<SubsetMove> getAllMoves(SubsetSolution solution)
solution
- solution for which all possible swap moves are generatedCopyright © 2016. All rights reserved.