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

net.sourceforge.cilib.niching.iterationstrategies.EnhancedSpeciation Maven / Gradle / Ivy

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

import java.util.Set;

import net.sourceforge.cilib.algorithm.population.AbstractIterationStrategy;
import net.sourceforge.cilib.algorithm.population.IterationStrategy;
import net.sourceforge.cilib.entity.Topologies;
import net.sourceforge.cilib.pso.PSO;
import net.sourceforge.cilib.pso.iterationstrategies.SynchronousIterationStrategy;
import net.sourceforge.cilib.pso.particle.Particle;
import fj.F;

/**
 * Reinitialises redundant particles but leaves the neighbourhood bests intact.
 */
public class EnhancedSpeciation extends AbstractIterationStrategy {

    private IterationStrategy delegate;

    public EnhancedSpeciation() {
        this.delegate = (IterationStrategy) new SynchronousIterationStrategy();
    }

    public EnhancedSpeciation(EnhancedSpeciation copy) {
        this.delegate = copy.delegate.getClone();
    }

    @Override
    public EnhancedSpeciation getClone() {
        return new EnhancedSpeciation(this);
    }

    @Override
    public void performIteration(PSO algorithm) {
        delegate.performIteration(algorithm);

        final Set nBests = (Set) Topologies.getNeighbourhoodBestEntities(algorithm.getTopology(), algorithm.getNeighbourhood());
        algorithm.setTopology(algorithm.getTopology().map(new F() {
            @Override
            public Particle f(Particle a) {
                if (a.getFitness().compareTo(a.getNeighbourhoodBest().getFitness()) == 0 && !nBests.contains(a)) {
                    a.reinitialise();
                }

                return a;
            }
        }));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy