MOEA Framework 2.12
API Specification

org.moeaframework.core
Class Population

java.lang.Object
  extended by org.moeaframework.core.Population
All Implemented Interfaces:
Iterable<Solution>
Direct Known Subclasses:
MSOPSRankedPopulation, NondominatedPopulation, NondominatedSortingPopulation, ReferenceVectorGuidedPopulation

public class Population
extends Object
implements Iterable<Solution>

A collection of solutions and common methods for manipulating the collection.


Constructor Summary
Population()
          Constructs an empty population.
Population(Iterable<? extends Solution> iterable)
          Constructs a population initialized with a collection of solutions.
Population(T[] solutions)
          Constructs a population initialized with an array of solutions.
 
Method Summary
 boolean add(Solution solution)
          Adds the specified solution to this population.
 boolean addAll(Iterable<? extends Solution> iterable)
          Adds a collection of solutions to this population.
<T extends Solution>
boolean
addAll(T[] solutions)
          Adds an array of solutions to this population.
 void clear()
          Removes all solutions from this population.
 boolean contains(Solution solution)
          Returns true if this population contains the specified solution; false otherwise.
 boolean containsAll(Iterable<? extends Solution> iterable)
          Returns true if this population contains all the solutions in the specified collection; false otherwise.
<T extends Solution>
boolean
containsAll(T[] solutions)
          Returns true if this population contains all the solutions in the specified array; false otherwise.
 Solution get(int index)
          Returns the solution at the specified index in this population.
 int indexOf(Solution solution)
          Returns the index of the specified solution in this population.
 boolean isEmpty()
          Returns true if this population contains no solutions; false otherwise.
 Iterator<Solution> iterator()
          Returns an iterator for accessing the solutions in this population.
 void remove(int index)
          Removes the solution at the specified index from this population.
 boolean remove(Solution solution)
          Removes the specified solution from this population, if present.
 boolean removeAll(Iterable<? extends Solution> iterable)
          Removes all solutions in the specified collection from this population.
<T extends Solution>
boolean
removeAll(T[] solutions)
          Removes all solutions in the specified array from this population.
 void replace(int index, Solution solution)
          Replaces the solution at the given index.
 int size()
          Returns the number of solutions in this population.
 void sort(Comparator<? super Solution> comparator)
          Sorts the solutions in this population using the specified comparator.
 void truncate(int size, Comparator<? super Solution> comparator)
          Sorts this population using the specified comparator and removes the last (maximum) solutions until this population's size is within the specified size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Population

public Population()
Constructs an empty population.


Population

public Population(Iterable<? extends Solution> iterable)
Constructs a population initialized with a collection of solutions.

Parameters:
iterable - the collection of solutions for initializing this population

Population

public Population(T[] solutions)
Constructs a population initialized with an array of solutions.

Parameters:
solutions - the array of solutions for initializing this population
Method Detail

get

public Solution get(int index)
Returns the solution at the specified index in this population.

Parameters:
index - the index of the solution to be returned
Returns:
the solution at the specified index
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0) || (index >= size())

remove

public void remove(int index)
Removes the solution at the specified index from this population.

Parameters:
index - the index of the solution to be removed
Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0) || (index >= size())

indexOf

public int indexOf(Solution solution)
Returns the index of the specified solution in this population. Invocations of certain methods on this population may alter the ordering of solutions, so the index returned should be used immediately by the get or remove methods.

Parameters:
solution - the solution whose index is to be returned
Returns:
the index of the specified solution

add

public boolean add(Solution solution)
Adds the specified solution to this population.

Parameters:
solution - the solution to be added
Returns:
true if the population was modified as a result of this method; false otherwise.

addAll

public boolean addAll(Iterable<? extends Solution> iterable)
Adds a collection of solutions to this population.

Parameters:
iterable - the collection of solutions to be added
Returns:
true if the population was modified as a result of this method; false otherwise

addAll

public <T extends Solution> boolean addAll(T[] solutions)
Adds an array of solutions to this population.

Parameters:
solutions - the solutions to be added
Returns:
true if the population was modified as a result of this method; false otherwise

replace

public void replace(int index,
                    Solution solution)
Replaces the solution at the given index.

Parameters:
index - the index to replace
solution - the new solution

clear

public void clear()
Removes all solutions from this population.


contains

public boolean contains(Solution solution)
Returns true if this population contains the specified solution; false otherwise.

Parameters:
solution - the solution whose presence is tested
Returns:
true if this population contains the specified solution; false otherwise

containsAll

public boolean containsAll(Iterable<? extends Solution> iterable)
Returns true if this population contains all the solutions in the specified collection; false otherwise.

Parameters:
iterable - the collection whose presence is tested
Returns:
true if this population contains all the solutions in the specified collection; false otherwise

containsAll

public <T extends Solution> boolean containsAll(T[] solutions)
Returns true if this population contains all the solutions in the specified array; false otherwise.

Parameters:
solutions - the array whose presence is tested
Returns:
true if this population contains all the solutions in the specified array; false otherwise

isEmpty

public boolean isEmpty()
Returns true if this population contains no solutions; false otherwise.

Returns:
true if this population contains no solutions; false otherwise.

iterator

public Iterator<Solution> iterator()
Returns an iterator for accessing the solutions in this population.

Specified by:
iterator in interface Iterable<Solution>

remove

public boolean remove(Solution solution)
Removes the specified solution from this population, if present.

Parameters:
solution - the solution to be removed
Returns:
true if this population was modified as a result of this method; false otherwise

removeAll

public boolean removeAll(Iterable<? extends Solution> iterable)
Removes all solutions in the specified collection from this population.

Parameters:
iterable - the collection of solutions to be removed
Returns:
true if this population was modified as a result of this method; false otherwise

removeAll

public <T extends Solution> boolean removeAll(T[] solutions)
Removes all solutions in the specified array from this population.

Parameters:
solutions - the array of solutions to be removed
Returns:
true if this population was modified as a result of this method; false otherwise

size

public int size()
Returns the number of solutions in this population.

Returns:
the number of solutions in this population

sort

public void sort(Comparator<? super Solution> comparator)
Sorts the solutions in this population using the specified comparator. Invocations of certain methods on this population may alter the ordering of solutions, so the get, remove and iteration methods should be called immediately after invoking this method.

Parameters:
comparator - the comparator to be used for sorting

truncate

public void truncate(int size,
                     Comparator<? super Solution> comparator)
Sorts this population using the specified comparator and removes the last (maximum) solutions until this population's size is within the specified size.

Parameters:
size - the target population size after truncation
comparator - the comparator to be used for truncation

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!