public class DisjointMultiAdditionNeighbourhood extends SubsetNeighbourhood
A subset neighbourhood that generates moves which simultaneously add a fixed number of items to the selection.
Generated moves are of type GeneralSubsetMove
, which is a subtype of SubsetMove
, and always only
add IDs to the selection. If desired, a set of fixed IDs can be provided which are not allowed to be selected.
Also, a maximum size can be imposed so that it is guaranteed that the subset size will not exceed this maximum
after application of a move generated by this neighbourhood. It may happen to be impossible to perform the desired
number of additions, e.g. because too few items are unselected or because of the imposed maximum subset size. In such
case a lower number of items will be added (as many as possible).
Note that a large amount of moves may be generated when the subset size increases. Therefore, this advanced neighbourhood should be used with care, especially in combination with searches that inspect all moves in every step. Furthermore, searches that inspect random moves may have few chances to find an improvement in case of a huge amount of possible neighbours.
This neighbourhood is thread-safe: it can be safely used to concurrently generate moves in different searches running in separate threads.
Constructor and Description |
---|
DisjointMultiAdditionNeighbourhood(int numAdditions)
Creates a disjoint multi addition neighbourhood that simultaneously adds a fixed number of
IDs to the selection.
|
DisjointMultiAdditionNeighbourhood(int numAdditions,
int maxSubsetSize)
Creates a disjoint multi addition neighbourhood that simultaneously adds a fixed number of
IDs to the selection, taking into account that the subset size may not exceed the given maximum.
|
DisjointMultiAdditionNeighbourhood(int numAdditions,
int maxSubsetSize,
Set<Integer> fixedIDs)
Creates a disjoint multi addition neighbourhood that simultaneously adds a fixed number of
IDs to the selection, taking into account that the subset size may not exceed the given maximum
and that the given set of fixed IDs are not allowed to be selected.
|
Modifier and Type | Method and Description |
---|---|
List<SubsetMove> |
getAllMoves(SubsetSolution solution)
Generates the list of all possible moves that perform \(k\) additions, where \(k\) is the fixed number
specified at construction.
|
int |
getMaxSubsetSize()
Get the maximum subset size specified at construction.
|
int |
getNumAdditions()
Get the fixed number of additions performed by generated moves.
|
SubsetMove |
getRandomMove(SubsetSolution solution,
Random rnd)
Generates a move for the given subset solution that selects a random subset of currently unselected IDs.
|
getAddCandidates, getRemoveCandidates
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRandomMove
public DisjointMultiAdditionNeighbourhood(int numAdditions)
numAdditions
is 1, this neighbourhood generates exactly the
same moves as the SingleAdditionNeighbourhood
so in such case it is advised to use the latter
neighbourhood which has been optimized for this specific scenario.numAdditions
- fixed number of added IDs (> 0)IllegalArgumentException
- if numAdditions
is not strictly positivepublic DisjointMultiAdditionNeighbourhood(int numAdditions, int maxSubsetSize)
numAdditions
is 1, this neighbourhood generates exactly the same moves as the
SingleAdditionNeighbourhood
so in such case it is advised to use the latter neighbourhood
which has been optimized for this specific scenario.numAdditions
- fixed number of added IDs (> 0)maxSubsetSize
- maximum subset size (> 0)IllegalArgumentException
- if numAdditions
or maxSubsetSize
are not strictly positivepublic DisjointMultiAdditionNeighbourhood(int numAdditions, int maxSubsetSize, Set<Integer> fixedIDs)
numAdditions
is 1, this neighbourhood generates exactly the same moves as the SingleAdditionNeighbourhood
so in such case it is advised to use the latter neighbourhood which has been optimized for this
specific scenario.numAdditions
- fixed number of added IDs (> 0)maxSubsetSize
- maximum subset size (> 0)fixedIDs
- set of fixed IDs which are not allowed to be added to the selectionIllegalArgumentException
- if numAdditions
or maxSubsetSize
are not strictly positivepublic int getNumAdditions()
public int getMaxSubsetSize()
Integer.MAX_VALUE
.public SubsetMove getRandomMove(SubsetSolution solution, Random rnd)
null
is returned.solution
- solution for which a random multi addition move is generatedrnd
- source of randomness used to generate random movenull
if no items can be addedpublic List<SubsetMove> getAllMoves(SubsetSolution solution)
Generates the list of all possible moves that perform \(k\) additions, where \(k\) is the fixed number specified at construction. Note: taking into account the current number of unselected items, the imposed maximum subset size (if set) and the fixed IDs (if any) may result in fewer additions (as many as possible).
May return an empty list if no moves can be generated.
solution
- solution for which all possible multi addition moves are generatedCopyright © 2016. All rights reserved.