![JAR search and dependency download from the Maven repository](/logo.png)
net.sourceforge.cilib.pso.hpso.pheromoneupdate.ConstantPheromoneUpdateStrategy 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.hpso.pheromoneupdate;
import net.sourceforge.cilib.controlparameter.ConstantControlParameter;
import net.sourceforge.cilib.controlparameter.ControlParameter;
import net.sourceforge.cilib.entity.EntityType;
import net.sourceforge.cilib.problem.solution.Fitness;
import net.sourceforge.cilib.pso.particle.Particle;
/**
* Calculates the change in pheromone level for a particular particle's behavior
* using three constants for whether the particle did better, the same or worse
* than the previous iteration.
*/
public class ConstantPheromoneUpdateStrategy implements PheromoneUpdateStrategy{
private ControlParameter better;
private ControlParameter same;
private ControlParameter worse;
/**
* Initialises the controlparameters to 1.0, 0.5 and 0.0 for whether the
* particle did better, the same or worse respectively.
*/
public ConstantPheromoneUpdateStrategy() {
this.better = ConstantControlParameter.of(1.0);
this.same = ConstantControlParameter.of(0.5);
this.worse = ConstantControlParameter.of(0.0);
}
/**
* Creates a ConstantPheromoneUpdateStrategy with the same attributes as another
* ConstantPheromoneUpdateStrategy
*
* @param o the other instance ConstantPheromoneUpdateStrategy
*/
public ConstantPheromoneUpdateStrategy(ConstantPheromoneUpdateStrategy o) {
this.better = o.better;
this.same = o.same;
this.worse = o.worse;
}
/**
* {@inheritDoc}
*/
public ConstantPheromoneUpdateStrategy getClone() {
return new ConstantPheromoneUpdateStrategy(this);
}
/**
* Calculates the change in pheromone level for a particular particle's behavior.
*
* @param e The particle whose behavior is being used for the pheromone update
* @return The change in pheromone level for a behavior
*/
@Override
public double updatePheromone(Particle e) {
int compResult = ((Fitness)e.getProperties().get(EntityType.PREVIOUS_FITNESS)).compareTo(e.getFitness());
double result = compResult < 0 ? this.better.getParameter() :
(compResult == 0 ? this.same.getParameter() : this.worse.getParameter());
return result;
}
public void setWorse(ControlParameter worse) {
this.worse = worse;
}
public void setSame(ControlParameter same) {
this.same = same;
}
public void setBetter(ControlParameter better) {
this.better = better;
}
public ControlParameter getWorse() {
return worse;
}
public ControlParameter getSame() {
return same;
}
public ControlParameter getBetter() {
return better;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy