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

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

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

import net.sourceforge.cilib.algorithm.population.SinglePopulationBasedAlgorithm;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.pso.dynamic.DynamicParticle;
import net.sourceforge.cilib.pso.particle.Particle;
import net.sourceforge.cilib.type.types.container.Vector;

/**
 * This reaction strategy initialises new dimensions introduced into the
 * particles. These new dimensions are indicated by initially having the value
 * Double.NaN.
 *
 * @param  some {@link PopulationBasedAlgorithm population based algorithm}
 */
public class InitialiseNaNElementsReactionStrategy extends EnvironmentChangeResponseStrategy {

    public InitialiseNaNElementsReactionStrategy() {
    }

    public InitialiseNaNElementsReactionStrategy(InitialiseNaNElementsReactionStrategy rhs) {
        super(rhs);
    }

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

    /**
     * Initialise the dimensions that have the value of Double.NaN. This is done
     * for all the particles in the topology.
     *
     * {@inheritDoc}
     */
    @Override
    public 

> void performReaction(A algorithm) { fj.data.List entities = algorithm.getTopology(); for (Entity entity : entities) { DynamicParticle particle = (DynamicParticle) entity; //initialise position Vector position = (Vector) particle.getPosition(); for (int curElement = 0; curElement < position.size(); ++curElement) { if (Double.isNaN(position.doubleValueOf(curElement))) { position.get(curElement).randomise(); } } //initialise personal best Vector personalBest = (Vector) particle.getBestPosition(); for (int curElement = 0; curElement < position.size(); ++curElement) { if (Double.isNaN(personalBest.doubleValueOf(curElement))) { personalBest.setReal(curElement, position.doubleValueOf(curElement)); } } //initialise velocity Vector velocity = particle.getVelocity(); for (int curElement = 0; curElement < position.size(); ++curElement) { if (Double.isNaN(velocity.doubleValueOf(curElement))) { velocity.setReal(curElement, 0.0); } } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy