![JAR search and dependency download from the Maven repository](/logo.png)
net.sourceforge.cilib.pso.dynamic.responsestrategies.MultiReactionStrategy 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.dynamic.responsestrategies;
import java.util.ArrayList;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
/**
* 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< EnvironmentChangeResponseStrategy > responses;
public MultiReactionStrategy() {
this.responses = new ArrayList< EnvironmentChangeResponseStrategy >();
}
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
public void performReaction(E 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