java.lang.Object
org.cicirello.search.ss.PartialPermutation
- All Implemented Interfaces:
Partial<Permutation>
A PartialPermutation represents a permutation that is being iteratively constructed as a solution
to an optimization problem over the space of permutations. This class supports the implementation
of constructive heuristics for permutation optimization problems, as well as for stochastic
sampling algorithms that rely on constructive heuristics.
In the context of this library, a permutation of length n is a permutation of the integers { 0, 1, ..., (n-1)}.
-
Constructor Summary
ConstructorDescriptionPartialPermutation
(int n) Constructs a PartialPermutation that will iteratively be transformed into a Permutation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
extend
(int extensionIndex) Extends the Partial by adding an element to the end of the Partial.int
get
(int index) Gets the element in the Partial at position index.int
getExtension
(int extensionIndex) Gets the element in position index of the list of possible extensions.int
getLast()
Gets the element in the current last position of the Partial, i.e., the element at index: size()-1.boolean
Checks if the Partial is actually a complete T.int
Gets the number of elements not yet added to the Partial.int
size()
Gets the size of the Partial, which is the number of elements that have already been added to it.Generates a complete instance that is consistent with this Partial.
-
Constructor Details
-
PartialPermutation
public PartialPermutation(int n) Constructs a PartialPermutation that will iteratively be transformed into a Permutation.- Parameters:
n
- The desired length of the final Permutation, which must be non-negative.- Throws:
IllegalArgumentException
- if n is less than 0
-
-
Method Details
-
toComplete
Description copied from interface:Partial
Generates a complete instance that is consistent with this Partial. That is, elements already added to the Partial will retain their positions, while elements not already in the Partial will be added in an undefined order such that the result is a valid complete object of type T.- Specified by:
toComplete
in interfacePartial<Permutation>
- Returns:
- a valid object of type T consistent with the current state of this Partial
-
isComplete
public boolean isComplete()Description copied from interface:Partial
Checks if the Partial is actually a complete T.- Specified by:
isComplete
in interfacePartial<Permutation>
- Returns:
- true if the Partial is a complete T.
-
get
public int get(int index) Description copied from interface:Partial
Gets the element in the Partial at position index.- Specified by:
get
in interfacePartial<Permutation>
- Parameters:
index
- The position, which must be less than size(). The valid index values are [0, 1, ..., (size()-1)].- Returns:
- the element in position index.
-
getLast
public int getLast()Description copied from interface:Partial
Gets the element in the current last position of the Partial, i.e., the element at index: size()-1.- Specified by:
getLast
in interfacePartial<Permutation>
- Returns:
- The element in the current last position of the Partial.
-
size
public int size()Description copied from interface:Partial
Gets the size of the Partial, which is the number of elements that have already been added to it. Note that this is NOT the size of the final complete T. Rather, it is the current size of the Partial.- Specified by:
size
in interfacePartial<Permutation>
- Returns:
- size The size of the Partial.
-
numExtensions
public int numExtensions()Description copied from interface:Partial
Gets the number of elements not yet added to the Partial. We refer to these as extensions since adding an element will extend the size of the Partial.- Specified by:
numExtensions
in interfacePartial<Permutation>
- Returns:
- the number of elements not yet added to the Partial
-
getExtension
public int getExtension(int extensionIndex) Description copied from interface:Partial
Gets the element in position index of the list of possible extensions. This method gets the element at position index from the list of those elements that can be added next to the Partial. For example, if this is a partial permutation, then this would get one of the elements not yet added to the permutation. Or for example, if this is a partial vector of integers, then this would get one of the values that is allowed to be added to the next position of the vector. Note that each timePartial.extend(int)
is called that the remaining elements may be reordered, so you cannot assume that the extensions remain in the same positions once you call extend.- Specified by:
getExtension
in interfacePartial<Permutation>
- Parameters:
extensionIndex
- An index into the list of elements that can be added to the Partial next. The valid extensionIndex values are [0, 1, ..., (numExtensions()-1)].- Returns:
- the element at the designated index in the list of elements that can be added to the Partial.
-
extend
public void extend(int extensionIndex) Description copied from interface:Partial
Extends the Partial by adding an element to the end of the Partial. If size() is the size of the Partial before the extension, then the new element is added to position size() and the size() is increased by 1.- Specified by:
extend
in interfacePartial<Permutation>
- Parameters:
extensionIndex
- An index into the list of elements that can be added to the Partial. The valid extensionIndex values are [0, 1, ..., (numExtensions()-1)].
-