Class AbstractPSOAlgorithm

java.lang.Object
org.moeaframework.algorithm.AbstractAlgorithm
org.moeaframework.algorithm.pso.AbstractPSOAlgorithm
All Implemented Interfaces:
Algorithm, Configurable, Stateful
Direct Known Subclasses:
OMOPSO, SMPSO

public abstract class AbstractPSOAlgorithm extends AbstractAlgorithm implements Configurable
Abstract multi-objective particle swarm optimizer (MOPSO).
  • Field Details

    • particles

      protected Solution[] particles
      The particles.
    • localBestParticles

      protected Solution[] localBestParticles
      The local best particles.
    • leaders

      protected FitnessBasedArchive leaders
      The leaders.
    • archive

      protected NondominatedPopulation archive
      The archive of non-dominated solutions; or null of no external archive is used.
    • velocities

      protected double[][] velocities
      The speed / velocity of each particle.
    • leaderComparator

      protected DominanceComparator leaderComparator
      Comparator for selecting leaders.
    • dominanceComparator

      protected DominanceComparator dominanceComparator
      Comparator for updating the local best particles.
    • mutation

      protected Mutation mutation
      Mutation operator, or null if no mutation is defined.
  • Constructor Details

    • AbstractPSOAlgorithm

      public AbstractPSOAlgorithm(Problem problem, int swarmSize, int leaderSize, DominanceComparator leaderComparator, DominanceComparator dominanceComparator, FitnessBasedArchive leaders, NondominatedPopulation archive, Mutation mutation)
      Constructs a new abstract PSO algorithm.
      Parameters:
      problem - the problem
      swarmSize - the number of particles
      leaderSize - the number of leaders
      leaderComparator - comparator for selecting leaders
      dominanceComparator - comparator for updating the local best particles
      leaders - non-dominated population for storing the leaders
      archive - non-dominated population for storing the external archive; or null if no external archive is defined
      mutation - mutation operator, or null if no mutation is defined
  • Method Details

    • getSwarmSize

      public int getSwarmSize()
      Returns the number of particles (aka swarm size or population size).
      Returns:
      the swarm size
    • setSwarmSize

      public void setSwarmSize(int swarmSize)
      Sets the number of particles (aka swarm size or population size). This value can only be set before initialization.
      Parameters:
      swarmSize - the swarm size
    • getLeaderSize

      public int getLeaderSize()
      Returns the number of leaders, which tracks the best particles according to some fitness criteria.
      Returns:
      the leader size
    • setLeaderSize

      public void setLeaderSize(int leaderSize)
      Sets the number of leaders, which tracks the best particles according to some fitness criteria. This value can only be set before initialization.
      Parameters:
      leaderSize - the leader size
    • getMutation

      public Mutation getMutation()
      Returns the mutation operator, or null if no mutation is defined.
      Returns:
      the mutation operator or null
    • getArchive

      protected NondominatedPopulation getArchive()
      Returns the archive of non-dominated solutions; or null of no external archive is used.
      Returns:
      the archive or null
    • setArchive

      protected void setArchive(NondominatedPopulation archive)
      Sets the archive of non-dominated solutions; or null of no external archive is used. This value can only be set before initialization.
      Parameters:
      archive - the archive or null.
    • updateVelocities

      protected void updateVelocities()
      Update the speeds of all particles.
    • updateVelocity

      protected void updateVelocity(int i)
      Update the speed of an individual particle.
      Parameters:
      i - the index of the particle
    • updatePositions

      protected void updatePositions()
      Update the positions of all particles.
    • updatePosition

      protected void updatePosition(int i)
      Update the position of an individual particle.
      Parameters:
      i - the index of the particle
    • selectLeader

      protected Solution selectLeader()
      Randomly select a leader.
      Returns:
      the selected leader
    • updateLocalBest

      protected void updateLocalBest()
      Updates the local best particles.
    • mutate

      protected void mutate()
      Applies the mutation operator to all particles.
    • mutate

      protected void mutate(int i)
      Applies the mutation operator to an individual particle.
      Parameters:
      i - the index of the particle
    • getResult

      public NondominatedPopulation getResult()
      Description copied from interface: Algorithm
      Returns the current best-known result.
      Specified by:
      getResult in interface Algorithm
      Returns:
      the current best-known result
    • initialize

      protected void initialize()
      Description copied from class: AbstractAlgorithm
      Performs any initialization that is required by this algorithm. This method is called automatically on the first invocation of AbstractAlgorithm.step(). Implementations should always invoke super.initialize() to ensure the algorithm is initialized correctly.
      Overrides:
      initialize in class AbstractAlgorithm
    • iterate

      protected void iterate()
      Description copied from class: AbstractAlgorithm
      Performs one iteration of the algorithm. This method should be overridden by implementations to perform each logical iteration of the algorithm.
      Specified by:
      iterate in class AbstractAlgorithm
    • getParticles

      public List<Solution> getParticles()
      Returns the current particles.
      Returns:
      the current particles
    • getLocalBestParticles

      public List<Solution> getLocalBestParticles()
      Returns the local best particles.
      Returns:
      the local best particles
    • getLeaders

      public List<Solution> getLeaders()
      Returns the current leaders.
      Returns:
      the current leaders
    • saveState

      public void saveState(ObjectOutputStream stream) throws IOException
      Description copied from interface: Stateful
      Writes the state of this object to the stream. The order that objects are written to the stream is important. We recommend first calling super.saveState(stream) followed by writing each field.
      Specified by:
      saveState in interface Stateful
      Overrides:
      saveState in class AbstractAlgorithm
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
    • loadState

      public void loadState(ObjectInputStream stream) throws IOException, ClassNotFoundException
      Description copied from interface: Stateful
      Loads the state of this object from the stream. The order for reading objects from the stream must match the order they are written to the stream in Stateful.saveState(ObjectOutputStream).
      Specified by:
      loadState in interface Stateful
      Overrides:
      loadState in class AbstractAlgorithm
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
      ClassNotFoundException - if the stream referenced a class that is not defined
    • copyToList

      protected static List<Solution> copyToList(Solution[] solutions)
      Converts an array of solutions to a list of solutions, creating copies of each solution.
      Parameters:
      solutions - the array of solutions
      Returns:
      the list of copied solutions