K
- the type of keysV
- the type of elementspublic class SelectMapGenotype<K,V> extends IntegerGenotype implements MapGenotype<K,V>
The SelectMapGenotype
selects for each key an element from a given
list.
Example problem: Choose for each of five balls ball1,
ball2, ball3, ball4, ball5 a
color. Available colors are blue, green, and red.
Example usage:
Example instance: [ball1=green, ball2=red, ball3=red, ball4=blue, ball5=blue]SelectMapGenotype<Ball, Color> genotype = new SelectMapGenotype<Ball, Color>(Arrays.asList(ball1, ball2, ball3, ball4, ball5), Arrays.asList(Color.BLUE, Color.GREEN, Color.RED)); genotype.init(new Random());
Modifier and Type | Class and Description |
---|---|
protected static class |
SelectMapGenotype.SelectBounds<O,P> |
Modifier and Type | Field and Description |
---|---|
protected java.util.List<K> |
keys |
protected java.util.Map<K,java.util.List<V>> |
values |
bounds
Constructor and Description |
---|
SelectMapGenotype(java.util.List<K> keys,
java.util.List<V> values)
Constructs a
SelectMapGenotype . |
SelectMapGenotype(java.util.List<K> keys,
java.util.Map<K,java.util.List<V>> values)
Constructs a
SelectMapGenotype . |
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(K key)
Returns
true if the key is contained. |
int |
getIndexOf(K key)
Returns the index of the key.
|
java.util.Collection<K> |
getKeys()
Return all keys.
|
V |
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 the
key set. |
void |
init(java.util.Random random,
int n)
Not supported.
|
<G extends Genotype> |
newInstance()
Constructs a new (empty) instance of this
Genotype . |
void |
setValue(K key,
V value)
Sets the value for the specified key.
|
java.lang.String |
toString() |
getLowerBound, getUpperBound
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
finalize, getClass, notify, notifyAll, wait, wait, wait
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
protected final java.util.List<K> keys
public SelectMapGenotype(java.util.List<K> keys, java.util.Map<K,java.util.List<V>> values)
SelectMapGenotype
.keys
- the keysvalues
- the valuespublic SelectMapGenotype(java.util.List<K> keys, java.util.List<V> values)
SelectMapGenotype
. Here, each key has the same
target list of element values.keys
- the keysvalues
- the valuespublic void init(java.util.Random random)
key
set.random
- the random number generatorpublic void init(java.util.Random random, int n)
init(Random)
instead.init
in class IntegerGenotype
random
- the random number generatorn
- the number of elements in the resulting genotypeIntegerGenotype.init(java.util.Random, int)
public boolean containsKey(K key)
MapGenotype
true
if the key is contained.containsKey
in interface MapGenotype<K,V>
key
- the keytrue
if the key is containedpublic int getIndexOf(K key)
MapGenotype
getIndexOf
in interface MapGenotype<K,V>
key
- the keypublic V getValue(K key)
MapGenotype
getValue
in interface MapGenotype<K,V>
key
- the keyMapGenotype.setValue(K, V)
public void setValue(K key, V value)
MapGenotype
setValue
in interface MapGenotype<K,V>
key
- the keyvalue
- the valueMapGenotype.getValue(K)
public <G extends Genotype> G newInstance()
Genotype
Genotype
.newInstance
in interface Genotype
newInstance
in class IntegerGenotype
G
- the type of genotype for an implicit castpublic java.lang.String toString()
toString
in class java.util.AbstractCollection<java.lang.Integer>
public java.util.Collection<K> getKeys()
MapGenotype
getKeys
in interface MapGenotype<K,V>