|
From: Wiehann M. <wcm...@gm...> - 2009-05-23 00:54:27
|
Firstly, all of the SelectionStrategy classes as well as the various
interface definitions got removed. Also, related classes like the
WeighingStrategy classes with related interfaces got removed. ALL of
these classes got replaced with the new fluent selection classes. Some
of the implementations of these classes (like the
AntiClusteringWeighingStrategy class) got modified to comply to the new
fluent selection interface.
== Continued from previous patch ==
Implemented the concept of various syntax interfaces: SelectionSyntax,
OrderingSyntax as well as WeighingSyntax that defines the grammar of the
embedded domain-specific language (EDSL). Changed the Selection class
(that represents the builder in the builder-design pattern) to implement
these interfaces and also changed what the Selection class does during
the selection process: it changes state when one of the syntax-specific
methods gets called and returns either itself or another class to
specify state transitions in the language (a state machine that
specifies what methods can get called in sequence).
Forming part of the abovementioned changes is a new builder that gets
created when a selection gets weighed. This builder implements a
slightly different syntax: it can return a weighed selection when the
select() method gets called, or it can return the original (unpacked)
selection when the selectOriginal() method gets called.
In addition to the abovementioned changes is a collection of Weighing
classes that receives a collection of elements and weighs it in a
specific manner (for example: a collection of entities can get
normalised weights with respect to their fitness values).
Some additional Ordering classes were implemented like the Proportional
ordering class to select an element probabilistically from a list
depending on an element's weight. Also removed the reverse() method
from the Selection class and replaced it with a new ReverseOrdering
class to get the same effect.
To tie these classes together the concept of a SelectionRecipe is
introduced. These classes make use of the EDSL to select a single
element from a collection of elements. Eg. look at the
TournamentSelection class containing a one-liner selection statement.
They store state and can be used in XML - the EDSL is not XML-able.
Then, last but not least: a couple of small bugs were sorted out:
The ProportionalControlParameter class had a faulty getClone() method.
The Invididual and AbstractParticle classes now use the getComparator()
in the compareTo(...) methods to achieve the correct ordering. This was
an issue with the ElitistSelection class (used in the
ElitistSelectionStrategy class) as entities were sorted based on fitness
(from least fit to most fit) instead of using the
DescendingFitnessComparator logic to order them correctly.
---
.../KnowledgeTransferStrategy.java | 3 +-
.../SelectiveKnowledgeTransferStrategy.java | 44 ++--
.../ProportionalControlParameter.java | 11 +-
.../java/net/sourceforge/cilib/ec/Individual.java | 2 +-
.../selection/ElitistSelectionStrategy.java | 23 +-
.../selection/RandomSelectionStrategy.java | 13 +-
.../selection/RouletteWheelSelectionStrategy.java | 121 +---------
.../selection/TournamentSelectionStrategy.java | 39 +---
.../constrained/SetBasedConstrainedArchive.java | 27 +-
.../solutionweighing/AntiClusterWeighing.java | 115 +++++++++
.../archive/solutionweighing/SolutionWeighing.java | 46 ++++
.../AntiClusterWeighingStrategy.java | 119 ---------
.../SolutionWeighingStrategy.java | 48 ----
.../cilib/pso/particle/AbstractParticle.java | 2 +-
.../cilib/util/selection/OrderingSyntax.java | 33 +++
.../cilib/util/selection/Selection.java | 170 ++++++++++++
.../cilib/util/selection/SelectionSyntax.java | 41 +++
.../cilib/util/selection/WeighedSelection.java | 102 ++++++++
.../cilib/util/selection/WeighingSyntax.java | 34 +++
.../cilib/util/selection/ordering/Ordering.java | 40 +++
.../selection/ordering/ProportionalOrdering.java | 74 ++++++
.../util/selection/ordering/RandomOrdering.java | 57 ++++
.../util/selection/ordering/ReverseOrdering.java | 38 +++
.../util/selection/ordering/RingBasedOrdering.java | 55 ++++
.../util/selection/ordering/SortedOrdering.java | 64 +++++
.../util/selection/recipes/ElitistSelection.java | 52 ++++
.../util/selection/recipes/RandomSelection.java | 58 +++++
.../util/selection/recipes/RankBasedSelection.java | 59 +++++
.../recipes/RingBasedPopulationSelection.java | 52 ++++
.../selection/recipes/RouletteWheelSelection.java | 71 +++++
.../util/selection/recipes/SelectionRecipe.java | 37 +++
.../selection/recipes/TournamentSelection.java | 80 ++++++
.../IndexedSelectionStrategy.java | 79 ------
.../NormalisedProbabilisticSelectionStrategy.java | 72 -----
.../PopulationSelectionStrategy.java | 40 ---
.../ProbabilisticSelectionStrategy.java | 99 -------
.../RandomSelectionStrategy.java | 68 -----
.../RankBasedSelectionStrategy.java | 66 -----
.../RingBasedPopulationSelectionStrategy.java | 62 -----
.../selectionstrategies/SelectionStrategy.java | 44 ----
.../SimpleSelectionStrategy.java | 51 ----
.../TournamentSelectionStrategy.java | 87 -------
.../WeighedSelectionStrategy.java | 87 -------
.../selectionstrategies/generic/Ordering.java | 41 ---
.../generic/RandomOrdering.java | 46 ----
.../selectionstrategies/generic/Selection.java | 156 -----------
.../generic/SortedOrdering.java | 46 ----
.../util/selection/weighing/FixedWeighing.java | 70 +++++
.../util/selection/weighing/LinearWeighing.java | 83 ++++++
.../cilib/util/selection/weighing/Weighing.java | 38 +++
.../selection/weighing/entity/CurrentFitness.java | 37 +++
.../selection/weighing/entity/EntityFitness.java | 34 +++
.../selection/weighing/entity/EntityWeighing.java | 92 +++++++
.../weighing/entity/SocialBestFitness.java | 36 +++
.../weighingstrategies/EntityWeighingStrategy.java | 41 ---
.../FitnessBasedEntityWeighingStrategy.java | 96 -------
.../InverseWeighingStrategyDecorator.java | 68 -----
.../weighingstrategies/LinearWeighingStrategy.java | 86 ------
.../UniformWeighingStrategy.java | 70 -----
.../weighingstrategies/WeighingStrategy.java | 42 ---
.../cilib/moo/archive/constrained/ArchiveTest.java | 3 +
.../constrained/ConstrainedArchiveTest.java | 24 +-
.../solutionweighing/SolutionWeighingTest.java | 172 +++++++++++++
.../SolutionWeighingStrategyTest.java | 170 ------------
.../cilib/util/selection/SelectionTest.java | 65 +++++
.../util/selection/ordering/OrderingTest.java | 82 ++++++
.../selection/recipes/SelectionRecipeTest.java | 61 +++++
.../selectionstrategies/SelectionStrategyTest.java | 271 --------------------
.../selectionstrategies/generic/SelectionTest.java | 107 --------
.../util/selection/weighing/WeighingTest.java | 59 +++++
.../weighing/entity/EntityWeighingTest.java | 58 +++++
.../weighingstrategies/WeighingStrategyTest.java | 75 ------
xml/dynamic-vepso.xml | 8 +-
xml/vepso.xml | 104 ++++----
74 files changed, 2308 insertions(+), 2518 deletions(-)
create mode 100644 src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/AntiClusterWeighing.java
create mode 100644 src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighing.java
delete mode 100644 src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/AntiClusterWeighingStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/SolutionWeighingStrategy.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/Selection.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/WeighedSelection.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/WeighingSyntax.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/recipes/SelectionRecipe.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/IndexedSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/NormalisedProbabilisticSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/PopulationSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/ProbabilisticSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/RandomSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/RankBasedSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/RingBasedPopulationSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/SelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/SimpleSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/TournamentSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/WeighedSelectionStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/generic/Ordering.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/generic/RandomOrdering.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/generic/Selection.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/selectionstrategies/generic/SortedOrdering.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/CurrentFitness.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityFitness.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java
create mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/SocialBestFitness.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighingstrategies/EntityWeighingStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighingstrategies/FitnessBasedEntityWeighingStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighingstrategies/InverseWeighingStrategyDecorator.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighingstrategies/LinearWeighingStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighingstrategies/UniformWeighingStrategy.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/weighingstrategies/WeighingStrategy.java
create mode 100644 src/test/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighingTest.java
delete mode 100644 src/test/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/SolutionWeighingStrategyTest.java
create mode 100644 src/test/java/net/sourceforge/cilib/util/selection/SelectionTest.java
create mode 100644 src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java
create mode 100644 src/test/java/net/sourceforge/cilib/util/selection/recipes/SelectionRecipeTest.java
delete mode 100644 src/test/java/net/sourceforge/cilib/util/selection/selectionstrategies/SelectionStrategyTest.java
delete mode 100644 src/test/java/net/sourceforge/cilib/util/selection/selectionstrategies/generic/SelectionTest.java
create mode 100644 src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.java
create mode 100644 src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighingTest.java
delete mode 100644 src/test/java/net/sourceforge/cilib/util/selection/weighingstrategies/WeighingStrategyTest.java
diff --git a/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/KnowledgeTransferStrategy.java b/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/KnowledgeTransferStrategy.java
index 6626c16..6d6ba98 100644
--- a/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/KnowledgeTransferStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/KnowledgeTransferStrategy.java
@@ -23,6 +23,7 @@ package net.sourceforge.cilib.algorithm.population.knowledgetransferstrategies;
import java.util.List;
+import net.sourceforge.cilib.algorithm.population.MultiPopulationBasedAlgorithm;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.util.Cloneable;
@@ -44,7 +45,7 @@ public interface KnowledgeTransferStrategy extends Cloneable {
/**
* Returns knowledge that was gained from an entity within the list of populations.
* @param allPopulations The list of populations that will be used to select an
- * entity from who's knowledge will be used.
+ * entity who's knowledge will be used.
* @return The knowledge that was gained.
*/
public Type transferKnowledge(List<PopulationBasedAlgorithm> allPopulations);
diff --git a/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/SelectiveKnowledgeTransferStrategy.java b/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/SelectiveKnowledgeTransferStrategy.java
index 6111a8e..fd73ff9 100644
--- a/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/SelectiveKnowledgeTransferStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/algorithm/population/knowledgetransferstrategies/SelectiveKnowledgeTransferStrategy.java
@@ -27,16 +27,17 @@ import net.sourceforge.cilib.algorithm.population.MultiPopulationBasedAlgorithm;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.util.selection.selectionstrategies.RandomSelectionStrategy;
-import net.sourceforge.cilib.util.selection.selectionstrategies.RingBasedPopulationSelectionStrategy;
-import net.sourceforge.cilib.util.selection.selectionstrategies.SelectionStrategy;
+import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.recipes.RankBasedSelection;
+import net.sourceforge.cilib.util.selection.recipes.RingBasedPopulationSelection;
+import net.sourceforge.cilib.util.selection.recipes.SelectionRecipe;
/**
* <p>
- * An implementation of {@link KnowledgeTransferStrategy} where two {@link SelectionStrategy}
+ * An implementation of {@link KnowledgeTransferStrategy} where two {@link Selection}
* instances are used to first select a sub-population ({@link PopulationBasedAlgorithm}) from
* a collection of population-based algorithms (see {@link MultiPopulationBasedAlgorithm) and then
- * within this sub-population's {@link Topology} , which entity's knowledge is to be transfered
+ * within this sub-population's {@link Topology}, which entity's knowledge is to be transfered
* to the caller requesting it.
* </p>
*
@@ -45,17 +46,18 @@ import net.sourceforge.cilib.util.selection.selectionstrategies.SelectionStrateg
public class SelectiveKnowledgeTransferStrategy implements KnowledgeTransferStrategy {
private static final long serialVersionUID = 402688951924934682L;
- private SelectionStrategy<PopulationBasedAlgorithm> populationSelectionStrategy;
- private SelectionStrategy<Entity> entitySelectionStrategy;
+
+ private SelectionRecipe<PopulationBasedAlgorithm> populationSelection;
+ private SelectionRecipe<Entity> entitySelection;
public SelectiveKnowledgeTransferStrategy() {
- this.populationSelectionStrategy = new RingBasedPopulationSelectionStrategy();
- this.entitySelectionStrategy = new RandomSelectionStrategy<Entity>();
+ this.populationSelection = new RingBasedPopulationSelection();
+ this.entitySelection = new RankBasedSelection<Entity>();
}
public SelectiveKnowledgeTransferStrategy(SelectiveKnowledgeTransferStrategy copy) {
- this.populationSelectionStrategy = copy.populationSelectionStrategy.getClone();
- this.entitySelectionStrategy = copy.entitySelectionStrategy.getClone();
+ this.populationSelection = copy.populationSelection.getClone();
+ this.entitySelection = copy.entitySelection.getClone();
}
@Override
@@ -63,26 +65,26 @@ public class SelectiveKnowledgeTransferStrategy implements KnowledgeTransferStra
return new SelectiveKnowledgeTransferStrategy(this);
}
- public void setPopulationSelectionStrategy(SelectionStrategy<PopulationBasedAlgorithm> populationSelectionStrategy) {
- this.populationSelectionStrategy = populationSelectionStrategy;
+ public void setPopulationSelection(SelectionRecipe<PopulationBasedAlgorithm> populationSelection) {
+ this.populationSelection = populationSelection;
}
- public SelectionStrategy<PopulationBasedAlgorithm> getPopulationBasedAlgorithm() {
- return this.populationSelectionStrategy;
+ public SelectionRecipe<PopulationBasedAlgorithm> getPopulationSelection() {
+ return this.populationSelection;
}
- public void setEntitySelectionStrategy(SelectionStrategy<Entity> entitySelectionStrategy) {
- this.entitySelectionStrategy = entitySelectionStrategy;
+ public void setEntitySelection(SelectionRecipe<Entity> entitySelection) {
+ this.entitySelection = entitySelection;
}
- public SelectionStrategy<Entity> getEntitySelectionStrategy() {
- return this.entitySelectionStrategy;
+ public SelectionRecipe<Entity> getEntitySelection() {
+ return this.entitySelection;
}
@Override
public Type transferKnowledge(List<PopulationBasedAlgorithm> allPopulations) {
- PopulationBasedAlgorithm population = this.populationSelectionStrategy.select(allPopulations);
- Entity entity = this.entitySelectionStrategy.select(population.getTopology());
+ PopulationBasedAlgorithm population = this.populationSelection.select(allPopulations);
+ Entity entity = this.entitySelection.select(population.getTopology());
return entity.getProperties();
}
}
diff --git a/src/main/java/net/sourceforge/cilib/controlparameter/ProportionalControlParameter.java b/src/main/java/net/sourceforge/cilib/controlparameter/ProportionalControlParameter.java
index f00eba1..816c998 100644
--- a/src/main/java/net/sourceforge/cilib/controlparameter/ProportionalControlParameter.java
+++ b/src/main/java/net/sourceforge/cilib/controlparameter/ProportionalControlParameter.java
@@ -38,16 +38,22 @@ public class ProportionalControlParameter implements ControlParameter {
this.proportion = 0.1;
}
+ public ProportionalControlParameter(ProportionalControlParameter copy) {
+ this.proportion = copy.proportion;
+ }
+
/**
* {@inheritDoc}
*/
+ @Override
public ProportionalControlParameter getClone() {
- return null;
+ return new ProportionalControlParameter(this);
}
/**
* {@inheritDoc}
*/
+ @Override
public double getParameter() {
return this.proportion;
}
@@ -55,6 +61,7 @@ public class ProportionalControlParameter implements ControlParameter {
/**
* {@inheritDoc}
*/
+ @Override
public double getParameter(double min, double max) {
double diff = max - min;
return this.proportion * diff;
@@ -63,6 +70,7 @@ public class ProportionalControlParameter implements ControlParameter {
/**
* {@inheritDoc}
*/
+ @Override
public void setParameter(double value) {
if (value < 0)
throw new IllegalArgumentException("The proportion must be positive");
@@ -73,6 +81,7 @@ public class ProportionalControlParameter implements ControlParameter {
/**
* {@inheritDoc}
*/
+ @Override
public void updateParameter() {
}
}
diff --git a/src/main/java/net/sourceforge/cilib/ec/Individual.java b/src/main/java/net/sourceforge/cilib/ec/Individual.java
index 5557fbe..15dfd0a 100644
--- a/src/main/java/net/sourceforge/cilib/ec/Individual.java
+++ b/src/main/java/net/sourceforge/cilib/ec/Individual.java
@@ -126,7 +126,7 @@ public class Individual extends AbstractEntity {
*/
@Override
public int compareTo(Entity o) {
- return this.getFitness().compareTo(o.getFitness());
+ return getComparator().compare(this, o);
}
/**
diff --git a/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSelectionStrategy.java b/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSelectionStrategy.java
index f594e12..4936a9e 100644
--- a/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSelectionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSelectionStrategy.java
@@ -19,33 +19,34 @@
* 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.operators.selection;
-import java.util.Collections;
-
import net.sourceforge.cilib.controlparameter.ControlParameter;
import net.sourceforge.cilib.controlparameter.ProportionalControlParameter;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.entity.Topology;
-import net.sourceforge.cilib.entity.topologies.GBestTopology;
import net.sourceforge.cilib.entity.topologies.TopologyHolder;
+import net.sourceforge.cilib.util.selection.recipes.ElitistSelection;
public class ElitistSelectionStrategy extends SelectionStrategy {
private static final long serialVersionUID = -3055600262753819388L;
-
+
private ControlParameter selectionPercentage;
public ElitistSelectionStrategy() {
this.selectionPercentage = new ProportionalControlParameter();
}
+ public ElitistSelectionStrategy(ElitistSelectionStrategy copy) {
+ this.selectionPercentage = copy.selectionPercentage.getClone();
+ }
+
/**
* {@inheritDoc}
*/
@Override
- public SelectionStrategy getClone() {
- return this;
+ public ElitistSelectionStrategy getClone() {
+ return new ElitistSelectionStrategy(this);
}
/**
@@ -58,12 +59,7 @@ public class ElitistSelectionStrategy extends SelectionStrategy {
*/
@Override
public <T extends Entity> T select(Topology<T> population) {
- Topology<T> tmp = new GBestTopology<T>();
- tmp.addAll(population);
-
- Collections.sort(tmp, tmp.get(0).getComparator());
-
- return tmp.get(0);
+ return new ElitistSelection<T>().select(population);
}
/**
@@ -98,5 +94,4 @@ public class ElitistSelectionStrategy extends SelectionStrategy {
public void setSelectionPercentage(ControlParameter selectionPercentage) {
this.selectionPercentage = selectionPercentage;
}
-
}
diff --git a/src/main/java/net/sourceforge/cilib/entity/operators/selection/RandomSelectionStrategy.java b/src/main/java/net/sourceforge/cilib/entity/operators/selection/RandomSelectionStrategy.java
index 0b4728e..7b522bc 100644
--- a/src/main/java/net/sourceforge/cilib/entity/operators/selection/RandomSelectionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/entity/operators/selection/RandomSelectionStrategy.java
@@ -21,12 +21,10 @@
*/
package net.sourceforge.cilib.entity.operators.selection;
-import java.util.Random;
-
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.entity.Topology;
import net.sourceforge.cilib.entity.topologies.TopologyHolder;
-import net.sourceforge.cilib.math.random.generator.MersenneTwister;
+import net.sourceforge.cilib.util.selection.recipes.RandomSelection;
/**
*
@@ -36,21 +34,17 @@ import net.sourceforge.cilib.math.random.generator.MersenneTwister;
public class RandomSelectionStrategy extends SelectionStrategy {
private static final long serialVersionUID = -216894674927488180L;
- private Random random;
-
public RandomSelectionStrategy() {
- this.random = new MersenneTwister();
}
@Override
- public SelectionStrategy getClone() {
+ public RandomSelectionStrategy getClone() {
return new RandomSelectionStrategy();
}
@Override
public <T extends Entity> T select(Topology<T> population) {
- int randomNumber = random.nextInt(population.size());
- return population.get(randomNumber);
+ return new RandomSelection<T>().select(population);
}
@Override
@@ -62,5 +56,4 @@ public class RandomSelectionStrategy extends SelectionStrategy {
holder.add(select(topology));
// offspring.add(select(topology));
}
-
}
diff --git a/src/main/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategy.java b/src/main/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategy.java
index e44471b..08b8713 100644
--- a/src/main/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategy.java
@@ -24,10 +24,8 @@ package net.sourceforge.cilib.entity.operators.selection;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.entity.Topology;
import net.sourceforge.cilib.entity.topologies.TopologyHolder;
-import net.sourceforge.cilib.math.random.generator.MersenneTwister;
-import net.sourceforge.cilib.math.random.generator.Random;
-import net.sourceforge.cilib.problem.InferiorFitness;
-import net.sourceforge.cilib.problem.MinimisationFitness;
+import net.sourceforge.cilib.util.selection.recipes.RouletteWheelSelection;
+import net.sourceforge.cilib.util.selection.weighing.entity.EntityWeighing;
/**
* This class implements Roulette Wheel selection, also known as proportionate
@@ -44,13 +42,11 @@ import net.sourceforge.cilib.problem.MinimisationFitness;
*/
public class RouletteWheelSelectionStrategy extends SelectionStrategy {
private static final long serialVersionUID = 6827649649373047787L;
- private Random random;
/**
* Create an instance of the {@linkplain RouletteWheelSelectionStrategy}.
*/
public RouletteWheelSelectionStrategy() {
- this.random = new MersenneTwister();
}
/**
@@ -58,7 +54,6 @@ public class RouletteWheelSelectionStrategy extends SelectionStrategy {
* @param copy The instance to copy.
*/
public RouletteWheelSelectionStrategy(final RouletteWheelSelectionStrategy copy) {
- this.random = copy.random.getClone();
}
/**
@@ -74,32 +69,9 @@ public class RouletteWheelSelectionStrategy extends SelectionStrategy {
*/
@Override
public <T extends Entity> T select(final Topology<T> population) {
- double minimumFitness = getMinimumFitness(population);
- double maximumFitness = getMaximumFitness(population);
-
- double totalFitness = getTotalFitness(population, minimumFitness, maximumFitness);
- double cumulativeProb = 0.0;
- double valueToPick = random.nextDouble();
-
- // If the fitness' have not been calculated return a random entity. This should NEVER happen.
- if (Double.compare(totalFitness, InferiorFitness.instance().getValue()) == 0)
- throw new UnsupportedOperationException("Cannot perform selection operator on Topology of Entity. Each Entity is incorrectly defined to have an InferiorFitness. Initial Fitness' need to be determined before selection");
-
- // If the fitness of all the Entities is zero, we randomly select one. This prevents the case
- // where it is possible to divide by zero resulting in an ArithmeticException.
- if (Double.compare(totalFitness, 0.0) == 0)
- return population.get(random.nextInt(population.size()));
-
- for (T entity : population) {
- double probability = getScaledFitness(entity, minimumFitness, maximumFitness) / totalFitness;
- if (valueToPick < cumulativeProb + probability) {
- return entity;
- }
-
- cumulativeProb += probability;
- }
-
- return population.get(population.size() - 1);
+ RouletteWheelSelection<T> selection = new RouletteWheelSelection<T>();
+ selection.setWeighing(new EntityWeighing<T>());
+ return selection.select(population);
}
/**
@@ -113,87 +85,4 @@ public class RouletteWheelSelectionStrategy extends SelectionStrategy {
// offspring.add(select(topology));
holder.add(select(topology));
}
-
- /**
- * It calculates the sum total of the fitness of all the {@linkplain Entity}s
- * in the {@linkplain Topology}.
- *
- * @param topology The {@linkplain Topology} to use.
- * @return The sum total of the fitness values.
- */
- private double getTotalFitness(final Topology<? extends Entity> topology, double minimum, double maximum) {
- double totalFitness = 0;
- for (Entity entity : topology) {
- totalFitness += getScaledFitness(entity, minimum, maximum);
- }
-
- return totalFitness;
- }
-
- /**
- * Get the minimum fitness value of the entire population.
- * @param topology The topology to determine the fitness of.
- * @return The minimum fitness value of the entire topology / population.
- */
- private double getMinimumFitness(final Topology<? extends Entity> topology) {
- double minimum = Double.MAX_VALUE;
-
- for (Entity entity : topology)
- minimum = Math.min(minimum, entity.getFitness().getValue().doubleValue());
-
- return minimum;
- }
-
- /**
- * Get the maximum current fitness within the topology.
- * @param topology The topology to determine the maximum fitness of.
- * @return The maximum fitness within the entire topology / population.
- */
- private double getMaximumFitness(final Topology<? extends Entity> topology) {
- double maximum = -Double.MAX_VALUE;
-
- for (Entity entity : topology)
- maximum = Math.max(maximum, entity.getFitness().getValue().doubleValue());
-
- return maximum;
- }
-
- /**
- * Determine the scaled fitness of the provided entity. This fitness value is
- * a fitness value that is scaled to <code>(0, 1]</code>.
- * @param entity The entity for which the scaled fitness value is to be calculated.
- * @param minimum The minimum fitness value in the current topology.
- * @param maximum The maximum fitness value in the current topology.
- * @return The scaled fitness value of the entity.
- */
- private double getScaledFitness(Entity entity, double minimum, double maximum) {
- double result = 0.0;
- if (entity.getFitness() instanceof MinimisationFitness)
- result = 1.0 / (1.0 + entity.getFitness().getValue().doubleValue() - minimum);
- else
- result = 1.0 / (1.0 + maximum - entity.getFitness().getValue().doubleValue()); // Maximisation case
-
- if (Double.compare(result, Double.NaN) == 0) return result;
- if (result <= 0.0 & result > 1.0)
- throw new ArithmeticException("Scaling should prevent this. The value returned should be: 0.0 < x <= 1.0");
-
- return result;
- }
-
- /**
- * Get the current {@linkplain Random} number generator.
- * @return The current {@linkplain Random}.
- */
- public Random getRandom() {
- return random;
- }
-
- /**
- * Set the {@linkplain Random} number generator.
- * @param random the value to set.
- */
- public void setRandom(Random random) {
- this.random = random;
- }
-
}
diff --git a/src/main/java/net/sourceforge/cilib/entity/operators/selection/TournamentSelectionStrategy.java b/src/main/java/net/sourceforge/cilib/entity/operators/selection/TournamentSelectionStrategy.java
index 239f783..2c0129d 100644
--- a/src/main/java/net/sourceforge/cilib/entity/operators/selection/TournamentSelectionStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/entity/operators/selection/TournamentSelectionStrategy.java
@@ -21,17 +21,12 @@
*/
package net.sourceforge.cilib.entity.operators.selection;
-import java.util.List;
-
import net.sourceforge.cilib.controlparameter.ControlParameter;
import net.sourceforge.cilib.controlparameter.ProportionalControlParameter;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.entity.Topology;
import net.sourceforge.cilib.entity.topologies.TopologyHolder;
-import net.sourceforge.cilib.math.random.RandomNumber;
-import net.sourceforge.cilib.util.selection.selectionstrategies.generic.RandomOrdering;
-import net.sourceforge.cilib.util.selection.selectionstrategies.generic.Selection;
-import net.sourceforge.cilib.util.selection.selectionstrategies.generic.SortedOrdering;
+import net.sourceforge.cilib.util.selection.recipes.TournamentSelection;
/**
* Perform a tournament selection process on the provided {@linkplain Topology}
@@ -41,15 +36,14 @@ import net.sourceforge.cilib.util.selection.selectionstrategies.generic.SortedOr
*/
public class TournamentSelectionStrategy extends SelectionStrategy {
private static final long serialVersionUID = -7520711765609204590L;
+
private ControlParameter tournamentProportion;
- private RandomNumber randomNumber;
/**
* Create a new instance of {@linkplain TournamentSelectionStrategy}.
*/
public TournamentSelectionStrategy() {
this.tournamentProportion = new ProportionalControlParameter();
- this.randomNumber = new RandomNumber();
}
/**
@@ -58,12 +52,12 @@ public class TournamentSelectionStrategy extends SelectionStrategy {
*/
public TournamentSelectionStrategy(TournamentSelectionStrategy copy) {
this.tournamentProportion = copy.tournamentProportion.getClone();
- this.randomNumber = copy.randomNumber.getClone();
}
/**
* {@inheritDoc}
*/
+ @Override
public TournamentSelectionStrategy getClone() {
return new TournamentSelectionStrategy(this);
}
@@ -71,12 +65,11 @@ public class TournamentSelectionStrategy extends SelectionStrategy {
/**
* {@inheritDoc}
*/
+ @Override
public <T extends Entity> T select(Topology<T> population) {
- int tournamentSize = Double.valueOf(this.tournamentProportion.getParameter()*population.size()).intValue();
- List<T> selection = Selection.from(population.asList()).apply(new RandomOrdering<T>()).first(tournamentSize)
- .apply(new SortedOrdering<T>()).last().select();
-
- return selection.get(0);
+ TournamentSelection<T> selection = new TournamentSelection<T>();
+ selection.setTournamentSize(this.tournamentProportion);
+ return selection.select(population);
}
/**
@@ -96,25 +89,10 @@ public class TournamentSelectionStrategy extends SelectionStrategy {
}
/**
- * Get the {@linkplain RandomNumber} defined for this {@linkplain SelectionStrategy}.
- * @return The current {@linkplain RandomNumber}.
- */
- public RandomNumber getRandomNumber() {
- return randomNumber;
- }
-
- /**
- * Set the {@linkplain RandomNumber} for the {@linkplain TournamentSelectionStrategy}.
- * @param randomNumber The {@linkplain RandomNumber} to set.
- */
- public void setRandomNumber(RandomNumber randomNumber) {
- this.randomNumber = randomNumber;
- }
-
- /**
* {@inheritDoc}
*/
// public void performOperation(Topology<? extends Entity> topology, Topology<Entity> offspring) {
+ @Override
public void performOperation(TopologyHolder holder) {
// Topology<Entity> offspring = (Topology<Entity>) holder.getOffpsring();
Topology<? extends Entity> topology = holder.getTopology();
@@ -122,5 +100,4 @@ public class TournamentSelectionStrategy extends SelectionStrategy {
// offspring.add(this.select(topology));
holder.add(select(topology));
}
-
}
diff --git a/src/main/java/net/sourceforge/cilib/moo/archive/constrained/SetBasedConstrainedArchive.java b/src/main/java/net/sourceforge/cilib/moo/archive/constrained/SetBasedConstrainedArchive.java
index 1ef43a7..3ccf600 100644
--- a/src/main/java/net/sourceforge/cilib/moo/archive/constrained/SetBasedConstrainedArchive.java
+++ b/src/main/java/net/sourceforge/cilib/moo/archive/constrained/SetBasedConstrainedArchive.java
@@ -30,14 +30,15 @@ import java.util.Set;
import net.sourceforge.cilib.moo.archive.Archive;
import net.sourceforge.cilib.problem.OptimisationSolution;
-import net.sourceforge.cilib.util.selection.selectionstrategies.RandomSelectionStrategy;
-import net.sourceforge.cilib.util.selection.selectionstrategies.SelectionStrategy;
+import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.recipes.RandomSelection;
+import net.sourceforge.cilib.util.selection.recipes.SelectionRecipe;
/**
* <p>
* A constrained set-driven {@link Archive} implementation. It makes use of
- * a {@link SelectionStrategy} to determine which solution from the archive
- * will be selected next for removal.
+ * a {@link Selection} to determine which solution from the archive
+ * will be selected next for removal if the archive grows larger than the capacity.
* </p>
*
* @author Wiehann Matthysen
@@ -45,19 +46,19 @@ import net.sourceforge.cilib.util.selection.selectionstrategies.SelectionStrateg
public class SetBasedConstrainedArchive extends ConstrainedArchive {
private Set<OptimisationSolution> solutions;
- private SelectionStrategy<OptimisationSolution> deleteSelectionStrategy;
+ private SelectionRecipe<OptimisationSolution> pruningSelection;
public SetBasedConstrainedArchive() {
this.solutions = new LinkedHashSet<OptimisationSolution>();
- this.deleteSelectionStrategy = new RandomSelectionStrategy<OptimisationSolution>();
+ this.pruningSelection = new RandomSelection<OptimisationSolution>();
}
- public void setDeleteSelectionStrategy(SelectionStrategy<OptimisationSolution> deleteSelectionStrategy) {
- this.deleteSelectionStrategy = deleteSelectionStrategy;
+ public void setPruningSelection(SelectionRecipe<OptimisationSolution> pruningSelection) {
+ this.pruningSelection = pruningSelection;
}
- public SelectionStrategy<OptimisationSolution> getDeleteSelectionStrategy() {
- return this.deleteSelectionStrategy;
+ public SelectionRecipe<OptimisationSolution> getPruningSelection() {
+ return this.pruningSelection;
}
@Override
@@ -86,8 +87,10 @@ public class SetBasedConstrainedArchive extends ConstrainedArchive {
protected void prune() {
// If the archive size is greater than the capacity, select a group of solutions and remove them from the archive.
int numSolutionsToRemove = size() - getCapacity();
- Collection<OptimisationSolution> solutionsToRemove = this.deleteSelectionStrategy.select(this.solutions, numSolutionsToRemove);
- removeAll(solutionsToRemove);
+ for (int i = 0; i < numSolutionsToRemove; ++i) {
+ OptimisationSolution solutionToRemove = this.pruningSelection.select(this);
+ remove(solutionToRemove);
+ }
}
@Override
diff --git a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/AntiClusterWeighing.java b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/AntiClusterWeighing.java
new file mode 100644
index 0000000..184cf5a
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/AntiClusterWeighing.java
@@ -0,0 +1,115 @@
+/**
+ * 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.moo.archive.solutionweighing;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import net.sourceforge.cilib.container.Pair;
+import net.sourceforge.cilib.moo.archive.Archive;
+import net.sourceforge.cilib.problem.Fitness;
+import net.sourceforge.cilib.problem.MOFitness;
+import net.sourceforge.cilib.problem.OptimisationSolution;
+import net.sourceforge.cilib.pso.moo.guideselectionstrategies.GuideSelectionStrategy;
+
+/**
+ * <p>
+ * An implementation of {@link SolutionWeighing} that weighs a collection of
+ * {@link OptimisationSolution}s based on how closely clustered these solutions are to
+ * one another.
+ * </p>
+ *
+ * <p>
+ * This class can be used to select the most closely clustered optimisation
+ * solutions to be removed from the {@link Archive} if it reaches its maximum capacity.
+ * However, by selecting the least closely clustered solutions, you have a collection of
+ * solutions that are good candidates to be used as guides in a Multi-objective optimisation
+ * algorithm (see {@link GuideSelectionStrategy}).
+ * </p>
+ *
+ * @author Wiehann Matthysen
+ */
+public class AntiClusterWeighing implements SolutionWeighing {
+ private static final long serialVersionUID = -4395783169143386500L;
+
+ public AntiClusterWeighing() {
+ }
+
+ public AntiClusterWeighing(AntiClusterWeighing copy) {
+ }
+
+ @Override
+ public AntiClusterWeighing getClone() {
+ return new AntiClusterWeighing(this);
+ }
+
+ @Override
+ public List<Pair<Double, OptimisationSolution>> weigh(List<OptimisationSolution> solutions) {
+ // Get first fitness as dummy fitness to set size of initial min and max fitness
+ // arrays as well as populating these arrays.
+ Iterator<? extends OptimisationSolution> solutionIterator = solutions.iterator();
+ MOFitness tempFitness = (MOFitness) solutionIterator.next().getFitness();
+ Fitness[] minFitnesses = new Fitness[tempFitness.getDimension()];
+ Fitness[] maxFitnesses = new Fitness[tempFitness.getDimension()];
+ for (int i = 0; i < tempFitness.getDimension(); ++i) {
+ minFitnesses[i] = tempFitness.getFitness(i);
+ maxFitnesses[i] = tempFitness.getFitness(i);
+ }
+
+ // Iterate over all remaining optimisation solutions and find the min and max fitness values.
+ while (solutionIterator.hasNext()) {
+ OptimisationSolution optimisationSolution = solutionIterator.next();
+ MOFitness fitnesses = (MOFitness) optimisationSolution.getFitness();
+ for (int i = 0; i < fitnesses.getDimension(); ++i) {
+ Double fitnessValue = fitnesses.getFitness(i).getValue();
+ if (fitnessValue < minFitnesses[i].getValue()) {
+ minFitnesses[i] = fitnesses.getFitness(i);
+ } else if (fitnessValue > maxFitnesses[i].getValue()) {
+ maxFitnesses[i] = fitnesses.getFitness(i);
+ }
+ }
+ }
+
+ // Now, iterate over all solutions again, but calculate the distance from each solution to every other
+ // solution and store the results in a list. Each solution in the list contains the distance as weight value.
+ List<Pair<Double, OptimisationSolution>> weighedOptimisationSolutions = new ArrayList<Pair<Double, OptimisationSolution>>();
+ for (OptimisationSolution fromSolution : solutions) {
+ double totalDistance = 0.0;
+ MOFitness fromFitnesses = (MOFitness) fromSolution.getFitness();
+ for (OptimisationSolution toSolution : solutions) {
+ if (fromSolution != toSolution) {
+ double distance = 0.0;
+ MOFitness toFitnesses = (MOFitness) toSolution.getFitness();
+ for (int i = 0; i < fromFitnesses.getDimension(); ++i) {
+ distance += Math.pow((fromFitnesses.getFitness(i).getValue() - toFitnesses.getFitness(i).getValue()) /
+ (maxFitnesses[i].getValue() - minFitnesses[i].getValue()), 2.0);
+ }
+ totalDistance += Math.sqrt(distance);
+ }
+ }
+ weighedOptimisationSolutions.add(new Pair<Double, OptimisationSolution>((totalDistance != 0.0) ? 1.0 / totalDistance : Double.MAX_VALUE, fromSolution));
+ }
+
+ return weighedOptimisationSolutions;
+ }
+}
diff --git a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighing.java b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighing.java
new file mode 100644
index 0000000..39f509d
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighing.java
@@ -0,0 +1,46 @@
+/**
+ * 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.moo.archive.solutionweighing;
+
+
+import java.util.List;
+import net.sourceforge.cilib.container.Pair;
+import net.sourceforge.cilib.problem.OptimisationSolution;
+import net.sourceforge.cilib.util.selection.weighing.Weighing;
+import net.sourceforge.cilib.util.Cloneable;
+
+/**
+ * <p>
+ * Weighs an optimisation solution for selection to be either removed from the
+ * {@code Archive} or selected to be used as guide during the search process.
+ * </p>
+ *
+ * @author Wiehann Matthysen
+ */
+public interface SolutionWeighing extends Weighing<OptimisationSolution>, Cloneable {
+
+ @Override
+ public abstract SolutionWeighing getClone();
+
+ @Override
+ public List<Pair<Double, OptimisationSolution>> weigh(List<OptimisationSolution> elements);
+}
diff --git a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/AntiClusterWeighingStrategy.java b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/AntiClusterWeighingStrategy.java
deleted file mode 100644
index b0dcda0..0000000
--- a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/AntiClusterWeighingStrategy.java
+++ /dev/null
@@ -1,119 +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.moo.archive.solutionweighingstrategies;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import net.sourceforge.cilib.container.Pair;
-import net.sourceforge.cilib.entity.operators.selection.SelectionStrategy;
-import net.sourceforge.cilib.problem.Fitness;
-import net.sourceforge.cilib.problem.MOFitness;
-import net.sourceforge.cilib.problem.OptimisationSolution;
-
-/**
- * <p>
- * An implementation of {@link SolutionWeighingStrategy} that weighs a collection of
- * {@link OptimisationSolution}s based on how closely clustered these solutions are to
- * one another. Solutions that are clustered closely together will get a large weight
- * value associated with them meaning that these solutions will have a higher probability
- * of being selected by a {@link SelectionStrategy}.
- * </p>
- *
- * <p>
- * This class is usually used to select a collection of closely clustered optimisation
- * solutions to be removed from the {@link Archive} if it reaches its maximum capacity.
- * However, in combination with {@link InverseWeighingStrategyDecorator} the solutions
- * that are the least clustered will be selected with a higher probability. These solutions
- * are usually good guides for a Multi-objective optimisation algorithm (see
- * {@link GuideSelectionStrategy}).
- * </p>
- *
- * @author Wiehann Matthysen
- */
-public class AntiClusterWeighingStrategy implements SolutionWeighingStrategy {
-
- private static final long serialVersionUID = -4395783169143386500L;
-
- public AntiClusterWeighingStrategy() {
- }
-
- public AntiClusterWeighingStrategy(AntiClusterWeighingStrategy copy) {
- }
-
- @Override
- public AntiClusterWeighingStrategy getClone() {
- return new AntiClusterWeighingStrategy(this);
- }
-
- @Override
- public List<Pair<Double, OptimisationSolution>> weigh(Collection<? extends OptimisationSolution> solutions) {
- // Get first fitness as dummy fitness to set size of initial min and max fitness
- // arrays as well as populating these arrays.
- Iterator<? extends OptimisationSolution> solutionIterator = solutions.iterator();
- MOFitness tempFitness = (MOFitness) solutionIterator.next().getFitness();
- Fitness[] minFitnesses = new Fitness[tempFitness.getDimension()];
- Fitness[] maxFitnesses = new Fitness[tempFitness.getDimension()];
- for (int i = 0; i < tempFitness.getDimension(); ++i) {
- minFitnesses[i] = tempFitness.getFitness(i);
- maxFitnesses[i] = tempFitness.getFitness(i);
- }
-
- // Iterate over all remaining optimisation solutions and find the min and max fitness values.
- while (solutionIterator.hasNext()) {
- OptimisationSolution optimisationSolution = solutionIterator.next();
- MOFitness fitnesses = (MOFitness) optimisationSolution.getFitness();
- for (int i = 0; i < fitnesses.getDimension(); ++i) {
- Double fitnessValue = fitnesses.getFitness(i).getValue();
- if (fitnessValue < minFitnesses[i].getValue()) {
- minFitnesses[i] = fitnesses.getFitness(i);
- } else if (fitnessValue > maxFitnesses[i].getValue()) {
- maxFitnesses[i] = fitnesses.getFitness(i);
- }
- }
- }
-
- // Now, iterate over all solutions again, but calculate the distance from each solution to every other
- // solution and store the results in a list. Each solution in the list contains the distance as weight value.
- List<Pair<Double, OptimisationSolution>> weighedOptimisationSolutions = new ArrayList<Pair<Double, OptimisationSolution>>();
- for (OptimisationSolution fromSolution : solutions) {
- double totalDistance = 0.0;
- MOFitness fromFitnesses = (MOFitness) fromSolution.getFitness();
- for (OptimisationSolution toSolution : solutions) {
- if (fromSolution != toSolution) {
- double distance = 0.0;
- MOFitness toFitnesses = (MOFitness) toSolution.getFitness();
- for (int i = 0; i < fromFitnesses.getDimension(); ++i) {
- distance += Math.pow((fromFitnesses.getFitness(i).getValue() - toFitnesses.getFitness(i).getValue()) /
- (maxFitnesses[i].getValue() - minFitnesses[i].getValue()), 2.0);
- }
- totalDistance += Math.sqrt(distance);
- }
- }
- weighedOptimisationSolutions.add(new Pair<Double, OptimisationSolution>((totalDistance != 0.0) ? 1.0 / totalDistance : Double.MAX_VALUE, fromSolution));
- }
-
- return weighedOptimisationSolutions;
- }
-}
diff --git a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/SolutionWeighingStrategy.java b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/SolutionWeighingStrategy.java
deleted file mode 100644
index 0db7951..0000000
--- a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighingstrategies/SolutionWeighingStrategy.java
+++ /dev/null
@@ -1,48 +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.moo.archive.solutionweighingstrategies;
-
-import java.util.Collection;
-import java.util.List;
-
-import net.sourceforge.cilib.container.Pair;
-import net.sourceforge.cilib.problem.OptimisationSolution;
-import net.sourceforge.cilib.util.selection.weighingstrategies.WeighingStrategy;
-
-/**
- * <p>
- * A {@link WeighingStrategy} used in combination with any of the
- * {@link WeighedSelectionStrategy} classes to weigh an optimisation solution
- * for selection to be either removed from the {@code Archive} or selected to be
- * used as guide during the search process.
- * </p>
- *
- * @author Wiehann Matthysen
- */
-public interface SolutionWeighingStrategy extends WeighingStrategy<Double, OptimisationSolution> {
-
- @Override
- public abstract SolutionWeighingStrategy getClone();
-
- @Override
- public abstract List<Pair<Double, OptimisationSolution>> weigh(Collection<? extends OptimisationSolution> solutions);
-}
diff --git a/src/main/java/net/sourceforge/cilib/pso/particle/AbstractParticle.java b/src/main/java/net/sourceforge/cilib/pso/particle/AbstractParticle.java
index a20174f..0a2713c 100644
--- a/src/main/java/net/sourceforge/cilib/pso/particle/AbstractParticle.java
+++ b/src/main/java/net/sourceforge/cilib/pso/particle/AbstractParticle.java
@@ -307,7 +307,7 @@ public abstract class AbstractParticle extends AbstractEntity implements Particl
*/
@Override
public int compareTo(Entity o) {
- return getFitness().compareTo(o.getFitness());
+ return getComparator().compare(this, o);
}
/**
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java b/src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java
new file mode 100644
index 0000000..de29db5
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java
@@ -0,0 +1,33 @@
+/**
+ * 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.util.selection;
+
+import net.sourceforge.cilib.util.selection.ordering.Ordering;
+
+/**
+ * @author Wiehann Matthysen
+ * @param <E>
+ */
+public interface OrderingSyntax<E> {
+
+ public SelectionSyntax<E>...
[truncated message content] |