|
From: Gary P. <gpa...@gm...> - 2009-06-02 14:40:22
|
The Topology class is an abstract class, extending from
EntityCollection.
Changing the names of the classes will mean that any classes using a
Topology will be using an interface and not an abstract class as a
reference.
A utility class, Topologies, has been created to house some static
methods.
Signed-off-by: Gary Pampara <gpa...@gm...>
---
pom.xml | 10 +-
.../sourceforge/cilib/entity/AbstractTopology.java | 122 ++++++++++
.../sourceforge/cilib/entity/EntityCollection.java | 150 ------------
.../net/sourceforge/cilib/entity/Topologies.java | 76 ++++++
.../net/sourceforge/cilib/entity/Topology.java | 243 +++++++++++---------
.../cilib/entity/topologies/GBestTopology.java | 4 +-
.../entity/topologies/VonNeumannTopology.java | 4 +-
...NeighbourhoodBestSentriesDetectionStrategy.java | 3 +-
.../NeighbourhoodBestSentriesReactionStrategy.java | 3 +-
...ClonedPopulationInitialisationStrategyTest.java | 9 +-
10 files changed, 343 insertions(+), 281 deletions(-)
create mode 100644 src/main/java/net/sourceforge/cilib/entity/AbstractTopology.java
delete mode 100644 src/main/java/net/sourceforge/cilib/entity/EntityCollection.java
create mode 100644 src/main/java/net/sourceforge/cilib/entity/Topologies.java
diff --git a/pom.xml b/pom.xml
index 3be1913..eeb940b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -241,7 +241,7 @@
</configuration>
<executions>
<execution>
- <phase>test</phase>
+ <phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
@@ -306,10 +306,10 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <configuration>
- <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
- </configuration>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <configuration>
+ <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
+ </configuration>
</plugin>
</plugins>
</reporting>
diff --git a/src/main/java/net/sourceforge/cilib/entity/AbstractTopology.java b/src/main/java/net/sourceforge/cilib/entity/AbstractTopology.java
new file mode 100644
index 0000000..47e4e6b
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/entity/AbstractTopology.java
@@ -0,0 +1,122 @@
+/*
+ * 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.entity;
+
+import java.util.Comparator;
+import java.util.Iterator;
+
+import net.sourceforge.cilib.container.visitor.Visitor;
+import net.sourceforge.cilib.entity.comparator.AscendingFitnessComparator;
+import net.sourceforge.cilib.entity.comparator.DescendingFitnessComparator;
+import net.sourceforge.cilib.entity.visitor.TopologyVisitor;
+
+/**
+ * This an abstract class which extends from the abstract Topology class.
+ * All {@linkplain net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm}
+ * Topologies must inherit from this class.
+ *
+ * @author Gary Pampara
+ * @author otter
+ * @param <E> The {@code Entity} type.
+ */
+public abstract class AbstractTopology<E extends Entity> implements Topology<E> {
+ private static final long serialVersionUID = -9117512234439769226L;
+
+ private E bestEntity;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract Topology<E> getClone();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void accept(Visitor<E> visitor) {
+ for (E element : this) {
+ if (visitor.isDone())
+ return;
+
+ visitor.visit(element);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void accept(TopologyVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ /**
+ * Obtain the most fit {@link Entity} within the {@code Topology}. This is
+ * the same as {@code getBestEntity(Comparator)} with a {@link AscendingFitnessComparator}
+ * as the provided comparator.
+ * @see Topology#getBestEntity(java.util.Comparator)
+ * @return The current best {@linkplain Entity}.
+ */
+ @Override
+ public E getBestEntity() {
+ return getBestEntity(new DescendingFitnessComparator<E>());
+ }
+
+ /**
+ * Obtain the {@link Entity} within the current {@code Topology}, based
+ * on the provided {@link Comparator} instance.
+ * @param comparator The {@link Comparator} to base the selection on.
+ * @return The best entity within the current topology.
+ */
+ @Override
+ public E getBestEntity(Comparator<? super E> comparator) {
+ if (bestEntity == null) {
+ Iterator<E> i = this.iterator();
+ bestEntity = i.next();
+
+ while (i.hasNext()) {
+ E entity = i.next();
+ if (comparator.compare(bestEntity, entity) < 0) { // bestEntity is worse than entity
+ bestEntity = entity;
+ }
+ }
+ }
+
+ return bestEntity;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clearBestEntity() {
+ this.bestEntity = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void update() {
+ }
+}
diff --git a/src/main/java/net/sourceforge/cilib/entity/EntityCollection.java b/src/main/java/net/sourceforge/cilib/entity/EntityCollection.java
deleted file mode 100644
index 2ebc655..0000000
--- a/src/main/java/net/sourceforge/cilib/entity/EntityCollection.java
+++ /dev/null
@@ -1,150 +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.entity;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import net.sourceforge.cilib.util.Cloneable;
-
-/**
- * This is a generalization for all algorithms that maintain a collection of
- * {@linkplain Entity} objects. Examples of this would include PSO, EC and ACO.
- *
- * @author Gary Pampara
- * @author otter
- * @param <E> All types derived from {@linkplain Entity}.
- */
-public interface EntityCollection<E extends Entity>
- extends Iterable<E>, List<E>, Cloneable, Serializable {
-
- /**
- * {@inheritDoc}
- */
- public EntityCollection<E> getClone();
-
- /**
- * Adds an entity to the topology.
- * @param entity The entity to be added.
- * @return <code>true</code> if the addition is successful, <code>false</code> otherwise.
- */
- public boolean add(E entity);
-
-
- /**
- * Removes an entity from the topology.
- * @param entity The entity to be removed.
- * @return boolean, true if remove operation was successful.
- */
- public boolean remove(E entity);
-
- /**
- * {@inheritDoc}
- */
- public E get(int index);
-
- /**
- * {@inheritDoc}
- */
- public E set(int index, E entity);
-
- /**
- * {@inheritDoc}
- */
- public boolean isEmpty();
-
- /**
- * Remove all the entities from the topology.
- * {@inheritDoc}
- */
- public void clear();
-
- /**
- * {@inheritDoc}
- */
- public boolean contains(Object o);
-
- /**
- * {@inheritDoc}
- */
- public boolean containsAll(Collection<?> c);
-
- /**
- * {@inheritDoc}
- */
- public boolean equals(Object o);
-
- /**
- * {@inheritDoc}
- */
- public int hashCode();
-
- /**
- * {@inheritDoc}
- */
- public Iterator<E> iterator();
-
- /**
- * {@inheritDoc}
- */
- public boolean remove(Object o);
-
- /**
- * {@inheritDoc}
- */
- public boolean removeAll(Collection<?> c);
-
- /**
- * {@inheritDoc}
- */
- public boolean retainAll(Collection<?> c);
-
- /**
- * Returns the size of the {@linkplain EntityCollection}.
- * @return The size of {@linkplain EntityCollection}.
- */
- public int size();
-
- /**
- * {@inheritDoc}
- */
- public Object [] toArray();
-
- /**
- * {@inheritDoc}
- */
- public <T> T[] toArray(T[] a);
-
- /**
- * Get the <code>id</code> associated with this {@linkplain EntityCollection}.
- * @return The <code>id</code> for this {@linkplain EntityCollection}.
- */
- public String getId();
-
- /**
- * Set the <code>id</code> for this {@linkplain EntityCollection}.
- * @param id The value to set.
- */
- public void setId(String id);
-}
diff --git a/src/main/java/net/sourceforge/cilib/entity/Topologies.java b/src/main/java/net/sourceforge/cilib/entity/Topologies.java
new file mode 100644
index 0000000..d3dd9a3
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/entity/Topologies.java
@@ -0,0 +1,76 @@
+/**
+ * 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.entity;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Topology related utilities.
+ * @author gpampara
+ */
+public final class Topologies {
+
+ private Topologies() {
+ }
+
+ /**
+ * Gather the best entity of each neighbourhood (in this {@link Topology}) in a
+ * {@link Set} (duplicates are not allowed) and return them. A single {@link Entity} may
+ * dominate in more than one neighbourhood, but we just want unique entities.
+ *
+ * @param <E> The entity type.
+ * @param topology The topology to query.
+ * @return a {@link Set} cosisting of the best entity of each neighbourhood in the
+ * topology
+ * @author Theuns Cloete
+ */
+ public static <E extends Entity> Set<E> getNeighbourhoodBestEntities(Topology<E> topology) {
+ // a Set does not allow duplicates
+ Set<E> neighbourhoodBests = new HashSet<E>(topology.size());
+ Iterator<E> topologyIterator = topology.iterator();
+
+ // iterate over all entities in the topology
+ while (topologyIterator.hasNext()) {
+ topologyIterator.next();
+ Iterator<E> neighbourhoodIterator = topology.neighbourhood(topologyIterator);
+ E currentBestEntity = null;
+
+ // iterate over the neighbours of the current entity
+ while (neighbourhoodIterator.hasNext()) {
+ E anotherEntity = neighbourhoodIterator.next();
+ // keep track of the best entity
+ if (currentBestEntity == null || currentBestEntity.compareTo(anotherEntity) > 0) {
+ currentBestEntity = anotherEntity;
+ }
+ }
+ // only gather unique entities
+ if (currentBestEntity != null) {
+ neighbourhoodBests.add(currentBestEntity);
+ }
+ }
+
+ return neighbourhoodBests;
+ }
+}
diff --git a/src/main/java/net/sourceforge/cilib/entity/Topology.java b/src/main/java/net/sourceforge/cilib/entity/Topology.java
index 183c590..63eba26 100644
--- a/src/main/java/net/sourceforge/cilib/entity/Topology.java
+++ b/src/main/java/net/sourceforge/cilib/entity/Topology.java
@@ -21,175 +21,192 @@
*/
package net.sourceforge.cilib.entity;
+import java.io.Serializable;
+import java.util.Collection;
import java.util.Comparator;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import net.sourceforge.cilib.container.visitor.Visitor;
-import net.sourceforge.cilib.entity.comparator.AscendingFitnessComparator;
import net.sourceforge.cilib.entity.visitor.TopologyVisitor;
+import net.sourceforge.cilib.util.Cloneable;
/**
- * This an abstract class which extends from the abstract Topology class.
- * All {@linkplain net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm}
- * Topologies must inherit from this class.
+ * This is a generalization for all algorithms that maintain a collection of
+ * {@linkplain Entity} objects. Examples of this would include PSO, EC and ACO.
*
* @author Gary Pampara
- * @author otter
- * @param <E> The {@code Entity} type.
+ * @param <E> All types derived from {@linkplain Entity}.
*/
-public abstract class Topology<E extends Entity> implements EntityCollection<E> {
- private static final long serialVersionUID = -9117512234439769226L;
+public interface Topology<E extends Entity>
+ extends Iterable<E>, List<E>, Cloneable, Serializable {
- private E bestEntity;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Topology<E> getClone();
+
+ /**
+ * Adds an entity to the topology.
+ * @param entity The entity to be added.
+ * @return <code>true</code> if the addition is successful, <code>false</code> otherwise.
+ */
+ @Override
+ public boolean add(E entity);
+
+
+ /**
+ * Removes an entity from the topology.
+ * @param entity The entity to be removed.
+ * @return boolean, true if remove operation was successful.
+ */
+ public boolean remove(E entity);
/**
* {@inheritDoc}
*/
- public abstract Topology<E> getClone();
+ public E get(int index);
/**
- * Returns an <code>Iterator</code> over all particles in the neighbourhood of
- * the particle referred to by the given <code>Iterator</code>.
- *
- * @param An iterator that refers to a particle in this topology.
- * @return A particle iterator.
+ * {@inheritDoc}
*/
- public abstract Iterator<E> neighbourhood(Iterator<? extends Entity> iterator);
+ public E set(int index, E entity);
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEmpty();
/**
- * Accept a vistitor and perform the visitor actions on this
- * <tt>Topology</tt>.
- *
- * @param visitor The {@see net.sourceforge.cilib.container.visitor.Visitor} to accept
+ * Remove all the entities from the topology.
+ * {@inheritDoc}
*/
- public void accept(Visitor<E> visitor) {
- for (E element : this) {
- if (visitor.isDone())
- return;
+ public void clear();
- visitor.visit(element);
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean contains(Object o);
/**
- * Accept a {@code TopologyVisitor} into the {@code Topology} to perform the actions
- * defined within the {@code TopologyVisitor}.
- * @param visitor The instance to accept into the {@code Topology}.
+ * {@inheritDoc}
*/
- public void accept(TopologyVisitor visitor) {
- visitor.visit(this);
- }
+ public boolean containsAll(Collection<?> c);
/**
- * Get all the entities within the topology.
- * @return Collection. Data collection of all the entities
+ * {@inheritDoc}
*/
- public abstract List<E> asList();
+ public boolean equals(Object o);
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode();
/**
- * Mainly for use in Co-Evolution, CCGA, Island GA and so on... where there is multiple populations.
- * Returns the topology identifier.
- *
- * @return A <tt>String</tt> representing the identifier.
+ * {@inheritDoc}
*/
- public abstract String getId();
+ public Iterator<E> iterator();
+ /**
+ * {@inheritDoc}
+ */
+ public boolean remove(Object o);
/**
- * Set the identifier for this <tt>Topology</tt>.
- *
- * @param id The identifier to set
+ * {@inheritDoc}
+ */
+ public boolean removeAll(Collection<?> c);
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean retainAll(Collection<?> c);
+
+ /**
+ * Returns the size of the {@linkplain Topology}.
+ * @return The size of {@linkplain Topology}.
+ */
+ public int size();
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object [] toArray();
+
+ /**
+ * {@inheritDoc}
*/
- public abstract void setId(String id);
+ public <T> T[] toArray(T[] a);
/**
- * Obtain the most fit {@link Entity} within the {@code Topology}. This is
- * the same as {@code getBestEntity(Comparator)} with a {@link AscendingFitnessComparator}
- * as the provided comparator.
- * @see Topology#getBestEntity(java.util.Comparator)
- * @return The current best {@linkplain Entity}.
+ * Get the <code>id</code> associated with this {@linkplain Topology}, if
+ * an id is defined.
+ * @return The <code>id</code> for this {@linkplain Topology}.
*/
- public E getBestEntity() {
- return getBestEntity(new AscendingFitnessComparator());
- }
+ public String getId();
/**
- * Obtain the {@link Entity} within the current {@code Topology}, based
- * on the provided {@link Comparator} instance.
- * @param comparator The {@link Comparator} to base the selection on.
- * @return The best entity within the current topology.
+ * Set the <code>id</code> for this {@linkplain Topology}.
+ * @param id The value to set.
*/
- public E getBestEntity(Comparator<? super E> comparator) {
- if (bestEntity == null) {
- Iterator<E> i = this.iterator();
- bestEntity = i.next();
+ public void setId(String id);
- while (i.hasNext()) {
- E entity = i.next();
- if (comparator.compare(bestEntity, entity) < 0) { // bestEntity is worse than entity
- bestEntity = entity;
- }
- }
- }
+ /**
+ * Get all the entities within the topology.
+ * @return Collection. Data collection of all the entities
+ */
+ public List<E> asList();
- return bestEntity;
- }
+ /**
+ * Obtain the current best entity within the {@code Topology}.
+ * @return The best {@code Entity}.
+ */
+ public E getBestEntity();
+
+ /**
+ * Obtain the current best entity within the {@code Topology}, based
+ * on the provided {@code Comparator}.
+ * @param comparator The {@code Comparator} to use.
+ * @return The best {@code Entity} based on the defined comparison.
+ */
+ public E getBestEntity(Comparator<? super E> comparator);
/**
- * Gather the best entity of each neighbourhood (in this {@link Topology}) in a
- * {@link Set} (duplicates are not allowed) and return them. A single {@link Entity} may
- * dominate in more than one neighbourhood, but we just want unique entities.
+ * Accept a vistitor and perform the visitor actions on this
+ * <tt>Topology</tt>.
*
- * @return a {@link Set} cosisting of the best entity of each neighbourhood in the
- * topology
- * @author Theuns Cloete
- */
- public Set<E> getNeighbourhoodBestEntities() {
- // a Set does not allow duplicates
- Set<E> neighbourhoodBests = new HashSet<E>(this.size());
- Iterator<E> topologyIterator = this.iterator();
-
- // iterate over all entities in the topology
- while (topologyIterator.hasNext()) {
- topologyIterator.next();
- Iterator<E> neighbourhoodIterator = this.neighbourhood(topologyIterator);
- E bestEntity = null;
-
- // iterate over the neighbours of the current entity
- while (neighbourhoodIterator.hasNext()) {
- E anotherEntity = neighbourhoodIterator.next();
- // keep track of the best entity
- if (bestEntity == null || bestEntity.compareTo(anotherEntity) > 0) {
- bestEntity = anotherEntity;
- }
- }
- // only gather unique entities
- if (bestEntity != null) {
- neighbourhoodBests.add(bestEntity);
- }
- }
-
- return neighbourhoodBests;
- }
+ * @param visitor The {@see net.sourceforge.cilib.container.visitor.Visitor} to accept
+ */
+ public void accept(Visitor<E> visitor);
/**
- * Clear the current best entity from the topology, thereby forcing a
- * re-calculation of the best {@linkplain Entity} within the topology.
+ * Accept a {@code TopologyVisitor} into the {@code Topology} to perform the actions
+ * defined within the {@code TopologyVisitor}.
+ * @param visitor The instance to accept into the {@code Topology}.
*/
- public void clearBestEntity() {
- this.bestEntity = null;
- }
+ public void accept(TopologyVisitor visitor);
/**
* Perform any required updates to the {@linkplain Topology} instance.
* The method in has an empty implementation and needs to be overridden
* within the required subclass.
*/
- public void update() {
- }
+ public void update();
+
+ /**
+ * Returns an <code>Iterator</code> over all particles in the neighbourhood of
+ * the particle referred to by the given <code>Iterator</code>.
+ *
+ * @param iterator An iterator that refers to a particle in this topology.
+ * @return A particle iterator.
+ */
+ public Iterator<E> neighbourhood(Iterator<? extends Entity> iterator);
+
+ /**
+ * Clear the current best entity from the topology, thereby forcing a
+ * re-calculation of the best {@linkplain Entity} within the topology.
+ */
+ public void clearBestEntity();
}
diff --git a/src/main/java/net/sourceforge/cilib/entity/topologies/GBestTopology.java b/src/main/java/net/sourceforge/cilib/entity/topologies/GBestTopology.java
index c7a743a..3e81aae 100644
--- a/src/main/java/net/sourceforge/cilib/entity/topologies/GBestTopology.java
+++ b/src/main/java/net/sourceforge/cilib/entity/topologies/GBestTopology.java
@@ -29,8 +29,8 @@ import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
+import net.sourceforge.cilib.entity.AbstractTopology;
import net.sourceforge.cilib.entity.Entity;
-import net.sourceforge.cilib.entity.Topology;
/**
* <p>
@@ -45,7 +45,7 @@ import net.sourceforge.cilib.entity.Topology;
* @param <E> The {@linkplain Entity} type.
* @author Edwin Peer
*/
-public class GBestTopology<E extends Entity> extends Topology<E> {
+public class GBestTopology<E extends Entity> extends AbstractTopology<E> {
private static final long serialVersionUID = 3190027340582769112L;
protected LinkedList<E> entities;
diff --git a/src/main/java/net/sourceforge/cilib/entity/topologies/VonNeumannTopology.java b/src/main/java/net/sourceforge/cilib/entity/topologies/VonNeumannTopology.java
index 56b28c7..3d658a5 100644
--- a/src/main/java/net/sourceforge/cilib/entity/topologies/VonNeumannTopology.java
+++ b/src/main/java/net/sourceforge/cilib/entity/topologies/VonNeumannTopology.java
@@ -28,8 +28,8 @@ import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
+import net.sourceforge.cilib.entity.AbstractTopology;
import net.sourceforge.cilib.entity.Entity;
-import net.sourceforge.cilib.entity.Topology;
/**
* <p>
@@ -48,7 +48,7 @@ import net.sourceforge.cilib.entity.Topology;
*
* @param <E> A {@linkplain Entity} instance.
*/
-public class VonNeumannTopology<E extends Entity> extends Topology<E> {
+public class VonNeumannTopology<E extends Entity> extends AbstractTopology<E> {
private static final long serialVersionUID = -4795901403887110994L;
private enum Direction { CENTER, NORTH, EAST, SOUTH, WEST, DONE };
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/NeighbourhoodBestSentriesDetectionStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/NeighbourhoodBestSentriesDetectionStrategy.java
index fabbe7d..85241eb 100644
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/NeighbourhoodBestSentriesDetectionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/pso/dynamic/detectionstrategies/NeighbourhoodBestSentriesDetectionStrategy.java
@@ -27,6 +27,7 @@ import java.util.Set;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.entity.Entity;
+import net.sourceforge.cilib.entity.Topologies;
public class NeighbourhoodBestSentriesDetectionStrategy<E extends PopulationBasedAlgorithm> extends EnvironmentChangeDetectionStrategy<E> {
private static final long serialVersionUID = 3598067152913033487L;
@@ -47,7 +48,7 @@ public class NeighbourhoodBestSentriesDetectionStrategy<E extends PopulationBase
@Override
public boolean detect(PopulationBasedAlgorithm algorithm) {
if (algorithm.getIterations() % interval == 0) {
- Set<? extends Entity> sentries = algorithm.getTopology().getNeighbourhoodBestEntities();
+ Set<? extends Entity> sentries = Topologies.getNeighbourhoodBestEntities(algorithm.getTopology());
for (Entity sentry : sentries) {
double previousFitness = sentry.getFitness().getValue();
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/responsestrategies/NeighbourhoodBestSentriesReactionStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/responsestrategies/NeighbourhoodBestSentriesReactionStrategy.java
index f18afb5..2c7d2b0 100644
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/responsestrategies/NeighbourhoodBestSentriesReactionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/pso/dynamic/responsestrategies/NeighbourhoodBestSentriesReactionStrategy.java
@@ -24,6 +24,7 @@ package net.sourceforge.cilib.pso.dynamic.responsestrategies;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.entity.Entity;
+import net.sourceforge.cilib.entity.Topologies;
import net.sourceforge.cilib.type.types.TypeUtil;
public class NeighbourhoodBestSentriesReactionStrategy<E extends PopulationBasedAlgorithm> extends EnvironmentChangeResponseStrategy<E> {
@@ -44,7 +45,7 @@ public class NeighbourhoodBestSentriesReactionStrategy<E extends PopulationBased
@Override
public void performReaction(PopulationBasedAlgorithm algorithm) {
- for (Entity entity : algorithm.getTopology().getNeighbourhoodBestEntities())
+ for (Entity entity : Topologies.getNeighbourhoodBestEntities(algorithm.getTopology()))
TypeUtil.randomize(entity.getCandidateSolution());
// TODO: What is the influence of reevaluation?
// entity.calculateFitness(false);
diff --git a/src/test/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategyTest.java b/src/test/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategyTest.java
index f001a11..0a4dfad 100644
--- a/src/test/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategyTest.java
+++ b/src/test/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategyTest.java
@@ -24,14 +24,12 @@ package net.sourceforge.cilib.algorithm.initialisation;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.entity.Topology;
-import net.sourceforge.cilib.entity.topologies.GBestTopology;
import net.sourceforge.cilib.problem.OptimisationProblem;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,9 +41,7 @@ import org.junit.runner.RunWith;
*/
@RunWith(JMock.class)
public class ClonedPopulationInitialisationStrategyTest {
- private Mockery context = new JUnit4Mockery() {{
- setImposteriser(ClassImposteriser.INSTANCE);
- }};
+ private Mockery context = new JUnit4Mockery();
/**
* Test that the initialisation of the entity does indeed mean that the initialised
@@ -53,8 +49,7 @@ public class ClonedPopulationInitialisationStrategyTest {
*/
@Test
public void initialiseClonedTopology() {
- @SuppressWarnings("unchecked")
- final Topology<Entity> topology = context.mock(GBestTopology.class);
+ final Topology<Entity> topology = context.mock(Topology.class);
final Entity entity = context.mock(Entity.class);
final OptimisationProblem problem = context.mock(OptimisationProblem.class);
--
1.6.2.3
|