net.sourceforge.cilib.pso.dynamic.detectionstrategies.RandomSentryDetectionStrategy 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
The newest version!
/** __ __
* _____ _/ /_/ /_ Computational Intelligence Library (CIlib)
* / ___/ / / / __ \ (c) CIRG @ UP
* / /__/ / / / /_/ / http://cilib.net
* \___/_/_/_/_.___/
*/
package net.sourceforge.cilib.pso.dynamic.detectionstrategies;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import net.sourceforge.cilib.algorithm.Algorithm;
import net.sourceforge.cilib.algorithm.population.HasNeighbourhood;
import net.sourceforge.cilib.algorithm.population.HasTopology;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.math.random.generator.Rand;
import net.sourceforge.cilib.pso.dynamic.DynamicParticle;
import net.sourceforge.cilib.pso.particle.Particle;
public class RandomSentryDetectionStrategy extends EnvironmentChangeDetectionStrategy {
private static final long serialVersionUID = 6254159986113630555L;
private int sentries;
private double theta;
private int[] sentryIDs;
private boolean initialised = false;
ArrayList sentryList;
public RandomSentryDetectionStrategy() {
sentries = 1;
theta = 0.001;
}
public void Initialise(A algorithm){
sentryIDs = new int[sentries];
int populationSize = algorithm.getTopology().length();
//randomly select the sentries among the particles
for(int i=0; i topology = algorithm.getTopology();
this.sentryList = new ArrayList();
Iterator extends Entity> iterator = topology.iterator();
int sentryCounter = 0;
while (iterator.hasNext() && sentryCounter boolean detect(A algorithm) {
if(initialised == false){
this.Initialise(algorithm);
}
boolean envChangeOccured = false;
for (Particle nextSentry : sentryList) {
double oldSentryFitness = nextSentry.getFitness().getValue();
double newSentryFitness = algorithm.getOptimisationProblem().getFitness(nextSentry.getPosition()).getValue();
if(Math.abs(oldSentryFitness - newSentryFitness) >= theta) {
envChangeOccured = true;
break;
}
}
return envChangeOccured;
}
/**
* @return the sentries
*/
public int getSentries() {
return sentries;
}
/**
* @param sentries the sentries to set
*/
public void setSentries(int sentries) {
this.sentries = sentries;
}
/**
* @return the theta
*/
public double getTheta() {
return theta;
}
/**
* @param theta the theta to set
*/
public void setTheta(double theta) {
this.theta = theta;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy