All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.cilib.pso.iterationstrategies.SynchronousIterationStrategy Maven / Gradle / Ivy

/**           __  __
 *    _____ _/ /_/ /_    Computational Intelligence Library (CIlib)
 *   / ___/ / / / __ \   (c) CIRG @ UP
 *  / /__/ / / / /_/ /   http://cilib.net
 *  \___/_/_/_/_.___/
 */
package net.sourceforge.cilib.pso.iterationstrategies;

import net.sourceforge.cilib.algorithm.population.AbstractIterationStrategy;
import net.sourceforge.cilib.pso.PSO;
import net.sourceforge.cilib.pso.particle.Particle;
import fj.F;

/**
 * Implementation of the synchronous iteration strategy for PSO.
 */
public class SynchronousIterationStrategy extends AbstractIterationStrategy {

    private static final long serialVersionUID = 6617737228912852220L;

    /**
     * {@inheritDoc}
     */
    @Override
    public SynchronousIterationStrategy getClone() {
        return this;
    }

    /**
     * This is an Synchronous strategy:
     *
     * 
    *
  1. For all particles:
  2. *
      *
    1. Update the particle velocity
    2. *
    3. Update the particle position
    4. *
    *
  3. For all particles:
  4. *
      *
    1. Calculate the particle fitness
    2. *
    3. For all particles in the current particle's neighbourhood:
    4. *
        *
      1. Update the neighbourhood best
      2. *
      *
    *
* * @param pso The {@link PSO} to have an iteration applied. */ @Override public void performIteration(final PSO pso) { final fj.data.List topology = pso.getTopology(); final F first = new F() { @Override public Particle f(Particle current) { current.updateVelocity(); current.updatePosition(); boundaryConstraint.enforce(current); return current; } }; final F second = new F() { public Particle f(Particle current) { current.calculateFitness(); for (Particle other : pso.getNeighbourhood().f(topology, current)) { if (current.getSocialFitness().compareTo(other.getNeighbourhoodBest().getSocialFitness()) > 0) { other.setNeighbourhoodBest(current); } } return current; } }; pso.setTopology(topology.map(first).map(second)); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy