/*
 * Copyright (C) 2003 - 2009
 * Computational Intelligence Research Group (CIRG@UP)
 * Department of Computer Science
 * University of Pretoria
 * South Africa
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package net.sourceforge.cilib.pso.dynamic;

import net.sourceforge.cilib.algorithm.Algorithm;
import net.sourceforge.cilib.entity.EntityType;
import net.sourceforge.cilib.pso.particle.StandardParticle;

/**
 * Special particle type to use with dynamic algorithms. The extra functionality
 * that it adds is the ability to re-evaluate both current and best position of
 * the particle. A dynamic algorithm usually re-evaluates all particles when a
 * change in the environment has been detected.
 *
 * @author Anna Rakitianskaia, Julien Duhain
 */
public class DynamicParticle extends StandardParticle {

    private static final long serialVersionUID = 1752969607979236619L;

    public DynamicParticle() {
        super();
    }

    public DynamicParticle(DynamicParticle copy) {
        super(copy);
    }

    public DynamicParticle getClone() {
           return new DynamicParticle(this);
    }

    /**
     * Re-evaluate both best and current position of the particle.
     */
    public void reevaluate() {
        this.getProperties().put(EntityType.Particle.BEST_FITNESS, getFitnessCalculator().getFitness(this));
        this.calculateFitness();
    }
}

/*
 * Copyright (C) 2003 - 2009
 * Computational Intelligence Research Group (CIRG@UP)
 * Department of Computer Science
 * University of Pretoria
 * South Africa
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package net.sourceforge.cilib.pso.dynamic;

import net.sourceforge.cilib.algorithm.Algorithm;
import net.sourceforge.cilib.entity.EntityType;
import net.sourceforge.cilib.pso.particle.StandardParticle;

/**
 * Special particle type to use with dynamic algorithms. The extra functionality
 * that it adds is the ability to re-evaluate both current and best position of
 * the particle. A dynamic algorithm usually re-evaluates all particles when a
 * change in the environment has been detected.
 *
 * @author Anna Rakitianskaia, Julien Duhain
 */
public class DynamicParticle extends StandardParticle {

    private static final long serialVersionUID = 1752969607979236619L;

    public DynamicParticle() {
        super();
    }

    public DynamicParticle(DynamicParticle copy) {
        super(copy);
    }

    public DynamicParticle getClone() {
           return new DynamicParticle(this);
    }

    /**
     * Re-evaluate both best and current position of the particle.
     */
    public void reevaluate() {
        DynamicParticle dp = this.getClone();
        dp.getProperties().put(EntityType.CANDIDATE_SOLUTION, dp.getBestPosition());
        this.getProperties().put(EntityType.Particle.BEST_FITNESS, getFitnessCalculator().getFitness(dp));

        this.calculateFitness();
    }
}

Update of Dynamic particle re-evaluation.