Package org.moeaframework.algorithm.pso
Class AbstractPSOAlgorithm
java.lang.Object
org.moeaframework.algorithm.AbstractAlgorithm
org.moeaframework.algorithm.pso.AbstractPSOAlgorithm
- All Implemented Interfaces:
Algorithm,Extensible,Configurable,Named,Stateful
Abstract multi-objective particle swarm optimizer (MOPSO).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected NondominatedPopulationThe archive of non-dominated solutions; ornullof no external archive is used.protected DominanceComparatorComparator for updating the local best particles.protected DominanceComparatorComparator for selecting leaders.protected FitnessBasedArchiveThe leaders.protected Solution[]The local best particles.protected MutationMutation operator, ornullif no mutation is defined.protected Solution[]The particles.protected double[][]The speed / velocity of each particle.Fields inherited from class org.moeaframework.algorithm.AbstractAlgorithm
initialized, numberOfEvaluations, problem, terminated -
Constructor Summary
ConstructorsConstructorDescriptionAbstractPSOAlgorithm(Problem problem, int swarmSize, int leaderSize, DominanceComparator leaderComparator, DominanceComparator dominanceComparator, FitnessBasedArchive leaders, NondominatedPopulation archive, Mutation mutation) Constructs a new abstract PSO algorithm. -
Method Summary
Modifier and TypeMethodDescriptioncopyToList(Solution[] solutions) Converts an array of solutions to a list of solutions, creating copies of each solution.protected NondominatedPopulationReturns the archive of non-dominated solutions; ornullof no external archive is used.Returns the current leaders.intReturns the number of leaders, which tracks the best particles according to some fitness criteria.Returns the local best particles.Returns the mutation operator, ornullif no mutation is defined.Returns the current particles.Returns the current best-known result.intReturns the number of particles (aka swarm size or population size).voidPerforms any initialization that is required by this algorithm.protected voiditerate()Performs one iteration of the algorithm.voidloadState(ObjectInputStream stream) Loads the state of this object from the stream.protected voidmutate()Applies the mutation operator to all particles.protected voidmutate(int i) Applies the mutation operator to an individual particle.voidsaveState(ObjectOutputStream stream) Writes the state of this object to the stream.protected SolutionRandomly select a leader.protected voidsetArchive(NondominatedPopulation archive) Sets the archive of non-dominated solutions; ornullof no external archive is used.voidsetLeaderSize(int leaderSize) Sets the number of leaders, which tracks the best particles according to some fitness criteria.voidsetSwarmSize(int swarmSize) Sets the number of particles (aka swarm size or population size).protected voidUpdates the local best particles.protected voidupdatePosition(int i) Update the position of an individual particle.protected voidUpdate the positions of all particles.protected voidUpdate the speeds of all particles.protected voidupdateVelocity(int i) Update the speed of an individual particle.Methods inherited from class org.moeaframework.algorithm.AbstractAlgorithm
assertNotInitialized, evaluate, getExtensions, getNumberOfEvaluations, getProblem, isInitialized, isTerminated, step, terminateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.moeaframework.algorithm.Algorithm
evaluateAll, evaluateAll, getName, run, runMethods inherited from interface org.moeaframework.core.configuration.Configurable
applyConfiguration, getConfigurationMethods inherited from interface org.moeaframework.algorithm.extension.Extensible
addExtension, removeExtension
-
Field Details
-
particles
The particles. -
localBestParticles
The local best particles. -
leaders
The leaders. -
archive
The archive of non-dominated solutions; ornullof no external archive is used. -
velocities
protected double[][] velocitiesThe speed / velocity of each particle. -
leaderComparator
Comparator for selecting leaders. -
dominanceComparator
Comparator for updating the local best particles. -
mutation
Mutation operator, ornullif 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 problemswarmSize- the number of particlesleaderSize- the number of leadersleaderComparator- comparator for selecting leadersdominanceComparator- comparator for updating the local best particlesleaders- non-dominated population for storing the leadersarchive- non-dominated population for storing the external archive; ornullif no external archive is definedmutation- mutation operator, ornullif 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
Returns the mutation operator, ornullif no mutation is defined.- Returns:
- the mutation operator or
null
-
getArchive
Returns the archive of non-dominated solutions; ornullof no external archive is used.- Returns:
- the archive or
null
-
setArchive
Sets the archive of non-dominated solutions; ornullof no external archive is used. This value can only be set before initialization.- Parameters:
archive- the archive ornull.
-
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
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
Description copied from interface:AlgorithmReturns the current best-known result. -
initialize
public void initialize()Description copied from interface:AlgorithmPerforms any initialization that is required by this algorithm. This method should only be called once, though the specific implementation may choose to no-op or throwAlgorithmInitializationExceptionif called multiple times.Implementations should always call
super.initialize()to ensure the algorithm is initialized correctly.- Specified by:
initializein interfaceAlgorithm- Overrides:
initializein classAbstractAlgorithm
-
iterate
protected void iterate()Description copied from class:AbstractAlgorithmPerforms one iteration of the algorithm. This method should be overridden by implementations to perform each logical iteration of the algorithm.- Specified by:
iteratein classAbstractAlgorithm
-
getParticles
Returns the current particles.- Returns:
- the current particles
-
getLocalBestParticles
Returns the local best particles.- Returns:
- the local best particles
-
getLeaders
Returns the current leaders.- Returns:
- the current leaders
-
saveState
Description copied from interface:StatefulWrites the state of this object to the stream. The order that objects are written to the stream is important. We recommend first callingsuper.saveState(stream)followed by writing each field.- Specified by:
saveStatein interfaceStateful- Overrides:
saveStatein classAbstractAlgorithm- Parameters:
stream- the stream- Throws:
IOException- if an I/O error occurred
-
loadState
Description copied from interface:StatefulLoads 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 inStateful.saveState(ObjectOutputStream).- Specified by:
loadStatein interfaceStateful- Overrides:
loadStatein classAbstractAlgorithm- Parameters:
stream- the stream- Throws:
IOException- if an I/O error occurredClassNotFoundException- if the stream referenced a class that is not defined
-
copyToList
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
-