|
From: Theuns C. <the...@gm...> - 2009-06-10 06:42:09
|
---
.../pso/dynamic/DynamicIterationStrategy.java | 26 ++--
.../RandomSentryDetectionStrategy.java | 128 --------------------
... => RandomSentryEntitiesDetectionStrategy.java} | 10 +-
.../RandomSentryPointsDetectionStrategy.java | 2 +-
xml/dynamic-vepso.xml | 2 +-
5 files changed, 20 insertions(+), 148 deletions(-)
delete mode 100644 src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryDetectionStrategy.java
rename src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/{RandomSentriesDetectionStrategy.java => RandomSentryEntitiesDetectionStrategy.java} (91%)
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/DynamicIterationStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/DynamicIterationStrategy.java
index 5ead1c9..2081e69 100644
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/DynamicIterationStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/pso/dynamic/DynamicIterationStrategy.java
@@ -24,7 +24,7 @@ package net.sourceforge.cilib.pso.dynamic;
import net.sourceforge.cilib.algorithm.population.IterationStrategy;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.pso.dynamic.detectionstrategies.EnvironmentChangeDetectionStrategy;
-import net.sourceforge.cilib.pso.dynamic.detectionstrategies.RandomSentriesDetectionStrategy;
+import net.sourceforge.cilib.pso.dynamic.detectionstrategies.RandomSentryEntitiesDetectionStrategy;
import net.sourceforge.cilib.pso.dynamic.responsestrategies.EnvironmentChangeResponseStrategy;
import net.sourceforge.cilib.pso.dynamic.responsestrategies.ReinitializationReactionStrategy;
@@ -41,17 +41,17 @@ import net.sourceforge.cilib.pso.dynamic.responsestrategies.ReinitializationReac
public class DynamicIterationStrategy<E extends PopulationBasedAlgorithm> implements IterationStrategy<E> {
private static final long serialVersionUID = -4441422301948289718L;
- private IterationStrategy<PopulationBasedAlgorithm> iterationStrategy;
- private EnvironmentChangeDetectionStrategy<PopulationBasedAlgorithm> detectionStrategy;
- private EnvironmentChangeResponseStrategy<PopulationBasedAlgorithm> responseStrategy;
+ private IterationStrategy<E> iterationStrategy;
+ private EnvironmentChangeDetectionStrategy<E> detectionStrategy;
+ private EnvironmentChangeResponseStrategy<E> responseStrategy;
/**
- * Create a new instance.
+ * Create a new instance of {@linkplain DynamicIterationStrategy}.
*/
public DynamicIterationStrategy() {
//this.iterationStrategy = new SynchronousIterationStrategy();
- this.detectionStrategy = new RandomSentriesDetectionStrategy<PopulationBasedAlgorithm>();
- this.responseStrategy = new ReinitializationReactionStrategy<PopulationBasedAlgorithm>();
+ this.detectionStrategy = new RandomSentryEntitiesDetectionStrategy<E>();
+ this.responseStrategy = new ReinitializationReactionStrategy<E>();
}
/**
@@ -101,7 +101,7 @@ public class DynamicIterationStrategy<E extends PopulationBasedAlgorithm> implem
* Get the current {@linkplain IterationStrategy}.
* @return The current {@linkplain IterationStrategy}.
*/
- public IterationStrategy<PopulationBasedAlgorithm> getIterationStrategy() {
+ public IterationStrategy<E> getIterationStrategy() {
return iterationStrategy;
}
@@ -109,7 +109,7 @@ public class DynamicIterationStrategy<E extends PopulationBasedAlgorithm> implem
* Set the {@linkplain IterationStrategy} to be used.
* @param iterationStrategy The value to set.
*/
- public void setIterationStrategy(IterationStrategy<PopulationBasedAlgorithm> iterationStrategy) {
+ public void setIterationStrategy(IterationStrategy<E> iterationStrategy) {
this.iterationStrategy = iterationStrategy;
}
@@ -117,7 +117,7 @@ public class DynamicIterationStrategy<E extends PopulationBasedAlgorithm> implem
* Get the currently defined {@linkplain EnvironmentChangeDetectionStrategy}.
* @return The current {@linkplain EnvironmentChangeDetectionStrategy}.
*/
- public EnvironmentChangeDetectionStrategy<PopulationBasedAlgorithm> getDetectionStrategy() {
+ public EnvironmentChangeDetectionStrategy<E> getDetectionStrategy() {
return detectionStrategy;
}
@@ -125,7 +125,7 @@ public class DynamicIterationStrategy<E extends PopulationBasedAlgorithm> implem
* Set the {@linkplain EnvironmentChangeDetectionStrategy} to be used.
* @param detectionStrategy The {@linkplain EnvironmentChangeDetectionStrategy} to set.
*/
- public void setDetectionStrategy(EnvironmentChangeDetectionStrategy<PopulationBasedAlgorithm> detectionStrategy) {
+ public void setDetectionStrategy(EnvironmentChangeDetectionStrategy<E> detectionStrategy) {
this.detectionStrategy = detectionStrategy;
}
@@ -133,7 +133,7 @@ public class DynamicIterationStrategy<E extends PopulationBasedAlgorithm> implem
* Get the currently defined {@linkplain EnvironmentChangeResponseStrategy},
* @return The current {@linkplain EnvironmentChangeResponseStrategy}.
*/
- public EnvironmentChangeResponseStrategy<PopulationBasedAlgorithm> getResponseStrategy() {
+ public EnvironmentChangeResponseStrategy<E> getResponseStrategy() {
return responseStrategy;
}
@@ -141,7 +141,7 @@ public class DynamicIterationStrategy<E extends PopulationBasedAlgorithm> implem
* Set the current {@linkplain EnvironmentChangeResponseStrategy} to use.
* @param responseStrategy The {@linkplain EnvironmentChangeResponseStrategy} to set.
*/
- public void setResponseStrategy(EnvironmentChangeResponseStrategy<PopulationBasedAlgorithm> responseStrategy) {
+ public void setResponseStrategy(EnvironmentChangeResponseStrategy<E> responseStrategy) {
this.responseStrategy = responseStrategy;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryDetectionStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryDetectionStrategy.java
deleted file mode 100644
index 1800c7c..0000000
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryDetectionStrategy.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2003 - 2008
- * 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.detectionstrategies;
-
-import java.util.ArrayList;
-
-import net.sourceforge.cilib.algorithm.Algorithm;
-import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
-import net.sourceforge.cilib.entity.Entity;
-import net.sourceforge.cilib.entity.Topology;
-import net.sourceforge.cilib.math.random.generator.MersenneTwister;
-import net.sourceforge.cilib.math.random.generator.Random;
-
-/**
- * This class defines a detection strategy that uses a user-specified
- * {@link #numberOfSentries number of} sentry entities and an {@local #epsilon} value to
- * detect whether a change has occured in the environment.
- *
- * @TechReport{ title = "Tracking Changing Extrema with Particle Swarm Optimizer", author =
- * "Anthony Jack Carlisle and Gerry V. Dozier", institution = "Huntingdon
- * College", year = "2001", number = "CSSE01-08" }
- * @param <E> some {@link PopulationBasedAlgorithm population based algorithm}
- * @author Anna Rakitianskaia
- * @author Theuns Cloete
- */
-//TODO: Rename to RandomSentryEntitiesDetectionStrategy
-public class RandomSentryDetectionStrategy<E extends PopulationBasedAlgorithm> extends EnvironmentChangeDetectionStrategy<E> {
- private static final long serialVersionUID = -7299802900616282412L;
- protected int numberOfSentries = 0;
- protected Random randomGenerator = null;
-
- public RandomSentryDetectionStrategy() {
- numberOfSentries = 1;
- randomGenerator = new MersenneTwister();
- }
-
- public RandomSentryDetectionStrategy(RandomSentryDetectionStrategy<E> rhs) {
- super(rhs);
- numberOfSentries = rhs.numberOfSentries;
- randomGenerator = rhs.randomGenerator.getClone();
- }
-
- @Override
- public RandomSentryDetectionStrategy<E> getClone() {
- return new RandomSentryDetectionStrategy<E>(this);
- }
-
- /**
- * After every {@link #interval} iterations, pick
- * {@link #numberOfSentries a number of} random entities from the given
- * {@link Algorithm algorithm's} topology and compare their previous fitness values with
- * their current fitness values. An environment change is detected when the difference
- * between the previous and current fitness values are >= the specified
- * {@link #epsilon} value.
- *
- * @param algorithm used to get hold of topology of entities and number of iterations
- * @return true if a change has been detected, false otherwise
- */
- @Override
- public boolean detect(E algorithm) {
- if (algorithm.getIterations() % interval == 0) {
- ArrayList<Entity> sentries = new ArrayList<Entity>(numberOfSentries);
- Topology<? extends Entity> topology = algorithm.getTopology();
- ArrayList<Entity> all = new ArrayList<Entity>(topology.size());
-
- all.addAll(topology.asList());
-
- // Populate the sentries list with randomly chosen elements from the all list
- // AND remove the selected element from the all list so that it won't be selected again
- for (int i = 0; i < numberOfSentries; i++) {
- int random = randomGenerator.nextInt(all.size());
- sentries.add(all.get(random));
- all.remove(random);
- }
-
- // iterate through randomly selected entities and check for changes
- for (Entity sentry : sentries) {
- double previousFitness = sentry.getFitness().getValue();
- sentry.calculateFitness(false);
- double currentFitness = sentry.getFitness().getValue();
-
- if (Math.abs(previousFitness - currentFitness) >= epsilon) {
- return true;
- }
- }
- }
- return false;
- }
-
- public void setNumberOfSentries(int nos) {
- if (nos <= 0) {
- throw new IllegalArgumentException("It doesn't make sense to have <= 0 sentry points");
- }
-
- numberOfSentries = nos;
- }
-
- public int getNumberOfSentries() {
- return numberOfSentries;
- }
-
- public void setRandomNumberGenerator(Random rng) {
- randomGenerator = rng;
- }
-
- public Random getRandomNumberGenerator() {
- return randomGenerator;
- }
-}
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentriesDetectionStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryEntitiesDetectionStrategy.java
similarity index 91%
rename from src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentriesDetectionStrategy.java
rename to src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryEntitiesDetectionStrategy.java
index 8273841..0b3551f 100644
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentriesDetectionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryEntitiesDetectionStrategy.java
@@ -42,26 +42,26 @@ import net.sourceforge.cilib.math.random.generator.Random;
* @param <E> some {@link PopulationBasedAlgorithm population based algorithm}
* @author Theuns Cloete
*/
-public class RandomSentriesDetectionStrategy<E extends PopulationBasedAlgorithm> extends EnvironmentChangeDetectionStrategy<E> {
+public class RandomSentryEntitiesDetectionStrategy<E extends PopulationBasedAlgorithm> extends EnvironmentChangeDetectionStrategy<E> {
private static final long serialVersionUID = -7299802900616282412L;
protected ControlParameter numberOfSentries;
protected Random randomGenerator = null;
- public RandomSentriesDetectionStrategy() {
+ public RandomSentryEntitiesDetectionStrategy() {
// super() is automatically called
numberOfSentries = new ConstantControlParameter(1.0);
randomGenerator = new MersenneTwister();
}
- public RandomSentriesDetectionStrategy(RandomSentriesDetectionStrategy<E> rhs) {
+ public RandomSentryEntitiesDetectionStrategy(RandomSentryEntitiesDetectionStrategy<E> rhs) {
super(rhs);
numberOfSentries = rhs.numberOfSentries.getClone();
randomGenerator = rhs.randomGenerator.getClone();
}
- public RandomSentriesDetectionStrategy<E> getClone() {
- return new RandomSentriesDetectionStrategy<E>(this);
+ public RandomSentryEntitiesDetectionStrategy<E> getClone() {
+ return new RandomSentryEntitiesDetectionStrategy<E>(this);
}
/**
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryPointsDetectionStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryPointsDetectionStrategy.java
index 421a08c..92a1bb8 100644
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryPointsDetectionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/RandomSentryPointsDetectionStrategy.java
@@ -41,7 +41,7 @@ import net.sourceforge.cilib.entity.Topology;
* @param <E> some {@link PopulationBasedAlgorithm population based algorithm}
* @author Theuns Cloete
*/
-public class RandomSentryPointsDetectionStrategy<E extends PopulationBasedAlgorithm> extends RandomSentriesDetectionStrategy<E> {
+public class RandomSentryPointsDetectionStrategy<E extends PopulationBasedAlgorithm> extends RandomSentryEntitiesDetectionStrategy<E> {
private static final long serialVersionUID = -7908355064341601839L;
protected ArrayList<Entity> sentries = null;
diff --git a/xml/dynamic-vepso.xml b/xml/dynamic-vepso.xml
index 0fc7941..cc51060 100644
--- a/xml/dynamic-vepso.xml
+++ b/xml/dynamic-vepso.xml
@@ -32,7 +32,7 @@
<iterationStrategy class="pso.iterationstrategies.SynchronousIterationStrategy">
<boundaryConstraint class="problem.boundaryconstraint.ClampingBoundaryConstraint"/>
</iterationStrategy>
- <detectionStrategy class="pso.dynamic.detectionstrategies.RandomSentriesDetectionStrategy">
+ <detectionStrategy class="pso.dynamic.detectionstrategies.RandomSentryEntitiesDetectionStrategy">
<iterationsModulus value="1"/>
<numberOfSentries class="controlparameter.ConstantControlParameter" parameter="2"/>
</detectionStrategy>
--
1.6.0.6
|