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

net.sourceforge.cilib.pso.dynamic.responsestrategies.MultiReactionStrategy Maven / Gradle / Ivy

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

import java.util.ArrayList;

import com.google.common.collect.Lists;

import net.sourceforge.cilib.algorithm.population.SinglePopulationBasedAlgorithm;
import net.sourceforge.cilib.pso.particle.Particle;

/**
 * This {@link EnvironmentChangeResponseStrategy reaction strategy} constructs a
 * constructs a list of {@link EnvironmentChangeResponseStrategy reaction strategies}.
 * When it is prompted to perform a reaction, it will call the response strategies
 * in the list, in sequence.
 *
 * @param  some {@link PopulationBasedAlgorithm population based algorithm}
 */
public class MultiReactionStrategy extends EnvironmentChangeResponseStrategy {

    protected ArrayList responses;

    public MultiReactionStrategy() {
        this.responses = Lists.newArrayList();
    }

    public MultiReactionStrategy(MultiReactionStrategy rhs) {
        super(rhs);
        
        for (EnvironmentChangeResponseStrategy response : rhs.responses) {
            this.responses.add(response);
        }
    }

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

    /**
     * Performs multiple reaction strategies, in the order in which they were
     * added via the addResponseStrategy method.
     *
     * {@inheritDoc}
     */
    @Override
	protected 

> void performReaction( A algorithm) { for (EnvironmentChangeResponseStrategy response : responses) { response.performReaction(algorithm); } } /** * Adds a response strategy to the end of the list of responses that have to * be performed. * * @param response The response strategy that has to be added. */ public void addResponseStrategy(EnvironmentChangeResponseStrategy response) { responses.add(response); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy