Package org.moeaframework.algorithm.pso
Class AbstractPSOAlgorithm
java.lang.Object
org.moeaframework.algorithm.AbstractAlgorithm
org.moeaframework.algorithm.pso.AbstractPSOAlgorithm
- All Implemented Interfaces:
Extensible
,Algorithm
,Configurable
,Stateful
Abstract multi-objective particle swarm optimizer (MOPSO).
-
Field Summary
Modifier and TypeFieldDescriptionprotected NondominatedPopulation
The archive of non-dominated solutions; ornull
of no external archive is used.protected DominanceComparator
Comparator for updating the local best particles.protected DominanceComparator
Comparator for selecting leaders.protected FitnessBasedArchive
The leaders.protected Solution[]
The local best particles.protected Mutation
Mutation operator, ornull
if 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
ConstructorDescriptionAbstractPSOAlgorithm
(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 NondominatedPopulation
Returns the archive of non-dominated solutions; ornull
of no external archive is used.Returns the current leaders.int
Returns the number of leaders, which tracks the best particles according to some fitness criteria.Returns the local best particles.Returns the mutation operator, ornull
if no mutation is defined.Returns the current particles.Returns the current best-known result.int
Returns the number of particles (aka swarm size or population size).void
Performs any initialization that is required by this algorithm.protected void
iterate()
Performs one iteration of the algorithm.void
loadState
(ObjectInputStream stream) Loads the state of this object from the stream.protected void
mutate()
Applies the mutation operator to all particles.protected void
mutate
(int i) Applies the mutation operator to an individual particle.void
saveState
(ObjectOutputStream stream) Writes the state of this object to the stream.protected Solution
Randomly select a leader.protected void
setArchive
(NondominatedPopulation archive) Sets the archive of non-dominated solutions; ornull
of no external archive is used.void
setLeaderSize
(int leaderSize) Sets the number of leaders, which tracks the best particles according to some fitness criteria.void
setSwarmSize
(int swarmSize) Sets the number of particles (aka swarm size or population size).protected void
Updates the local best particles.protected void
updatePosition
(int i) Update the position of an individual particle.protected void
Update the positions of all particles.protected void
Update the speeds of all particles.protected void
updateVelocity
(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, terminate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.moeaframework.core.Algorithm
evaluateAll, evaluateAll, run, run
Methods inherited from interface org.moeaframework.core.configuration.Configurable
applyConfiguration, getConfiguration
Methods 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; ornull
of 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, ornull
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 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; ornull
if no external archive is definedmutation
- mutation operator, ornull
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
Returns the mutation operator, ornull
if no mutation is defined.- Returns:
- the mutation operator or
null
-
getArchive
Returns the archive of non-dominated solutions; ornull
of no external archive is used.- Returns:
- the archive or
null
-
setArchive
Sets the archive of non-dominated solutions; ornull
of 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:Algorithm
Returns the current best-known result. -
initialize
public void initialize()Description copied from interface:Algorithm
Performs 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 throwAlgorithmInitializationException
if called multiple times.Implementations should always call
super.initialize()
to ensure the algorithm is initialized correctly.- Specified by:
initialize
in interfaceAlgorithm
- Overrides:
initialize
in classAbstractAlgorithm
-
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 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:Stateful
Writes 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:
saveState
in interfaceStateful
- Overrides:
saveState
in classAbstractAlgorithm
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurred
-
loadState
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 inStateful.saveState(ObjectOutputStream)
.- Specified by:
loadState
in interfaceStateful
- Overrides:
loadState
in 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
-