Class Spea2

  • All Implemented Interfaces:
    Selector

    public class Spea2
    extends java.lang.Object
    implements Selector

    The Spea2-Selector is a Java implementation of the SPEA2-MOEA, see "SPEA2: Improving the Strength Pareto Evolutionary Algorithm For Multiobjective Optimization, Eckart Zitzler, Marco Laumanns, and Lothar Thiele, In Evolutionary Methods for Design, Optimisation, and Control, pages 19–26, 2002.".

    The Spea2-Selector will not work properly if the Objectives are not fixed, i.e., the Objectives of an Individual change during the optimization process. This caused by the internal caching of distances, etc. In this case, it is recommended to use the Nsga2.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double[][] distance  
      protected boolean fitnessDirty  
      protected java.util.LinkedList<java.lang.Integer> freeIDs  
      protected java.util.Set<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> individualSets  
      protected java.util.Map<org.opt4j.core.Individual,​org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> map  
      protected org.opt4j.core.common.random.Rand random  
      protected int tournament  
    • Constructor Summary

      Constructors 
      Constructor Description
      Spea2​(int tournament, org.opt4j.core.common.random.Rand random)
      Constructs a Spea2-Selector.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void add​(org.opt4j.core.Individual individual)
      Add a new Individual.
      protected double calculateDistance​(org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w0, org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w1)
      Calculate the distance between two Spea2IndividualSets.
      protected void calculateFitness()
      Calculate the fitness.
      protected double distance​(org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w0, org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w1)
      Return the distance of two Spea2IndividualSets.
      protected java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> getDominated()
      Returns all dominated Spea2IndividualSets (fitness > 0).
      java.util.Collection<org.opt4j.core.Individual> getLames​(int lambda, java.util.Collection<org.opt4j.core.Individual> population)
      Selects a subset of lambda Individuals and returns it as a new Collection.
      java.util.Collection<org.opt4j.core.Individual> getLamesFromNonDominated​(int count)
      Returns a specific number of lames from the non-dominated Individuals.
      protected double getMinDistance​(org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w0)  
      protected java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> getNearest​(int n, java.util.Collection<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> candidates)
      Returns n with nearest neighbor based on distances.
      protected java.util.Map<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet,​java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet>> getNearestPreOrder​(java.util.Collection<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> candidates)
      Helper function to preorder the candidates for getNearest() operation
      protected java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> getNonDominated()
      Returns all non-dominated Spea2IndividualSets (fitness == 0).
      java.util.Collection<org.opt4j.core.Individual> getParents​(int mu, java.util.Collection<org.opt4j.core.Individual> population)
      Selects a subset of Individuals and returns it as a new Collection.
      void init​(int maxsize)
      Sets the maximal number of Individuals.
      protected void remove​(org.opt4j.core.Individual individual)
      Remove an Individual.
      protected void update​(java.util.Collection<org.opt4j.core.Individual> population)
      Update with current population.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • random

        protected final org.opt4j.core.common.random.Rand random
      • tournament

        protected final int tournament
      • map

        protected final java.util.Map<org.opt4j.core.Individual,​org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> map
      • individualSets

        protected final java.util.Set<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> individualSets
      • freeIDs

        protected final java.util.LinkedList<java.lang.Integer> freeIDs
      • distance

        protected double[][] distance
      • fitnessDirty

        protected boolean fitnessDirty
    • Constructor Detail

      • Spea2

        @Inject
        public Spea2​(int tournament,
                     org.opt4j.core.common.random.Rand random)
        Constructs a Spea2-Selector.
        Parameters:
        tournament - the number of individuals that fight against each other to become a parent
        random - the random number generator
    • Method Detail

      • init

        public void init​(int maxsize)
        Description copied from interface: Selector
        Sets the maximal number of Individuals.
        Specified by:
        init in interface Selector
        Parameters:
        maxsize - the number of individuals
      • getParents

        public java.util.Collection<org.opt4j.core.Individual> getParents​(int mu,
                                                                          java.util.Collection<org.opt4j.core.Individual> population)
        Description copied from interface: Selector
        Selects a subset of Individuals and returns it as a new Collection. These so called parents can be used to form the next generation.
        Specified by:
        getParents in interface Selector
        Parameters:
        mu - the number of parents to select
        population - the list of individuals
        Returns:
        the parents
      • getLames

        public java.util.Collection<org.opt4j.core.Individual> getLames​(int lambda,
                                                                        java.util.Collection<org.opt4j.core.Individual> population)
        Description copied from interface: Selector
        Selects a subset of lambda Individuals and returns it as a new Collection. These individuals can be erased in the next generation.
        Specified by:
        getLames in interface Selector
        Parameters:
        lambda - the number of lames to select
        population - the list of individuals
        Returns:
        the worst lambda individuals
      • getLamesFromNonDominated

        public java.util.Collection<org.opt4j.core.Individual> getLamesFromNonDominated​(int count)
        Returns a specific number of lames from the non-dominated Individuals.
        Parameters:
        count - the specified number
        Returns:
        a collection of the lame individuals
      • getNearest

        protected java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> getNearest​(int n,
                                                                                              java.util.Collection<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> candidates)
        Returns n with nearest neighbor based on distances.
        Parameters:
        n - the number of required IndividualSets
        candidates - the candidate IndividualSets
        Returns:
        the n nearest neighbors
      • getNearestPreOrder

        protected java.util.Map<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet,​java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet>> getNearestPreOrder​(java.util.Collection<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> candidates)
        Helper function to preorder the candidates for getNearest() operation
        Parameters:
        candidates - the candidate IndividualSets
        Returns:
        the preordered IndividualSets
      • getMinDistance

        protected double getMinDistance​(org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w0)
      • update

        protected void update​(java.util.Collection<org.opt4j.core.Individual> population)
        Update with current population.
        Parameters:
        population - the current population
      • distance

        protected double distance​(org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w0,
                                  org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w1)
        Return the distance of two Spea2IndividualSets.
        Parameters:
        w0 - first set
        w1 - second set
        Returns:
        the distance
      • add

        protected void add​(org.opt4j.core.Individual individual)
        Add a new Individual.
        Parameters:
        individual - the individual to add
      • remove

        protected void remove​(org.opt4j.core.Individual individual)
        Remove an Individual.
        Parameters:
        individual - the individual to remove
      • calculateDistance

        protected double calculateDistance​(org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w0,
                                           org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet w1)
        Calculate the distance between two Spea2IndividualSets.
        Parameters:
        w0 - the first set
        w1 - the second set
        Returns:
        the distance
      • calculateFitness

        protected void calculateFitness()
        Calculate the fitness.
      • getDominated

        protected java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> getDominated()
        Returns all dominated Spea2IndividualSets (fitness > 0).
        Returns:
        all dominated IndividualSets
      • getNonDominated

        protected java.util.List<org.opt4j.optimizers.ea.Spea2.Spea2IndividualSet> getNonDominated()
        Returns all non-dominated Spea2IndividualSets (fitness == 0).
        Returns:
        all non-dominated individualSets