eaLib API Docs
Last Modified : January 7 2002

mss.ea.core
Class SortedPopulation

java.lang.Object
  |
  +--mss.ea.core.GeneticOperator
        |
        +--mss.ea.core.AbstractPopulation
              |
              +--mss.ea.core.SortedPopulation
All Implemented Interfaces:
java.util.EventListener, IndividualGate, NotificationListener
Direct Known Subclasses:
SortedSteadyPopulation

public class SortedPopulation
extends AbstractPopulation

Base class for a population.

Since:
0.1
Version:
$Revision: 1.4 $ $Date: 2001/11/23 12:41:06 $
Author:
Andreas Rummler

Field Summary
protected  IndividualComparator comp
          Individual comparator used for comparison of individuals.
protected  SortedVector pop
          Sorted vector with individuals, which represents the population.
 
Fields inherited from class mss.ea.core.AbstractPopulation
filter, gc
 
Fields inherited from class mss.ea.core.GeneticOperator
description, ID, name
 
Constructor Summary
SortedPopulation()
          Default constructor.
SortedPopulation(IndividualComparator comp)
          Constructor with individual comparator.
SortedPopulation(IndividualComparator comp, IndividualFilter filt)
          Constructor with individual comparator and filter.
 
Method Summary
 void add(Individual i)
          Adds an individual.
 void add(Individual[] ia)
          Adds an array with individuals to the population.
 void add(java.util.Vector iv)
          Deprecated. should not be used any longer
 Individual get(int i)
          Gets the individual at a particular index.
 Individual getAverage()
          Gets an average individual from this population.
 Individual getBest()
          Gets the best individual from this population.
 IndividualComparator getComparator()
          Gets the individual comparator.
 int getIndex(Individual i)
          Gets the index of a particular individual.
 Individual getWorst()
          Gets the worst individual from this population.
 void remove(int i)
          Removes an individual from the population.
 void remove(int lowerIndex, int upperIndex)
          Removes a range of individuals.
 void removeAll()
          Removes all individuals.
 void replace(Individual i, int index)
          Replaces an individual at a position.
 void setComparator(IndividualComparator comp)
          Sets a new individual comparator.
 int size()
          Gets the current size of the population.
 java.util.List subList(int fromIndex, int toIndex)
          Gets a part of the population as a list.
 Individual[] toArray()
          Gets a copy of the internal array with all individuals.
 java.util.Collection toCollection()
          Gets a all individuals of the population contained in an array list.
 
Methods inherited from class mss.ea.core.AbstractPopulation
add, add, getCounter, getFilter, getStream, notificationSignal, setFilter, toStream
 
Methods inherited from class mss.ea.core.GeneticOperator
getDescription, getID, getName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

comp

protected IndividualComparator comp
Individual comparator used for comparison of individuals.

pop

protected SortedVector pop
Sorted vector with individuals, which represents the population.
Constructor Detail

SortedPopulation

public SortedPopulation()
Default constructor.

SortedPopulation

public SortedPopulation(IndividualComparator comp)
Constructor with individual comparator.
Parameters:
comp - individual comparator

SortedPopulation

public SortedPopulation(IndividualComparator comp,
                        IndividualFilter filt)
Constructor with individual comparator and filter.
Parameters:
comp - individual comparator
filter - individual filter
Method Detail

size

public int size()
Gets the current size of the population.
Overrides:
size in class AbstractPopulation
Returns:
population size

add

public void add(Individual i)
Adds an individual.
Overrides:
add in class AbstractPopulation
Parameters:
i - individual to add

add

public void add(Individual[] ia)
Adds an array with individuals to the population.
Overrides:
add in class AbstractPopulation
Parameters:
ia - array with individuals

add

public void add(java.util.Vector iv)
Deprecated. should not be used any longer

Adds a vector with individuals to the population.
Parameters:
iv - vector with individuals

get

public Individual get(int i)
Gets the individual at a particular index. Attention : the first individual has the index 0, but the rank 1 !!!
Overrides:
get in class AbstractPopulation
Parameters:
i - position of the individual
Returns:
individual at given position

getBest

public Individual getBest()
Gets the best individual from this population.
Returns:
best individual

getAverage

public Individual getAverage()
Gets an average individual from this population.
Returns:
individual at position (population size / 2)

getWorst

public Individual getWorst()
Gets the worst individual from this population.
Returns:
worst individual

getIndex

public int getIndex(Individual i)
Gets the index of a particular individual.
Parameters:
i - individual
Returns:
position of the given individual

toArray

public Individual[] toArray()
Gets a copy of the internal array with all individuals.
Overrides:
toArray in class AbstractPopulation
Returns:
all individuals of the population as an array

toCollection

public java.util.Collection toCollection()
Gets a all individuals of the population contained in an array list.
Overrides:
toCollection in class AbstractPopulation
Returns:
all individuals contained in an array list

replace

public void replace(Individual i,
                    int index)
Replaces an individual at a position. The new individual will be inserted according to it's score.
Overrides:
replace in class AbstractPopulation
Parameters:
i - new individual
index - position of the individual to replace

remove

public void remove(int i)
Removes an individual from the population.
Overrides:
remove in class AbstractPopulation
Parameters:
i - position of the individual

removeAll

public void removeAll()
Removes all individuals.
Overrides:
removeAll in class AbstractPopulation

remove

public void remove(int lowerIndex,
                   int upperIndex)
Removes a range of individuals. The range reaches from lowerIndex (inclusive) to upperIndex (exclusive).
Overrides:
remove in class AbstractPopulation
Parameters:
lowerIndex - lower bound
upperIndex - upper bound

getComparator

public IndividualComparator getComparator()
Gets the individual comparator. This method returns null, if no comparator is set.
Returns:
used individual comparator or null

setComparator

public void setComparator(IndividualComparator comp)
Sets a new individual comparator.
Parameters:
comp - new individual comparator

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Gets a part of the population as a list. The liste contains all individuals between two indexes.
Parameters:
fromIndex - lower index
toIndex - upper index
Returns:
list with individuals

eaLib API Docs
Last Modified : January 7 2002

Copyright © 2000-2001 Technical University of Ilmenau, Department ESS