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

net.sourceforge.cilib.pso.dynamic.DynamicIterationStrategy Maven / Gradle / Ivy

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

import net.sourceforge.cilib.algorithm.population.IterationStrategy;
import net.sourceforge.cilib.problem.boundaryconstraint.BoundaryConstraint;
import net.sourceforge.cilib.pso.PSO;
import net.sourceforge.cilib.pso.dynamic.detectionstrategies.EnvironmentChangeDetectionStrategy;
import net.sourceforge.cilib.pso.dynamic.detectionstrategies.RandomSentryDetectionStrategy;
import net.sourceforge.cilib.pso.dynamic.responsestrategies.EnvironmentChangeResponseStrategy;
import net.sourceforge.cilib.pso.dynamic.responsestrategies.PartialReinitialisationResponseStrategy;
import net.sourceforge.cilib.pso.iterationstrategies.SynchronousIterationStrategy;

/**
 * Dynamic iteration strategy for PSO in dynamic environments.
 * In each iteration, it checks for an environmental change, and reinitialises
 * a percentage of the swarm once such a change is detected in order to preserve
 * diversity.
 *
 * The algorithm is adopted from
* @book{focsi, * author= {Andries P. Engelbrecht}, * title= {{Fundamentals of Computational Swarm Intelligence}}, * publisher= {John Wiley \& Sons, Ltd}, * year= {2005} * } * */ public class DynamicIterationStrategy implements IterationStrategy { private static final long serialVersionUID = -4441422301948289718L; private IterationStrategy iterationStrategy; private EnvironmentChangeDetectionStrategy detectionStrategy; private EnvironmentChangeResponseStrategy responseStrategy; /** * Create a new instance of {@linkplain DynamicIterationStrategy}. *

* The following defaults are set in the constructor: * randomiser is instantiated as a MersenneTwister, * theta is set to 0.001, * reinitialisationRatio is set to 0.5 (reinitialise one half of the swarm) */ public DynamicIterationStrategy() { this.iterationStrategy = new SynchronousIterationStrategy(); this.detectionStrategy = new RandomSentryDetectionStrategy(); this.responseStrategy = new PartialReinitialisationResponseStrategy(); } /** * Create a copy of the provided instance. * @param copy The instance to copy. */ public DynamicIterationStrategy(DynamicIterationStrategy copy) { this.iterationStrategy = copy.iterationStrategy.getClone(); this.detectionStrategy = copy.detectionStrategy.getClone(); this.responseStrategy = copy.responseStrategy.getClone(); } /** * {@inheritDoc} */ @Override public DynamicIterationStrategy getClone() { return new DynamicIterationStrategy(this); } /** * Structure of Dynamic iteration strategy with re-initialisation: * *

    *
  1. Check for environment change
  2. *
  3. If the environment has changed:
  4. *
      *
    1. Respond to change
    2. *
        *
      1. Perform normal iteration
      2. *
      */ @Override public void performIteration(PSO algorithm) { boolean hasChanged = detectionStrategy.detect(algorithm); if (hasChanged) { responseStrategy.respond(algorithm); } iterationStrategy.performIteration(algorithm); } /** * Get the current {@linkplain IterationStrategy}. * @return The current {@linkplain IterationStrategy}. */ public IterationStrategy getIterationStrategy() { return iterationStrategy; } /** * Set the {@linkplain IterationStrategy} to be used. * @param iterationStrategy The value to set. */ public void setIterationStrategy(IterationStrategy iterationStrategy) { this.iterationStrategy = iterationStrategy; } /** * Get the currently defined {@linkplain EnvironmentChangeDetectionStrategy}. * @return The current {@linkplain EnvironmentChangeDetectionStrategy}. */ public EnvironmentChangeDetectionStrategy getDetectionStrategy() { return detectionStrategy; } /** * Set the {@linkplain EnvironmentChangeDetectionStrategy} to be used. * @param detectionStrategy The {@linkplain EnvironmentChangeDetectionStrategy} to set. */ public void setDetectionStrategy(EnvironmentChangeDetectionStrategy detectionStrategy) { this.detectionStrategy = detectionStrategy; } /** * Get the currently defined {@linkplain EnvironmentChangeResponseStrategy}, * @return The current {@linkplain EnvironmentChangeResponseStrategy}. */ public EnvironmentChangeResponseStrategy getResponseStrategy() { return responseStrategy; } /** * Set the current {@linkplain EnvironmentChangeResponseStrategy} to use. * @param responseStrategy The {@linkplain EnvironmentChangeResponseStrategy} to set. */ public void setResponseStrategy(EnvironmentChangeResponseStrategy responseStrategy) { this.responseStrategy = responseStrategy; } @Override public BoundaryConstraint getBoundaryConstraint() { return this.iterationStrategy.getBoundaryConstraint(); } @Override public void setBoundaryConstraint(BoundaryConstraint boundaryConstraint) { this.iterationStrategy.setBoundaryConstraint(boundaryConstraint); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy