Package org.opt4j.core.genotype
Class IntegerMapGenotype<K>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<java.lang.Integer>
-
- org.opt4j.core.genotype.IntegerGenotype
-
- org.opt4j.core.genotype.IntegerMapGenotype<K>
-
- Type Parameters:
K
- the type of keys
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<java.lang.Integer>
,java.util.Collection<java.lang.Integer>
,java.util.List<java.lang.Integer>
,java.util.RandomAccess
,Genotype
,ListGenotype<java.lang.Integer>
,MapGenotype<K,java.lang.Integer>
public class IntegerMapGenotype<K> extends IntegerGenotype implements MapGenotype<K,java.lang.Integer>
The
IntegerMapGenotype
is aIntegerGenotype
with theMapGenotype
functionality.Example problem: Select the outcome of throwing five dice die1, die2, die3, die4, die5
Example usage:IntegerGenotype<Die> genotype = new IntegerMapGenotype<Die>(Arrays.asList(die1, die2, die3, die4, die5), 1, 6); genotype.init(new Random());
Example search space size: 65- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<K>
list
-
Fields inherited from class org.opt4j.core.genotype.IntegerGenotype
bounds
-
Fields inherited from interface org.opt4j.core.genotype.MapGenotype
ERROR_MESSAGE_INVALID_KEY, ERROR_MESSAGE_NON_UNIQUE_KEYS, ERROR_MESSAGE_OUT_OF_BOUNDS, ERROR_MESSAGE_UNSUPPORTED_INIT
-
-
Constructor Summary
Constructors Constructor Description IntegerMapGenotype(java.util.List<K> list, int lowerBound, int upperBound)
Constructs aIntegerMapGenotype
with fixed bounds.IntegerMapGenotype(java.util.List<K> list, Bounds<java.lang.Integer> bounds)
Constructs aIntegerMapGenotype
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(K key)
Returnstrue
if the key is contained.int
getIndexOf(K key)
Returns the index of the key.java.util.Collection<K>
getKeys()
Return all keys.java.lang.Integer
getValue(K key)
Returns the value for the specified key.void
init(java.util.Random random)
Initialize this genotype with random values based on the size of thelist
.void
init(java.util.Random random, int n)
Not supported.<G extends Genotype>
GnewInstance()
Constructs a new (empty) instance of thisGenotype
.void
setValue(K key, java.lang.Integer value)
Sets the value for the specified key.java.lang.String
toString()
-
Methods inherited from class org.opt4j.core.genotype.IntegerGenotype
getLowerBound, getUpperBound
-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
-
-
-
Field Detail
-
list
protected final java.util.List<K> list
-
-
Constructor Detail
-
IntegerMapGenotype
public IntegerMapGenotype(java.util.List<K> list, Bounds<java.lang.Integer> bounds)
Constructs aIntegerMapGenotype
.- Parameters:
list
- the list of keysbounds
- the lower and upper bounds
-
IntegerMapGenotype
public IntegerMapGenotype(java.util.List<K> list, int lowerBound, int upperBound)
Constructs aIntegerMapGenotype
with fixed bounds.- Parameters:
list
- the list of keyslowerBound
- the lower boundupperBound
- the upper bound
-
-
Method Detail
-
init
public void init(java.util.Random random)
Initialize this genotype with random values based on the size of thelist
.- Parameters:
random
- the random number generator
-
init
public void init(java.util.Random random, int n)
Not supported. Useinit(Random)
instead.- Overrides:
init
in classIntegerGenotype
- Parameters:
random
- the random number generatorn
- the number of elements in the resulting genotype- See Also:
IntegerGenotype.init(java.util.Random, int)
-
containsKey
public boolean containsKey(K key)
Description copied from interface:MapGenotype
Returnstrue
if the key is contained.- Specified by:
containsKey
in interfaceMapGenotype<K,java.lang.Integer>
- Parameters:
key
- the key- Returns:
true
if the key is contained
-
getValue
public java.lang.Integer getValue(K key)
Description copied from interface:MapGenotype
Returns the value for the specified key. Throws an exception if the key is not contained.- Specified by:
getValue
in interfaceMapGenotype<K,java.lang.Integer>
- Parameters:
key
- the key- Returns:
- the value
- See Also:
MapGenotype.setValue(K, V)
-
setValue
public void setValue(K key, java.lang.Integer value)
Description copied from interface:MapGenotype
Sets the value for the specified key. Throws an exception if the key is not contained.- Specified by:
setValue
in interfaceMapGenotype<K,java.lang.Integer>
- Parameters:
key
- the keyvalue
- the value- See Also:
MapGenotype.getValue(K)
-
newInstance
public <G extends Genotype> G newInstance()
Description copied from interface:Genotype
Constructs a new (empty) instance of thisGenotype
.- Specified by:
newInstance
in interfaceGenotype
- Overrides:
newInstance
in classIntegerGenotype
- Type Parameters:
G
- the type of genotype for an implicit cast- Returns:
- new instance of the genotype
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<java.lang.Integer>
-
getIndexOf
public int getIndexOf(K key)
Description copied from interface:MapGenotype
Returns the index of the key. Throws an exception if the key is not contained.- Specified by:
getIndexOf
in interfaceMapGenotype<K,java.lang.Integer>
- Parameters:
key
- the key- Returns:
- the index
-
getKeys
public java.util.Collection<K> getKeys()
Description copied from interface:MapGenotype
Return all keys.- Specified by:
getKeys
in interfaceMapGenotype<K,java.lang.Integer>
- Returns:
- all keys
-
-