![JAR search and dependency download from the Maven repository](/logo.png)
net.sourceforge.cilib.pso.iterationstrategies.ASynchronousIterationStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cilib-library Show documentation
Show all versions of cilib-library Show documentation
A library of composable components enabling simpler Computational Intelligence
/** __ __
* _____ _/ /_/ /_ Computational Intelligence Library (CIlib)
* / ___/ / / / __ \ (c) CIRG @ UP
* / /__/ / / / /_/ / http://cilib.net
* \___/_/_/_/_.___/
*/
package net.sourceforge.cilib.pso.iterationstrategies;
import fj.F;
import net.sourceforge.cilib.algorithm.population.AbstractIterationStrategy;
import net.sourceforge.cilib.entity.Topology;
import net.sourceforge.cilib.pso.PSO;
import net.sourceforge.cilib.pso.particle.Particle;
/**
* Implementation of the asynchronous iteration strategy for PSO.
*/
public class ASynchronousIterationStrategy extends AbstractIterationStrategy {
private static final long serialVersionUID = -3511991873784185698L;
private F additionalStep = new F() {
@Override
public Particle f(Particle a) {
return a;
}
};
/**
* {@inheritDoc}
*/
@Override
public ASynchronousIterationStrategy getClone() {
return this;
}
/**
* This is an ASynchronous strategy:
*
* - For all particles:
*
* - Update the particle velocity
* - Update the particle position
* - Calculate the particle fitness
* - For all particles in the current particle's neighbourhood
* - Update the neighbourhood best
*
*
*
* @see net.sourceforge.cilib.PSO.IterationStrategy#performIteration()
* @param algorithm The algorithm to which an iteration is to be applied.
*/
public void performIteration(PSO algorithm) {
Topology topology = algorithm.getTopology();
for (Particle current : topology) {
current.updateVelocity(); // TODO: replace with visitor (will simplify particle interface)
current.updatePosition(); // TODO: replace with visitor (will simplify particle interface)
boundaryConstraint.enforce(current);
current.calculateFitness();
Particle newParticle = additionalStep.f(current);
topology.set(topology.indexOf(current), newParticle);
for (Particle other : topology.neighbourhood(current)) {
if (current.getSocialFitness().compareTo(other.getNeighbourhoodBest().getSocialFitness()) > 0) {
other.setNeighbourhoodBest(newParticle); // TODO: neighbourhood visitor?
}
}
}
}
public void setAdditionalStep(F additionalStep) {
this.additionalStep = additionalStep;
}
public F getAdditionalStep() {
return additionalStep;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy