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

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

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

import fj.F;
import java.util.List;

import net.sourceforge.cilib.algorithm.population.AbstractIterationStrategy;
import net.sourceforge.cilib.controlparameter.ConstantControlParameter;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.entity.EntityType;
import net.sourceforge.cilib.entity.Topologies;
import net.sourceforge.cilib.entity.comparator.SocialBestFitnessComparator;
import net.sourceforge.cilib.entity.operators.CrossoverOperator;
import net.sourceforge.cilib.entity.operators.crossover.real.BlendCrossoverStrategy;
import net.sourceforge.cilib.pso.PSO;
import net.sourceforge.cilib.pso.particle.Particle;
import net.sourceforge.cilib.util.selection.Samples;
import net.sourceforge.cilib.util.selection.recipes.ElitistSelector;
import net.sourceforge.cilib.util.selection.recipes.RouletteWheelSelector;
import net.sourceforge.cilib.util.selection.recipes.Selector;
import net.sourceforge.cilib.util.selection.weighting.CurrentFitness;
import net.sourceforge.cilib.util.selection.weighting.EntityWeighting;


/**
 * ???@article {springerlink:10.1007/s10015-010-0846-z,
 *  author = {Duong, Sam and Kinjo, Hiroshi and Uezato, Eiho and Yamamoto, Tetsuhiko},
 *  affiliation = {Faculty of Engineering, University of the Ryukyus, 1 Senbaru, Nishihara, Okinawa, 903-0213 Japan},
 *  title = {Particle swarm optimization with genetic recombination: a hybrid evolutionary algorithm},
 *  journal = {Artificial Life and Robotics},
 *  publisher = {Springer Japan},
 *  issn = {1433-5298},
 *  keyword = {Computer Science},
 *  pages = {444-449},
 *  volume = {15},
 *  issue = {4},
 *  url = {http://dx.doi.org/10.1007/s10015-010-0846-z},
 *  note = {10.1007/s10015-010-0846-z},
 *  year = {2010}
 *  }
 */
public class HybridEAIterationStrategy extends AbstractIterationStrategy {

    private CrossoverOperator crossover;
    private Selector selector;

    public HybridEAIterationStrategy() {
        BlendCrossoverStrategy cs = new BlendCrossoverStrategy();
        cs.setAlpha(ConstantControlParameter.of(0.4));

        this.crossover = new CrossoverOperator();
        this.crossover.setSelectionStrategy(new RouletteWheelSelector(new EntityWeighting(new CurrentFitness())));
        this.crossover.setCrossoverProbability(ConstantControlParameter.of(0.1));
        this.crossover.setCrossoverStrategy(cs);

        this.selector = new ElitistSelector();
    }

    public HybridEAIterationStrategy(HybridEAIterationStrategy copy) {
        this.crossover = copy.crossover.getClone();
        this.selector = copy.selector;
    }

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

    @Override
    public void performIteration(final PSO algorithm) {
        final fj.data.List topology = algorithm.getTopology();
        int size = topology.length();

        // pos/vel update
        for (Particle current : topology) {
            current.updateVelocity();
            current.updatePosition();

            boundaryConstraint.enforce(current);
            current.calculateFitness();
        }

        // crossover
        fj.data.List offspring = topology.bind(new F>() {
        	public fj.data.List f(Particle p) {
        		List o = crossover.crossover(topology);
        		if (!o.isEmpty()) {
        			return fj.data.List.single(o.get(0));
        		} else {
        			return fj.data.List.nil();
        		}
        	}
        }) ;

        fj.data.List newTopology = fj.data.List.iterableList(selector.on(topology.append(offspring.map(new F(){
        	public Particle f(Particle p) {
        		p.getProperties().put(EntityType.Particle.BEST_POSITION, p.getCandidateSolution());
                p.setNeighbourhoodBest(p);
                p.calculateFitness();
                return p;
        	}
        }))).select(Samples.first(size)));

        algorithm.setTopology(newTopology.map(new F() {
        	public Particle f(Particle p) {
        		Particle nBest = Topologies.getNeighbourhoodBest(topology, p, algorithm.getNeighbourhood(), new SocialBestFitnessComparator());
                p.setNeighbourhoodBest(nBest);
                return p;
        	}
        }));
    }

    public void setSelector(Selector selector) {
        this.selector = selector;
    }

    public Selector getSelector() {
        return selector;
    }

    public void setCrossoverStrategy(CrossoverOperator crossoverStrategy) {
        this.crossover = crossoverStrategy;
    }

    public CrossoverOperator getCrossoverStrategy() {
        return crossover;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy