You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(7) |
Oct
(1) |
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(13) |
Feb
(17) |
Mar
(5) |
Apr
(10) |
May
(10) |
Jun
(42) |
Jul
(23) |
Aug
(38) |
Sep
(12) |
Oct
(9) |
Nov
(6) |
Dec
|
| 2005 |
Jan
(3) |
Feb
(17) |
Mar
(6) |
Apr
|
May
(1) |
Jun
(10) |
Jul
|
Aug
(10) |
Sep
|
Oct
(8) |
Nov
(2) |
Dec
(2) |
| 2006 |
Jan
(2) |
Feb
(11) |
Mar
(44) |
Apr
(84) |
May
(120) |
Jun
(18) |
Jul
|
Aug
(12) |
Sep
(19) |
Oct
(22) |
Nov
(7) |
Dec
(11) |
| 2007 |
Jan
(6) |
Feb
(10) |
Mar
(24) |
Apr
(13) |
May
(46) |
Jun
(25) |
Jul
(46) |
Aug
(47) |
Sep
(60) |
Oct
(61) |
Nov
(138) |
Dec
(47) |
| 2008 |
Jan
(6) |
Feb
(23) |
Mar
(58) |
Apr
(78) |
May
(82) |
Jun
(34) |
Jul
(56) |
Aug
(59) |
Sep
(54) |
Oct
(127) |
Nov
(47) |
Dec
(33) |
| 2009 |
Jan
(16) |
Feb
(18) |
Mar
(37) |
Apr
(162) |
May
(49) |
Jun
(58) |
Jul
(59) |
Aug
(17) |
Sep
(10) |
Oct
|
Nov
|
Dec
|
|
From: Andries E. <en...@cs...> - 2009-06-08 12:58:49
|
Thanks Gary, We'll, that is what I also figured. For what I want to do, the ProportinalControlParameter wil not work. Let me think of a new implementation that will do what I want and still keeps the current functionality. Regards Gary Pampara wrote: > Hi, > > Well, yes... I can't remember the orginal intent of the > ProportionalControlParameter, but it effectively maintains a proportion. > > For example. Within the TournamentSelection class, the proportion is set to > 0.1. The parameter is then used as follows: > > proportion.getParamter() * population.size() > > to obtain what 10% of the population would be. > > I think that this control parameter might be a little too stupid? We might > actually want to rethink the class's intent. > > Thoughts? > > On Monday 08 June 2009 10:03:23 Andries Engelbrecht wrote: > >> Hi, >> >> I want Vmax to be proportional to the domain of the >> problem. That is, Vmax = k*(Max - Min), where 0 <= k <= 1. >> I see there is a ProportionalControlParameter, but I can >> not figure out how to use it for my purpose. Before I >> write something to extend ProportionalControlParameter >> to base the value of a control parameter on the domain, >> can any of you tell me how I can use the existing code to >> reach my objective? >> >> Thanks >> > > ------------------------------------------------------------------------------ > OpenSolaris 2009.06 is a cutting edge operating system for enterprises > looking to deploy the next generation of Solaris that includes the latest > innovations from Sun and the OpenSource community. Download a copy and > enjoy capabilities such as Networking, Storage and Virtualization. > Go to: http://p.sf.net/sfu/opensolaris-get > _______________________________________________ > cilib-devel mailing list > cil...@li... > https://lists.sourceforge.net/lists/listinfo/cilib-devel > -- ========================================================== Prof Andries P Engelbrecht South African Research Chair in Artificial Intelligence Fundamentals of Computational Swarm Intelligence, John Wiley & Sons, December 2005. Computational Intelligence, An Introduction John Wiley & Sons, Second edition to be published soon Computational Intelligence Research Group: http://cirg.cs.up.ac.za Department of Computer Science School of Information Technology University of Pretoria Pretoria 0002, South Africa Tel: +27 12 420 3578 Fax: +27 12 362 5188 http://www.cs.up.ac.za/~engel ================================================ This message and attachments are subject to a disclaimer. Please refer to www.it.up.ac.za/documentation/governance/disclaimer/ for full details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule onderhewig. Volledige besonderhede is by www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar. |
|
From: Gary P. <gpa...@gm...> - 2009-06-08 12:00:18
|
Hi, Well, yes... I can't remember the orginal intent of the ProportionalControlParameter, but it effectively maintains a proportion. For example. Within the TournamentSelection class, the proportion is set to 0.1. The parameter is then used as follows: proportion.getParamter() * population.size() to obtain what 10% of the population would be. I think that this control parameter might be a little too stupid? We might actually want to rethink the class's intent. Thoughts? On Monday 08 June 2009 10:03:23 Andries Engelbrecht wrote: > Hi, > > I want Vmax to be proportional to the domain of the > problem. That is, Vmax = k*(Max - Min), where 0 <= k <= 1. > I see there is a ProportionalControlParameter, but I can > not figure out how to use it for my purpose. Before I > write something to extend ProportionalControlParameter > to base the value of a control parameter on the domain, > can any of you tell me how I can use the existing code to > reach my objective? > > Thanks |
|
From: Gary P. <gpa...@gm...> - 2009-06-08 11:52:49
|
The class is located at: net.sourceforge.cilib.pso.positionupdatestrategies.BoundedPersonalBestUpdateStrategy Regards, Gary On Monday 08 June 2009 09:55:36 Andries Engelbrecht wrote: > Hi, > > I remember at the previous CIlib workshop we have implemented > pbest update strategies. Specifically, we have implemented a > strategy that prevents a particle position to become a pbest if > the particle violates its boundary constraints. > > Can someone tell me where in the CIlib tree this was implemented? > > Thanks |
|
From: Andries E. <en...@cs...> - 2009-06-08 08:03:16
|
Hi,
I want Vmax to be proportional to the domain of the
problem. That is, Vmax = k*(Max - Min), where 0 <= k <= 1.
I see there is a ProportionalControlParameter, but I can
not figure out how to use it for my purpose. Before I
write something to extend ProportionalControlParameter
to base the value of a control parameter on the domain,
can any of you tell me how I can use the existing code to
reach my objective?
Thanks
--
==========================================================
Prof Andries P Engelbrecht
South African Research Chair in Artificial Intelligence
Fundamentals of Computational Swarm Intelligence,
John Wiley & Sons, December 2005.
Computational Intelligence, An Introduction
John Wiley & Sons, Second edition to be published soon
Computational Intelligence Research Group:
http://cirg.cs.up.ac.za
Department of Computer Science
School of Information Technology
University of Pretoria
Pretoria 0002, South Africa
Tel: +27 12 420 3578 Fax: +27 12 362 5188
http://www.cs.up.ac.za/~engel
================================================
This message and attachments are subject to a disclaimer. Please refer to www.it.up.ac.za/documentation/governance/disclaimer/ for full details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule onderhewig. Volledige besonderhede is by www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.
|
|
From: Andries E. <en...@cs...> - 2009-06-08 07:55:23
|
Hi,
I remember at the previous CIlib workshop we have implemented
pbest update strategies. Specifically, we have implemented a
strategy that prevents a particle position to become a pbest if
the particle violates its boundary constraints.
Can someone tell me where in the CIlib tree this was implemented?
Thanks
--
==========================================================
Prof Andries P Engelbrecht
South African Research Chair in Artificial Intelligence
Fundamentals of Computational Swarm Intelligence,
John Wiley & Sons, December 2005.
Computational Intelligence, An Introduction
John Wiley & Sons, Second edition to be published soon
Computational Intelligence Research Group:
http://cirg.cs.up.ac.za
Department of Computer Science
School of Information Technology
University of Pretoria
Pretoria 0002, South Africa
Tel: +27 12 420 3578 Fax: +27 12 362 5188
http://www.cs.up.ac.za/~engel
================================================
This message and attachments are subject to a disclaimer. Please refer to www.it.up.ac.za/documentation/governance/disclaimer/ for full details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule onderhewig. Volledige besonderhede is by www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.
|
|
From: Andries E. <en...@cs...> - 2009-06-05 11:40:38
|
--
==========================================================
Prof Andries P Engelbrecht
South African Research Chair in Artificial Intelligence
Fundamentals of Computational Swarm Intelligence,
John Wiley & Sons, December 2005.
Computational Intelligence, An Introduction
John Wiley & Sons, Second edition to be published soon
Computational Intelligence Research Group:
http://cirg.cs.up.ac.za
Department of Computer Science
School of Information Technology
University of Pretoria
Pretoria 0002, South Africa
Tel: +27 12 420 3578 Fax: +27 12 362 5188
http://www.cs.up.ac.za/~engel
================================================
This message and attachments are subject to a disclaimer. Please refer to www.it.up.ac.za/documentation/governance/disclaimer/ for full details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule onderhewig. Volledige besonderhede is by www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.
|
|
From: Gary P. <gpa...@gm...> - 2009-06-05 05:38:25
|
Hi all, There seems to have been a bug introduced with the latest chages with the GA. Minimisation seems to be failing. I'm not sure of the cause but will have a look at it. Regards, Gary |
|
From: Gary P. <gpa...@gm...> - 2009-06-04 11:44:38
|
As far as I know these patches are already applied. If we have missed them, please state which patches were missed. Regards. On Thursday 04 June 2009 15:42:24 Anna Rakitianskaia wrote: > Hi everyone, > > I remember we had a few patches related to dynamic environments > discussed on this mailing list. It appears that none of the patches were > eventually applied, since the version currently available in the git > repository is outdated. Could we maybe look into it sometime in the near > future? I am trying to run experiments for my M.Sc on the cloud, but I > really need that code to be committed before I can proceed. > > Kind regards, > Anna. > > --------------------------------------------------------------------------- >--- OpenSolaris 2009.06 is a cutting edge operating system for enterprises > looking to deploy the next generation of Solaris that includes the latest > innovations from Sun and the OpenSource community. Download a copy and > enjoy capabilities such as Networking, Storage and Virtualization. Go to: > http://p.sf.net/sfu/opensolaris-get > _______________________________________________ > cilib-devel mailing list > cil...@li... > https://lists.sourceforge.net/lists/listinfo/cilib-devel |
|
From: Anna R. <s23...@tu...> - 2009-06-04 09:52:50
|
Hi everyone, I remember we had a few patches related to dynamic environments discussed on this mailing list. It appears that none of the patches were eventually applied, since the version currently available in the git repository is outdated. Could we maybe look into it sometime in the near future? I am trying to run experiments for my M.Sc on the cloud, but I really need that code to be committed before I can proceed. Kind regards, Anna. |
|
From: Gary P. <gpa...@gm...> - 2009-06-03 05:25:45
|
I suppose one possible solution would be to have a reposnse strategy that informs a parent level algorithm that it should perform it's repsonse strategy. The others would create M-N relationships where you would end up not knowing what response strategy to invoke. Anyone have any other ideas? Regards, Gary On Wednesday 03 June 2009 07:14:40 Gary Pampara wrote: > Hi Marde, > > I was actually wondering when we would need functionality as you have > described here. The current detection / response implementation is a little > limited as you have discovered. > > I'll have a look at it. The potential solution I'm thinking of might > require a fair amount of work to get it going. > > Regards, > Gary > > On Tuesday 02 June 2009 23:14:17 Marde Greeff wrote: > > Hi everyone, > > > > I want to do the following: > > > > For the VEPSO algorithm that solves a dynamic MOO problem, the following > > must be possible: > > > > 1) All swarms detect for a change > > 2) If any swarm detects a change, all swarms respond to the change > > > > However, with the current implementation the detection and response > > occurs on the swarm level in the DynamicIterationStrategy class. > > > > What is the best way to do this? > > > > Marde > > --------------------------------------------------------------------------- >--- OpenSolaris 2009.06 is a cutting edge operating system for enterprises > looking to deploy the next generation of Solaris that includes the latest > innovations from Sun and the OpenSource community. Download a copy and > enjoy capabilities such as Networking, Storage and Virtualization. Go to: > http://p.sf.net/sfu/opensolaris-get > _______________________________________________ > cilib-devel mailing list > cil...@li... > https://lists.sourceforge.net/lists/listinfo/cilib-devel |
|
From: Gary P. <gpa...@gm...> - 2009-06-03 05:14:46
|
Hi Marde, I was actually wondering when we would need functionality as you have described here. The current detection / response implementation is a little limited as you have discovered. I'll have a look at it. The potential solution I'm thinking of might require a fair amount of work to get it going. Regards, Gary On Tuesday 02 June 2009 23:14:17 Marde Greeff wrote: > Hi everyone, > > I want to do the following: > > For the VEPSO algorithm that solves a dynamic MOO problem, the following > must be possible: > > 1) All swarms detect for a change > 2) If any swarm detects a change, all swarms respond to the change > > However, with the current implementation the detection and response occurs > on the swarm level in the DynamicIterationStrategy class. > > What is the best way to do this? > > Marde |
|
From: Marde G. <mg...@cs...> - 2009-06-02 21:15:27
|
Hi everyone, I want to do the following: For the VEPSO algorithm that solves a dynamic MOO problem, the following must be possible: 1) All swarms detect for a change 2) If any swarm detects a change, all swarms respond to the change However, with the current implementation the detection and response occurs on the swarm level in the DynamicIterationStrategy class. What is the best way to do this? Marde -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support. |
|
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
|
|
From: Gary P. <gpa...@gm...> - 2009-06-01 08:08:04
|
The Vector and TypeList classes had a bug where they interpreted a range
of values [fromIndex, toIndex) instead of [fromIndex, toIndex].
Signed-off-by: Gary Pampara <gpa...@gm...>
---
pom.xml | 2 +-
.../problem/dataset/StringDataSetBuilder.java | 3 -
.../net/sourceforge/cilib/type/types/Type.java | 29 ++++++-
.../cilib/type/types/container/AbstractList.java | 16 +++-
.../cilib/type/types/container/TypeList.java | 87 +++++++++++++++++---
src/site/site.xml | 22 ++++-
.../clustering/ClusteringFitnessFunctionTest.java | 1 -
.../sourceforge/cilib/type/DomainParserTest.java | 62 ++++++--------
.../cilib/type/types/container/TypeListTest.java | 48 +++++++++++
.../cilib/type/types/container/VectorTest.java | 10 ++
.../net/sourceforge/cilib/xml/XMLFileTest.java | 11 ++-
11 files changed, 223 insertions(+), 68 deletions(-)
create mode 100644 src/test/java/net/sourceforge/cilib/type/types/container/TypeListTest.java
diff --git a/pom.xml b/pom.xml
index ba9cb3d..3be1913 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,7 +54,7 @@
<distributionManagement>
<site>
<id>sourceforge</id>
- <url>sftp://web.sourceforge.net/home/groups/c/ci/cilib/htdocs</url>
+ <url>scp://shell.sourceforge.net/home/groups/c/ci/cilib/htdocs</url>
</site>
</distributionManagement>
<developers>
diff --git a/src/main/java/net/sourceforge/cilib/problem/dataset/StringDataSetBuilder.java b/src/main/java/net/sourceforge/cilib/problem/dataset/StringDataSetBuilder.java
index e1f9370..3e0e45d 100644
--- a/src/main/java/net/sourceforge/cilib/problem/dataset/StringDataSetBuilder.java
+++ b/src/main/java/net/sourceforge/cilib/problem/dataset/StringDataSetBuilder.java
@@ -39,7 +39,6 @@ public class StringDataSetBuilder extends TextDataSetBuilder {
public StringDataSetBuilder() {
this.strings = new ArrayList<String>();
- // System.out.println("Building...");
}
public StringDataSetBuilder(StringDataSetBuilder rhs) {
@@ -66,7 +65,6 @@ public class StringDataSetBuilder extends TextDataSetBuilder {
String result = in.readLine();
while (result != null) {
- // System.out.println(result);
strings.add(result);
result = in.readLine();
@@ -75,7 +73,6 @@ public class StringDataSetBuilder extends TextDataSetBuilder {
catch (IOException ioException) {
throw new RuntimeException(ioException);
}
- // System.out.println("Data set(s) initialised, proceeding...");
}
}
diff --git a/src/main/java/net/sourceforge/cilib/type/types/Type.java b/src/main/java/net/sourceforge/cilib/type/types/Type.java
index 4cb56f2..a33cca8 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/Type.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/Type.java
@@ -25,6 +25,7 @@ import net.sourceforge.cilib.util.Cloneable;
/**
* {@code Type} interface for all type-objects that are used within CIlib.
+ * The types are built on an extend the Java Collections Framework.
*/
public interface Type extends Cloneable {
@@ -35,15 +36,35 @@ public interface Type extends Cloneable {
public Type getClone();
/**
- * {@inheritDoc}
+ * Compare the specified object with this type for equality. Returns
+ * {@code true} if and only if the specified object is also an instance
+ * of the same type.
+ * @param o The object to compare.
+ * @return {@code true} if equality exists, {@code false} otherwise.
* @see Object#equals(Object)
*/
@Override
- public boolean equals(Object other);
+ public boolean equals(Object o);
/**
- * {@inheritDoc}
- * @see Object#hashCode()
+ * Returns the hash code value for this list. The hash code of a list
+ * is defined to be the result of the following calculation:
+ * <pre>
+ * int hashCode = 7;
+ * Iterator<E> i = list.iterator();
+ * while (i.hasNext()) {
+ * E obj = i.next();
+ * hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
+ * }
+ * </pre>
+ * This ensures that <tt>type1.equals(type2)</tt> implies that
+ * <tt>type1.hashCode()==type2.hashCode()</tt> for any two types,
+ * <tt>type1</tt> and <tt>type2</tt>, as required by the general
+ * contract of {@link Object#hashCode}.
+ *
+ * @return the hash code value for this list
+ * @see Object#equals(Object)
+ * @see #equals(Object)
*/
@Override
public int hashCode();
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java b/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java
index 50fc7b6..a3ff4b4 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java
@@ -27,6 +27,7 @@ import net.sourceforge.cilib.type.types.TypeUtil;
/**
* The basic definition for all {@linkplain Type} objects that are based on a list.
*
+ * @param <E> The type element.
* @author Gary Pampara
*/
public abstract class AbstractList<E extends Type> implements StructuredType<E> {
@@ -35,16 +36,19 @@ public abstract class AbstractList<E extends Type> implements StructuredType<E>
/**
* {@inheritDoc}
*/
+ @Override
public abstract AbstractList<E> getClone();
/**
* {@inheritDoc}
*/
- public abstract boolean equals(Object obj);
+ @Override
+ public abstract boolean equals(Object o);
/**
* {@inheritDoc}
*/
+ @Override
public abstract int hashCode();
/**
@@ -94,7 +98,7 @@ public abstract class AbstractList<E extends Type> implements StructuredType<E>
/**
* Add the provided {@linkplain AbstractList} to the start of the current list.
- * @param vector The object to add.
+ * @param list The object to add.
* @return <code>true</code> if the operation was successful, <code>false</code> otherwise.
*/
public abstract boolean prepend(AbstractList<E> list);
@@ -150,15 +154,16 @@ public abstract class AbstractList<E extends Type> implements StructuredType<E>
/**
* Create a sub vector from the current {@linkplain Vector}.
- * @param fromIndex The index to start the sub-vector from.
- * @param toIndex The last index to end the sub-vector at.
- * @return The created sub-vector instance.
+ * @param fromIndex The index to start the sub-list from.
+ * @param toIndex The last index to end the sub-list at.
+ * @return The created sub-list instance.
*/
public abstract AbstractList<E> subList(int fromIndex, int toIndex);
/**
* Create a new (cloned) <tt>Vector</tt> consisting of <tt>rhs</tt> that has been appended to
* <tt>lhs</tt>.
+ * @param <T> The type element.
* @param lhs The <tt>Vector</tt> that will form the front part of the new (cloned)
* <tt>Vector</tt>.
* @param rhs The <tt>Vector</tt> that will form the back part of the new (cloned)
@@ -228,6 +233,7 @@ public abstract class AbstractList<E extends Type> implements StructuredType<E>
/**
* {@inheritDoc}
*/
+ @Override
public String toString() {
return toString('[', ']', ',');
}
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
index bb907cd..a257e95 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
@@ -29,28 +29,32 @@ import net.sourceforge.cilib.container.visitor.Visitor;
import net.sourceforge.cilib.type.types.Type;
/**
- * Concrete implementation of the {@see net.sourceforge.cilib.type.types.Vector}
- * class. Any {@see net.sourceforge.cilib.type.types.Type} object may be contained
- * within this object.
+ * General list container for all {@code Type} instances.
*
- * @author Gary Pampara
- * @author Edwin Peer
+ * @author gpampara
*/
public class TypeList extends AbstractList<Type> {
private static final long serialVersionUID = 136711882764612609L;
private List<Type> components;
+ /**
+ * Create a new instance.
+ */
public TypeList() {
this.components = new ArrayList<Type>();
}
+ /**
+ * Create a new instance with the predefined size.
+ * @param size The predefined size.
+ */
public TypeList(int size) {
this.components = new ArrayList<Type>();
}
/**
- *
- * @param copy
+ * Create a copy of the provided instance.
+ * @param copy The instance to copy.
*/
public TypeList(TypeList copy) {
this.components = new ArrayList<Type>(copy.components.size());
@@ -59,6 +63,9 @@ public class TypeList extends AbstractList<Type> {
this.components.add(type.getClone());
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public TypeList getClone() {
return new TypeList(this);
@@ -68,14 +75,15 @@ public class TypeList extends AbstractList<Type> {
/**
* {@inheritDoc}
*/
- public boolean equals(Object other) {
- if (other == this)
+ @Override
+ public boolean equals(Object o) {
+ if (o == this)
return true;
- if ((other == null) || (this.getClass() != other.getClass()))
+ if ((o == null) || (this.getClass() != o.getClass()))
return false;
- TypeList otherList = (TypeList) other;
+ TypeList otherList = (TypeList) o;
return this.components.equals(otherList.components);
}
@@ -83,27 +91,40 @@ public class TypeList extends AbstractList<Type> {
/**
* {@inheritDoc}
*/
+ @Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + (this.components == null ? 0 : this.components.hashCode());
return hash;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Type get(int index) {
return this.components.get(index);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void set(int index, Type value) {
this.components.set(index, value);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void insert(int index, Type value) {
this.components.add(index, value);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean append(AbstractList<Type> list) {
for (Type type : list)
@@ -112,6 +133,9 @@ public class TypeList extends AbstractList<Type> {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean prepend(AbstractList<Type> list) {
for (int i = list.size()-1; i >= 0; i--)
@@ -120,11 +144,17 @@ public class TypeList extends AbstractList<Type> {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Object[] toArray() {
return this.components.toArray();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public TypeList subList(int fromIndex, int toIndex) {
// Need to bump up the toIndex because the List.subList() operation is upper bound exclusive.
@@ -137,11 +167,17 @@ public class TypeList extends AbstractList<Type> {
return sublist;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean add(Type element) {
return this.components.add(element);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean addAll(StructuredType<? extends Type> structure) {
for (Type type : structure)
@@ -150,36 +186,59 @@ public class TypeList extends AbstractList<Type> {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void clear() {
this.components.clear();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean contains(Type element) {
return this.components.contains(element);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean isEmpty() {
return this.components.isEmpty();
}
+ /**
+ * Returns an iterator over the elements in this list in proper sequence.
+ *
+ * @return an iterator over the elements in this list in proper sequence
+ */
@Override
public Iterator<Type> iterator() {
return this.components.iterator();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean remove(Type element) {
return this.components.remove(element);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public Type remove(int index) {
return this.components.remove(index);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean removeAll(StructuredType<Type> structure) {
for (Type type : structure)
@@ -188,11 +247,17 @@ public class TypeList extends AbstractList<Type> {
return true;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public int size() {
return this.components.size();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void accept(Visitor<Type> visitor) {
for (Type type : this.components)
diff --git a/src/site/site.xml b/src/site/site.xml
index a263ada..58beb77 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -6,17 +6,17 @@
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
@@ -36,7 +36,7 @@
</bannerRight>
<poweredBy>
- <logo
+ <logo
href="http://sourceforge.net/projects/cilib"
img="http://sflogo.sourceforge.net/sflogo.php?group_id=72233&type=11"
name="Get Computational Intelligence Library at SourceForge.net. Fast, secure and Free Open Source software downloads"
@@ -50,6 +50,20 @@
</poweredBy>
<body>
+ <head>
+ <meta content="Computational Intelligence, CI, Artificial Intelligence, AI, PSO, Particle swarm optimization, Evolutionary computation, GA, Genetic Algorithm, DE, Differential evolution, ABC, Artificial Bee Colony" name="KEYWORDS"/>
+ <script type="text/javascript">
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+ </script>
+ <script type="text/javascript">
+ try {
+ var pageTracker = _gat._getTracker("UA-4962709-1");
+ pageTracker._trackPageview();
+ } catch(err) {}
+ </script>
+ </head>
+
<links>
<item name="SoureForge.net project page"
href="http://www.sourceforge.net/projects/cilib" />
diff --git a/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java b/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
index e3f7964..c1de919 100644
--- a/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
+++ b/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
@@ -84,7 +84,6 @@ public class ClusteringFitnessFunctionTest {
@Test
public void testEvaluate() {
// the evaluate method arranges the clusters and centroids
- System.out.println(function.evaluate(centroids));
assertEquals(4.27188655918496, function.evaluate(centroids), DELTA);
}
diff --git a/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java b/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
index ca30397..a6e1872 100644
--- a/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
@@ -4,17 +4,17 @@
* 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
@@ -32,11 +32,11 @@ import net.sourceforge.cilib.type.types.container.Vector;
import org.junit.Test;
/**
- *
+ *
* @author Gary Pampara
*/
public class DomainParserTest {
-
+
@Test
public void testParseReal() {
DomainParser parser = new DomainParser();
@@ -55,8 +55,8 @@ public class DomainParserTest {
fail("Parser cannot handle parsing of R! " + e.getMessage());
}
}
-
-
+
+
@Test
public void testParseBit() {
DomainParser parser = new DomainParser();
@@ -70,7 +70,7 @@ public class DomainParserTest {
fail("Parser cannot handle parsing of B! " + e.getMessage());
}
}
-
+
@Test
public void testParseInteger() {
@@ -90,11 +90,11 @@ public class DomainParserTest {
assertEquals("Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0),Z(0.0,1.0)", parser.expandDomainString("Z(0,1)^10"));
}
catch (Exception e) {
- fail("Parser cannot handle parsing of Z! " + e.getMessage());
+ fail("Parser cannot handle parsing of Z! " + e.getMessage());
}
}
-
-
+
+
@Test
public void testParseString() {
DomainParser parser = new DomainParser();
@@ -106,8 +106,8 @@ public class DomainParserTest {
fail("Parser cannot handle parsing of T! " + e.getMessage());
}
}
-
-
+
+
@Test
public void testParseComplexDomain() {
DomainParser parser = new DomainParser();
@@ -121,7 +121,7 @@ public class DomainParserTest {
}
}
-
+
/**
* This test determines if the parser can successfully parse and build
* domains that can be represented as a matrix (also regarded as second order
@@ -139,30 +139,30 @@ public class DomainParserTest {
fail("Parser cannot handle martix representation domains! " + e.getMessage());
}
}
-
-
+
+
@Test
public void testBuildMatrixDomain() {
DomainParser parser = new DomainParser();
try {
parser.parse("[R(-30.0,30.0)^4]^5");
-
+
TypeList matrix = (TypeList) parser.getBuiltRepresentation();
-
+
// Test the dimensionality
assertEquals(5, matrix.size());
-
+
for (int i = 0; i < matrix.size(); i++) {
assertEquals(4, ((TypeList)matrix.get(i)).size());
}
-
+
// Test object equality
Vector v1 = (Vector) matrix.get(0);
Vector v2 = (Vector) matrix.get(1);
Vector v3 = (Vector) matrix.get(2);
Vector v4 = (Vector) matrix.get(3);
Vector v5 = (Vector) matrix.get(4);
-
+
assertTrue(assertObjectNotSame(v1, v2));
assertTrue(assertObjectNotSame(v1, v3));
assertTrue(assertObjectNotSame(v1, v4));
@@ -173,32 +173,24 @@ public class DomainParserTest {
assertTrue(assertObjectNotSame(v3, v4));
assertTrue(assertObjectNotSame(v3, v4));
assertTrue(assertObjectNotSame(v4, v5));
- }
-
- catch (Exception e) {
-
+ } catch (Exception e) {
+
}
}
-
-// @Test
-// public void expansionOfPredefinedDomain() {
-// parser.parse("[R(4.3, 7.9), R(2.0, 4.4), R(1.0, 6.9), R(0.1, 2.5)]^3");
-// System.out.println(parser.getBuiltRepresentation());
-// }
-
+
/**
- *
+ *
* @param v1
* @param v2
* @return
*/
private boolean assertObjectNotSame(Vector v1, Vector v2) {
-
+
for (int i = 0; i < v1.getDimension(); i++) {
if (v1.get(i).equals(v2.get(i)))
return false;
}
-
+
return true;
}
diff --git a/src/test/java/net/sourceforge/cilib/type/types/container/TypeListTest.java b/src/test/java/net/sourceforge/cilib/type/types/container/TypeListTest.java
new file mode 100644
index 0000000..273f93e
--- /dev/null
+++ b/src/test/java/net/sourceforge/cilib/type/types/container/TypeListTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.type.types.container;
+
+import net.sourceforge.cilib.type.types.Int;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author gpampara
+ */
+public class TypeListTest {
+
+ @Test
+ public void subList() {
+ TypeList list = new TypeList();
+ list.add(new Vector());
+ list.add(new BinaryTree());
+ list.add(new Int());
+ list.add(new Set());
+ list.add(new NaryTree());
+
+ TypeList subList = list.subList(0, 3);
+
+ Assert.assertEquals(4, subList.size());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
index 1b03f92..86ef5d9 100644
--- a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
@@ -34,7 +34,9 @@ import net.sourceforge.cilib.type.types.Int;
import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Real;
+import net.sourceforge.cilib.util.VectorUtils;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -511,4 +513,12 @@ public class VectorTest {
assertTrue(a.equals(a));
assertTrue(a.equals(b));
}
+
+ @Test
+ public void subList() {
+ Vector original = VectorUtils.create(1, 2, 3, 4, 5, 6, 7, 8, 9);
+ Vector subVector = original.subList(0, 3);
+
+ Assert.assertEquals(4, subVector.size());
+ }
}
diff --git a/src/test/java/net/sourceforge/cilib/xml/XMLFileTest.java b/src/test/java/net/sourceforge/cilib/xml/XMLFileTest.java
index f56e89b..772bd93 100644
--- a/src/test/java/net/sourceforge/cilib/xml/XMLFileTest.java
+++ b/src/test/java/net/sourceforge/cilib/xml/XMLFileTest.java
@@ -4,17 +4,17 @@
* 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
@@ -53,6 +53,9 @@ public class XMLFileTest {
* <p>
* Tests will pass if all the instance creation succeeds.
* </p>
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
*/
@Test
public void simulationConstruction() throws ParserConfigurationException, SAXException, IOException {
@@ -67,7 +70,7 @@ public class XMLFileTest {
NodeList simulations = doc.getElementsByTagName("simulation");
ProgressListener progress = new ProgressText(simulations.getLength());
-
+
for (int i = 0; i < simulations.getLength(); ++i) {
if(progress != null)
progress.setSimulation(i);
--
1.6.2.3
|
|
From: Gary P. <gpa...@gm...> - 2009-06-01 08:08:02
|
Fixed the out by one error with the Vector and TypeList classes.
java.util.List defines a subList() method that is used internally. It,
unfortunately, results in a selection from the range: [from, to).
The last element was being forgotten.
Signed-off-by: Gary Pampara <gpa...@gm...>
---
.../cilib/cooperative/CooperativeEntity.java | 4 +-
.../problem/changestrategy/ChangeStrategy.java | 6 +-
.../pso/dynamic/ChargedVelocityUpdateStrategy.java | 3 +-
.../net/sourceforge/cilib/type/DomainBuilder.java | 38 ++++++--
.../cilib/type/types/container/TypeList.java | 3 +-
.../cilib/type/types/container/Vector.java | 3 +-
.../sourceforge/cilib/util/ClusteringUtils.java | 3 +-
.../sourceforge/cilib/entity/IndividualTest.java | 2 -
.../clustering/ClusteringFitnessFunctionTest.java | 1 +
.../measurement/multiple/MultipleFitnessTest.java | 22 ++--
.../multiple/MultipleSolutionsTest.java | 6 +-
.../single/BestParticlePositionTest.java | 8 +-
.../cilib/measurement/single/DiameterTest.java | 16 ++--
.../measurement/single/ParticlePositionsTest.java | 6 +-
.../cilib/measurement/single/SolutionTest.java | 6 +-
.../sourceforge/cilib/type/DomainParserTest.java | 9 +-
.../cilib/type/StringBasedDomainRegistryTest.java | 8 +-
.../cilib/type/types/container/VectorTest.java | 111 --------------------
.../cilib/util/ClusteringUtilsTest.java | 12 +-
.../sourceforge/cilib/util/VectorUtilsTest.java | 13 ---
20 files changed, 91 insertions(+), 189 deletions(-)
diff --git a/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java b/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java
index b44c8d7..38723b4 100644
--- a/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java
+++ b/src/main/java/net/sourceforge/cilib/cooperative/CooperativeEntity.java
@@ -26,8 +26,10 @@ import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.problem.InferiorFitness;
import net.sourceforge.cilib.problem.OptimisationProblem;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.container.StructuredType;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -89,7 +91,7 @@ public class CooperativeEntity extends AbstractEntity {
if(value instanceof Vector)
context.append((Vector) value);
else
- context.append(value);
+ context.append((Numeric) value);
}
public void append(Entity entity) {
diff --git a/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java b/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java
index 8f29a17..35b3611 100644
--- a/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/problem/changestrategy/ChangeStrategy.java
@@ -39,9 +39,9 @@ import net.sourceforge.cilib.problem.Problem;
public interface ChangeStrategy {
/**
- * Test if a change should be applied on the provided {@code problem} instance.
- * @param problem The problem on which a change test is to be applied.
- * @return {@code true} if a change should be applied, {@code false} otherwise.
+ * Determine whether a change should be applied to the provided {@code problem} instance.
+ * @param problem The problem on which a change is to be applied.
+ * @return {@code true} if a change occoured, {@code false} otherwise.
*/
public boolean shouldApply(Problem problem);
diff --git a/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java b/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java
index f8f65a7..1600157 100644
--- a/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/pso/dynamic/ChargedVelocityUpdateStrategy.java
@@ -72,8 +72,7 @@ public class ChargedVelocityUpdateStrategy extends StandardVelocityUpdate {
Vector bestPosition = (Vector) particle.getBestPosition();
Vector nBestPosition = (Vector) particle.getNeighbourhoodBest().getBestPosition();
- Vector acceleration = new Vector(velocity.getDimension());
- acceleration.initialise(velocity.getDimension(), new Real(0));
+ Vector acceleration = new Vector(velocity.getDimension(), new Real(0.0));
PSO pso = (PSO) Algorithm.get();
Iterator<Particle> iter = null;
// make iter point to the current particle
diff --git a/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java b/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java
index 1640208..f6a4637 100644
--- a/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java
+++ b/src/main/java/net/sourceforge/cilib/type/DomainBuilder.java
@@ -26,8 +26,11 @@ import java.io.IOException;
import java.io.StreamTokenizer;
import net.sourceforge.cilib.type.creator.TypeCreator;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.AbstractList;
import net.sourceforge.cilib.type.types.container.StructuredType;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -52,7 +55,7 @@ import net.sourceforge.cilib.type.types.container.Vector;
*/
public class DomainBuilder {
- private Vector representation;
+ private TypeList representation;
private StreamTokenizer parser;
private double lower;
private double upper;
@@ -74,9 +77,8 @@ public class DomainBuilder {
* @param expandedDomain The expanded domain string
* @return A container containing the built represenation
*/
- public Vector build(String expandedDomain) {
-
- representation = new Vector();
+ public StructuredType build(String expandedDomain) {
+ representation = new TypeList();
parser = new StreamTokenizer(new CharArrayReader(expandedDomain.toCharArray()));
try {
@@ -87,7 +89,7 @@ public class DomainBuilder {
throw new RuntimeException("IOException occoured during building of the domain\n" + e);
}
- return representation;
+ return getBuiltRepresenation();
}
@@ -97,7 +99,10 @@ public class DomainBuilder {
* @return The constructed <tt>Type</tt> object representing the domain string.
*/
public StructuredType getBuiltRepresenation() {
- return this.representation;
+ if (isVector(representation))
+ return toVector(representation);
+
+ return representation;
}
@@ -109,8 +114,8 @@ public class DomainBuilder {
parser.nextToken();
if ((char) parser.ttype == '[') {
- final Vector tmp = this.representation;
- this.representation = new Vector();
+ final TypeList tmp = this.representation;
+ this.representation = new TypeList();
buildDomain();
parser.nextToken();
@@ -292,4 +297,21 @@ public class DomainBuilder {
throw new RuntimeException("Parser error: " + c + " was expected but received: " + (char) parser.ttype);
}
+ private boolean isVector(TypeList representation) {
+ for (Type type : representation)
+ if (!(type instanceof Numeric))
+ return false;
+
+ return true;
+ }
+
+ private AbstractList toVector(TypeList representation) {
+ Vector vector = new Vector(representation.size());
+
+ for (Type type : representation)
+ vector.add((Numeric) type);
+
+ return vector;
+ }
+
}
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
index 345ce84..bb907cd 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
@@ -127,7 +127,8 @@ public class TypeList extends AbstractList<Type> {
@Override
public TypeList subList(int fromIndex, int toIndex) {
- List<Type> result = this.components.subList(fromIndex, toIndex);
+ // Need to bump up the toIndex because the List.subList() operation is upper bound exclusive.
+ List<Type> result = this.components.subList(fromIndex, toIndex+1);
TypeList sublist = new TypeList();
for (Type type : result)
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java b/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
index ba9acab..c9be1df 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
@@ -187,7 +187,8 @@ public class Vector extends AbstractList<Numeric> implements VectorMath, Resetab
*/
@Override
public Vector subList(int fromIndex, int toIndex) {
- List<Numeric> list = this.components.subList(fromIndex, toIndex);
+ // Change the final bound to be incremented by. List.subList() is exclusive on the upper bound.
+ List<Numeric> list = this.components.subList(fromIndex, toIndex+1);
Vector result = new Vector();
for (Numeric numeric : list)
diff --git a/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java b/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java
index 86880bd..a769292 100644
--- a/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java
+++ b/src/main/java/net/sourceforge/cilib/util/ClusteringUtils.java
@@ -198,7 +198,8 @@ public final class ClusteringUtils {
int dimension = centroids.size() / numberOfClusters;
for (int i = 0; i < numberOfClusters; i++) {
- originalCentroids.add(centroids.subVector(i * dimension, (i * dimension) + dimension - 1));
+ Vector list = centroids.subList(i * dimension, (i * dimension) + dimension - 1);
+ originalCentroids.add(list);
}
}
diff --git a/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java b/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java
index 488b8dc..3a462da 100644
--- a/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java
+++ b/src/test/java/net/sourceforge/cilib/entity/IndividualTest.java
@@ -26,9 +26,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.ec.Individual;
-import net.sourceforge.cilib.type.types.Blackboard;
import net.sourceforge.cilib.type.types.Real;
-import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.container.Vector;
import org.junit.Test;
diff --git a/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java b/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
index c1de919..e3f7964 100644
--- a/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
+++ b/src/test/java/net/sourceforge/cilib/functions/clustering/ClusteringFitnessFunctionTest.java
@@ -84,6 +84,7 @@ public class ClusteringFitnessFunctionTest {
@Test
public void testEvaluate() {
// the evaluate method arranges the clusters and centroids
+ System.out.println(function.evaluate(centroids));
assertEquals(4.27188655918496, function.evaluate(centroids), DELTA);
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java
index 6a6659a..0301b81 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleFitnessTest.java
@@ -4,17 +4,17 @@
* 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
@@ -27,26 +27,26 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
/**
- *
+ *
* @author Gary Pampara
*/
public class MultipleFitnessTest {
-
+
@Test
public void testMultipleFitnessDomain() {
Measurement m = new MultipleFitness();
-
+
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
-
- Vector vector = (Vector) parser.getBuiltRepresentation();
-
- assertEquals(1, vector.getDimension());
+
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
+
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java
index 7ea536f..e477da9 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutionsTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,9 +44,9 @@ public class MultipleSolutionsTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector vector = (Vector) parser.getBuiltRepresentation();
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
- assertEquals(1, vector.getDimension());
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java
index 291f83d..4d4bdb9 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/BestParticlePositionTest.java
@@ -22,12 +22,12 @@
package net.sourceforge.cilib.measurement.single;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,10 +44,10 @@ public class BestParticlePositionTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector t = (Vector) parser.getBuiltRepresentation();
+ TypeList t = (TypeList) parser.getBuiltRepresentation();
assertTrue(t.get(0) instanceof StringType);
- assertEquals(1, t.getDimension());
+ assertEquals(1, t.size());
}
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java
index cad1f52..e7c5071 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/DiameterTest.java
@@ -4,17 +4,17 @@
* 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
@@ -32,20 +32,20 @@ import net.sourceforge.cilib.type.types.container.Vector;
import org.junit.Test;
/**
- *
+ *
* @author Gary Pampara
*/
public class DiameterTest {
-
+
@Test
public void testDiameterTestDomain() {
Measurement m = new Diameter();
-
+
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
-
+
Vector vector = (Vector) parser.getBuiltRepresentation();
-
+
assertEquals(1, vector.getDimension());
assertTrue(vector.get(0) instanceof Real);
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java
index 3fdf322..1e1800d 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/ParticlePositionsTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,9 +44,9 @@ public class ParticlePositionsTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector vector = (Vector) parser.getBuiltRepresentation();
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
- assertEquals(1, vector.getDimension());
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
}
diff --git a/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java b/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java
index 3245408..a00da70 100644
--- a/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java
+++ b/src/test/java/net/sourceforge/cilib/measurement/single/SolutionTest.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.DomainParser;
import net.sourceforge.cilib.type.types.StringType;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Test;
@@ -44,9 +44,9 @@ public class SolutionTest {
DomainParser parser = new DomainParser();
parser.parse(m.getDomain());
- Vector vector = (Vector) parser.getBuiltRepresentation();
+ TypeList vector = (TypeList) parser.getBuiltRepresentation();
- assertEquals(1, vector.getDimension());
+ assertEquals(1, vector.size());
assertTrue(vector.get(0) instanceof StringType);
}
diff --git a/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java b/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
index 100bcd8..ca30397 100644
--- a/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/DomainParserTest.java
@@ -22,6 +22,7 @@
package net.sourceforge.cilib.type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -146,13 +147,13 @@ public class DomainParserTest {
try {
parser.parse("[R(-30.0,30.0)^4]^5");
- Vector matrix = (Vector) parser.getBuiltRepresentation();
+ TypeList matrix = (TypeList) parser.getBuiltRepresentation();
// Test the dimensionality
- assertEquals(5, matrix.getDimension());
+ assertEquals(5, matrix.size());
- for (int i = 0; i < matrix.getDimension(); i++) {
- assertEquals(4, ((Vector)matrix.get(i)).getDimension());
+ for (int i = 0; i < matrix.size(); i++) {
+ assertEquals(4, ((TypeList)matrix.get(i)).size());
}
// Test object equality
diff --git a/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java b/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java
index f1d7b8b..6385942 100644
--- a/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/StringBasedDomainRegistryTest.java
@@ -23,7 +23,7 @@
package net.sourceforge.cilib.type;
import net.sourceforge.cilib.type.types.TypeUtil;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
import org.junit.Assert;
import org.junit.Test;
@@ -38,9 +38,9 @@ public class StringBasedDomainRegistryTest {
DomainRegistry registry = new StringBasedDomainRegistry();
registry.setDomainString("[R(-5.0, 5.0)^10]^10");
- Vector matrix = (Vector) registry.getBuiltRepresenation();
- Assert.assertEquals(10, matrix.getDimension());
- Assert.assertEquals(10, ((Vector) matrix.get(0)).size());
+ TypeList matrix = (TypeList) registry.getBuiltRepresenation();
+ Assert.assertEquals(10, matrix.size());
+ Assert.assertEquals(10, ((TypeList) matrix.get(0)).size());
Assert.assertTrue(TypeUtil.isInsideBounds(matrix));
}
}
diff --git a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
index 914f37f..1b03f92 100644
--- a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
@@ -27,7 +27,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import net.sourceforge.cilib.type.types.Bit;
@@ -440,69 +439,6 @@ public class VectorTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void invalidVectorDivision() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 1; i < 11; i++)
- a.append(new Real(i));
- for(int i = 1; i < 10; i++)
- b.prepend(new Real(i));
-
- a.divide(b);
- }
-
- @Test(expected = ArithmeticException.class)
- public void vectorDivisionByZero() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 1; i < 11; i++)
- a.append(new Real(i));
- for(int i = 1; i < 10; i++)
- b.prepend(new Real(i));
-
- b.prepend(new Real(0));
-
- a.divide(b);
- }
-
- @Test
- public void testVectorDivision() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 1; i < 11; i++)
- a.append(new Real(i));
- for(int i = 1; i < 10; i++)
- b.prepend(new Real(i));
-
- b.prepend(new Real(0));
- b.get(0).setReal(10);
- Vector divided = a.divide(b);
-
- assertNotNull(a);
- assertNotNull(b);
- assertNotNull(divided);
- assertNotSame(a, b);
- assertNotSame(divided, a);
- assertNotSame(divided, b);
-
- for(int i = 0; i < 10; i++) {
- assertNotNull(a.get(i));
- assertNotNull(b.get(i));
- assertNotNull(divided.get(i));
- assertNotSame(a.get(i), b.get(i));
- assertNotSame(divided.get(i), a.get(i));
- assertNotSame(divided.get(i), b.get(i));
-
- assertEquals(a.getReal(i), (i + 1.0), 0.0);
- assertEquals(b.getReal(i), (10.0 - i), 0.0);
- assertEquals(divided.getReal(i), ((i + 1) / (10.0 - i)), 0.0);
- }
- }
-
@Test(expected = ArithmeticException.class)
public void vectorDivisionByScalarZero() {
Vector a = new Vector();
@@ -536,53 +472,6 @@ public class VectorTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void invalidVectorMultiplication() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 0; i < 10; i++)
- a.append(new Real(i));
- for(int i = 0; i < 9; i++)
- b.prepend(new Real(i));
-
- a.multiply(b);
- }
-
- @Test
- public void testVectorMultiplication() {
- Vector a = new Vector();
- Vector b = new Vector();
-
- for(int i = 0; i < 10; i++)
- a.append(new Real(i));
- for(int i = 0; i < 9; i++)
- b.prepend(new Real(i));
-
- b.prepend(new Real(9));
- Vector product = a.multiply(b);
-
- assertNotNull(a);
- assertNotNull(b);
- assertNotNull(product);
- assertNotSame(a, b);
- assertNotSame(product, a);
- assertNotSame(product, b);
-
- for(int i = 0; i < 10; i++) {
- assertNotNull(a.get(i));
- assertNotNull(b.get(i));
- assertNotNull(product.get(i));
- assertNotSame(a.get(i), b.get(i));
- assertNotSame(product.get(i), a.get(i));
- assertNotSame(product.get(i), b.get(i));
-
- assertEquals(a.getReal(i), (double)i, 0.0);
- assertEquals(b.getReal(i), (9.0 - i), 0.0);
- assertEquals(product.getReal(i), (i * (9.0 - i)), 0.0);
- }
- }
-
@Test
public void testScalarMultiplication() {
Vector a = new Vector();
diff --git a/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java b/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java
index 822946c..9331544 100644
--- a/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java
+++ b/src/test/java/net/sourceforge/cilib/util/ClusteringUtilsTest.java
@@ -262,17 +262,17 @@ public class ClusteringUtilsTest {
@Test(expected = IndexOutOfBoundsException.class)
public void testArrangedCentroids() {
- assertThat(arrangedCentroids.get(0), equalTo(centroids.subVector(0, 1)));
+ assertThat(arrangedCentroids.get(0), equalTo(centroids.subList(0, 1)));
- assertThat(arrangedCentroids.get(1), equalTo(centroids.subVector(2, 3)));
+ assertThat(arrangedCentroids.get(1), equalTo(centroids.subList(2, 3)));
- assertThat(arrangedCentroids.get(2), equalTo(centroids.subVector(4, 5)));
+ assertThat(arrangedCentroids.get(2), equalTo(centroids.subList(4, 5)));
- assertThat(arrangedCentroids.get(3), equalTo(centroids.subVector(6, 7)));
+ assertThat(arrangedCentroids.get(3), equalTo(centroids.subList(6, 7)));
- assertThat(arrangedCentroids.get(4), equalTo(centroids.subVector(8, 9)));
+ assertThat(arrangedCentroids.get(4), equalTo(centroids.subList(8, 9)));
- assertThat(arrangedCentroids.get(5), equalTo(centroids.subVector(10, 11)));
+ assertThat(arrangedCentroids.get(5), equalTo(centroids.subList(10, 11)));
// the last centroid is useless, i.e. no pattern "belongs" to it
// should throw an exception (no such element / index out of bounds)
diff --git a/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java b/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java
index 35cd661..01aed31 100644
--- a/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java
+++ b/src/test/java/net/sourceforge/cilib/util/VectorUtilsTest.java
@@ -60,12 +60,6 @@ public class VectorUtilsTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void createUpperBoundVector() {
- vector.add(new Vector());
- VectorUtils.createUpperBoundVector(vector);
- }
-
@Test
public void testLowerBounds() {
int i = 1;
@@ -76,11 +70,4 @@ public class VectorUtilsTest {
}
}
- @Test(expected = UnsupportedOperationException.class)
- public void createLowerBoundVector() {
- vector.add(new Vector());
- VectorUtils.createLowerBoundVector(vector);
- }
-
-
}
--
1.6.2.3
|
|
From: Gary P. <gpa...@gm...> - 2009-06-01 08:07:53
|
The Vector class has been altered to not accept any type of object other
than a Numeric.
Migrated all Vector related calls to TypeList.
---
.../sourceforge/cilib/games/agent/NeuralAgent.java | 3 +-
.../neural/NeuralOutputInterpretationStrategy.java | 5 +-
.../state/evaluation/NeuralStateEvaluator.java | 6 +-
.../predatorprey/NeuralPredatorOutputStrategy.java | 13 +-
.../predatorprey/NeuralPreyOutputStrategy.java | 15 +-
.../cilib/games/items/GridLocation.java | 11 +-
.../measurement/RecordItemLocationMeasure.java | 7 +-
.../measurement/multiple/CompositeMeasurement.java | 4 +-
.../measurement/multiple/ParetoOptimalFront.java | 6 +-
.../measurement/multiple/ParetoOptimalSet.java | 3 +-
.../neuralnetwork/basicFFNN/FFNNTopology.java | 5 +-
.../neuralnetwork/basicFFNN/TrainAndTestNN.java | 3 +-
.../foundation/EvaluationMediator.java | 5 +-
.../cilib/neuralnetwork/foundation/NNError.java | 4 +-
.../foundation/NeuralNetworkProblem.java | 3 +-
.../foundation/NeuralNetworkTopology.java | 3 +-
.../BatchTrainingSetEpochStrategy.java | 4 +-
...chasticTrainingGeneralisationEpochStrategy.java | 5 +-
.../foundation/measurements/AreaUnderROC.java | 6 +-
.../foundation/measurements/NNOutput.java | 4 +-
.../neuralnetwork/generic/GenericTopology.java | 3 +-
.../generic/LayeredGenericTopology.java | 7 +-
.../DynamicPatternSelectionData.java | 4 +-
.../errorfunctions/ClassificationErrorReal.java | 6 +-
.../generic/errorfunctions/MSEErrorFunction.java | 4 +-
.../FFNNEvaluationMediator.java | 9 +-
.../SAILAEvaluationMediator.java | 22 +-
.../topologyvisitors/WeightExtractingVisitor.java | 3 +-
.../generic/trainingstrategies/ErrorSignal.java | 4 +-
.../FFNN_GD_TrainingStrategy.java | 8 +-
.../trainingstrategies/SquaredErrorFunction.java | 3 +-
.../testarea/TestErrorINCLearnWithTrainer.java | 3 +-
.../testarea/TestFFNNandGDTrainer.java | 3 +-
.../testarea/TestNeuronAndEvaluateFFNN.java | 5 +-
.../testarea/TestSAILAwithTrainer.java | 3 +-
.../cilib/type/types/container/Randomizable.java | 13 +-
.../cilib/type/types/container/TypeList.java | 4 +
.../cilib/type/types/container/Vector.java | 725 +++++++-------------
.../net/sourceforge/cilib/util/VectorUtils.java | 24 +-
39 files changed, 398 insertions(+), 570 deletions(-)
diff --git a/src/main/java/net/sourceforge/cilib/games/agent/NeuralAgent.java b/src/main/java/net/sourceforge/cilib/games/agent/NeuralAgent.java
index ce39421..7ae9102 100644
--- a/src/main/java/net/sourceforge/cilib/games/agent/NeuralAgent.java
+++ b/src/main/java/net/sourceforge/cilib/games/agent/NeuralAgent.java
@@ -32,6 +32,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.topologybuilders.FFNNgenericT
import net.sourceforge.cilib.type.DomainRegistry;
import net.sourceforge.cilib.type.StringBasedDomainRegistry;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
@@ -132,7 +133,7 @@ public class NeuralAgent extends Agent {
Vector input = stateInputStrategy.getNeuralInputArray(this, game);
StandardPattern pattern = new StandardPattern(input, input);
//get the output vector
- Vector NNOutput = neuralNetworkTopology.evaluate(pattern);//perform NN iteration, get output
+ TypeList NNOutput = neuralNetworkTopology.evaluate(pattern);//perform NN iteration, get output
outputInterpretationStrategy.applyOutputToState(NNOutput, this, game);
}
diff --git a/src/main/java/net/sourceforge/cilib/games/agent/neural/NeuralOutputInterpretationStrategy.java b/src/main/java/net/sourceforge/cilib/games/agent/neural/NeuralOutputInterpretationStrategy.java
index 938cd42..184c35a 100644
--- a/src/main/java/net/sourceforge/cilib/games/agent/neural/NeuralOutputInterpretationStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/games/agent/neural/NeuralOutputInterpretationStrategy.java
@@ -22,9 +22,10 @@
package net.sourceforge.cilib.games.agent.neural;
import net.sourceforge.cilib.games.agent.Agent;
+import net.sourceforge.cilib.games.agent.NeuralAgent;
import net.sourceforge.cilib.games.game.Game;
import net.sourceforge.cilib.games.states.GameState;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author leo
@@ -46,5 +47,5 @@ public abstract class NeuralOutputInterpretationStrategy {
* @param currentPlayer the agent that is represented by the Neural Network
* @param oldState the game state to be altered
*/
- public abstract void applyOutputToState(Vector outputData, Agent currentPlayer, Game<GameState> oldState);
+ public abstract void applyOutputToState(TypeList outputData, Agent currentPlayer, Game<GameState> oldState);
}
diff --git a/src/main/java/net/sourceforge/cilib/games/agent/state/evaluation/NeuralStateEvaluator.java b/src/main/java/net/sourceforge/cilib/games/agent/state/evaluation/NeuralStateEvaluator.java
index dc2c070..4c0c912 100644
--- a/src/main/java/net/sourceforge/cilib/games/agent/state/evaluation/NeuralStateEvaluator.java
+++ b/src/main/java/net/sourceforge/cilib/games/agent/state/evaluation/NeuralStateEvaluator.java
@@ -30,7 +30,9 @@ import net.sourceforge.cilib.games.states.GameState;
import net.sourceforge.cilib.neuralnetwork.generic.datacontainers.StandardPattern;
import net.sourceforge.cilib.neuralnetwork.generic.topologybuilders.FFNNgenericTopologyBuilder;
import net.sourceforge.cilib.type.DomainRegistry;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -65,8 +67,8 @@ public class NeuralStateEvaluator extends NeuralAgent implements StateEvaluator
Vector input = stateInputStrategy.getNeuralInputArray(this, state);
StandardPattern pattern = new StandardPattern(input, input);
//get the output vector
- Vector NNOutput = neuralNetworkTopology.evaluate(pattern);//perform NN iteration, get output
- return NNOutput.getReal(0);
+ TypeList NNOutput = neuralNetworkTopology.evaluate(pattern);//perform NN iteration, get output
+ return ((Numeric) NNOutput.get(0)).getReal();
}
/**
diff --git a/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPredatorOutputStrategy.java b/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPredatorOutputStrategy.java
index 4a81d7c..eb14e53 100644
--- a/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPredatorOutputStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPredatorOutputStrategy.java
@@ -25,7 +25,8 @@ import net.sourceforge.cilib.games.agent.neural.NeuralOutputInterpretationStrate
import net.sourceforge.cilib.games.agent.Agent;
import net.sourceforge.cilib.games.game.Game;
import net.sourceforge.cilib.games.items.GameToken;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.Numeric;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author leo
@@ -40,21 +41,21 @@ public class NeuralPredatorOutputStrategy extends
* {@inheritDoc}
*/
@Override
- public void applyOutputToState(Vector outputData, Agent currentPlayer, Game oldState) {
+ public void applyOutputToState(TypeList outputData, Agent currentPlayer, Game oldState) {
if(!(oldState instanceof PredatorPreyGame))
throw new RuntimeException("Invalid game for this agent");
if(!currentPlayer.getAgentToken().equals(GameToken.PredatorPrey.PREDATOR))
throw new RuntimeException("This strategy can only be used on a prey player");
PredatorPreyGame game = (PredatorPreyGame)oldState;
int x = 0;
- if(outputData.getReal(0) > 0.0) //move on x axis
- if(outputData.getReal(1) > 0.0) //move right
+ if(((Numeric) outputData.get(0)).getReal() > 0.0) //move on x axis
+ if(((Numeric) outputData.get(1)).getReal() > 0.0) //move right
x = 1;
else
x = -1;
int y = 0;
- if(outputData.getReal(2) > 0.0) //move on y axis
- if(outputData.getReal(3) > 0.0) //move down
+ if(((Numeric) outputData.get(2)).getReal() > 0.0) //move on y axis
+ if(((Numeric) outputData.get(3)).getReal() > 0.0) //move down
y = 1;
else
y = -1;
diff --git a/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPreyOutputStrategy.java b/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPreyOutputStrategy.java
index 96ebd04..dd86b24 100644
--- a/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPreyOutputStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/games/game/predatorprey/NeuralPreyOutputStrategy.java
@@ -25,7 +25,8 @@ import net.sourceforge.cilib.games.agent.Agent;
import net.sourceforge.cilib.games.agent.neural.NeuralOutputInterpretationStrategy;
import net.sourceforge.cilib.games.game.Game;
import net.sourceforge.cilib.games.items.GameToken;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.Numeric;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author leo
@@ -40,7 +41,7 @@ public class NeuralPreyOutputStrategy extends
* {@inheritDoc}
*/
@Override
- public void applyOutputToState(Vector outputData, Agent currentPlayer, Game oldState) {
+ public void applyOutputToState(TypeList outputData, Agent currentPlayer, Game oldState) {
if(!(oldState instanceof PredatorPreyGame))
throw new RuntimeException("Invalid game for this agent");
@@ -49,19 +50,19 @@ public class NeuralPreyOutputStrategy extends
PredatorPreyGame game = (PredatorPreyGame)oldState;
int moveAmount = 1;
- if(outputData.getReal(0) > 0.0) //move 2 squares
+ if(((Numeric) outputData.get(0)).getReal() > 0.0) //move 2 squares
moveAmount = 2;
int x = 0;
- if(outputData.getReal(1) > 0.0) //move on x axis
- if(outputData.getReal(2) > 0.0) //move right
+ if(((Numeric) outputData.get(1)).getReal() > 0.0) //move on x axis
+ if(((Numeric) outputData.get(2)).getReal() > 0.0) //move right
x = 1;
else
x = -1;
int y = 0;
- if(outputData.getReal(3) > 0.0) //move on y axis
- if(outputData.getReal(4) > 0.0) //move down
+ if(((Numeric) outputData.get(3)).getReal() > 0.0) //move on y axis
+ if(((Numeric) outputData.get(4)).getReal() > 0.0) //move down
y = 1;
else
y = -1;
diff --git a/src/main/java/net/sourceforge/cilib/games/items/GridLocation.java b/src/main/java/net/sourceforge/cilib/games/items/GridLocation.java
index ba14f96..fb646dd 100644
--- a/src/main/java/net/sourceforge/cilib/games/items/GridLocation.java
+++ b/src/main/java/net/sourceforge/cilib/games/items/GridLocation.java
@@ -22,6 +22,7 @@
package net.sourceforge.cilib.games.items;
import net.sourceforge.cilib.type.types.Int;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.container.Vector;
import net.sourceforge.cilib.util.DistanceMeasure;
@@ -58,7 +59,7 @@ public class GridLocation extends Vector implements ItemLocation {
throw new UnsupportedOperationException("Cannot set the postition to a vector with a different dimention");
}
this.clear();
- for(Type t: newPos){
+ for(Numeric t : newPos){
this.add(t.getClone());
}
}
@@ -90,10 +91,10 @@ public class GridLocation extends Vector implements ItemLocation {
for(int i = 0; i < ((Vector)amount).size(); ++i){
int newVal = ((Vector)amount).getInt(i) + this.getInt(i);
- if(newVal < this.getNumeric(i).getBounds().getLowerBound())
- newVal = (int)this.getNumeric(i).getBounds().getLowerBound();
- else if(newVal > this.getNumeric(i).getBounds().getUpperBound())
- newVal = (int)this.getNumeric(i).getBounds().getUpperBound();
+ if(newVal < this.get(i).getBounds().getLowerBound())
+ newVal = (int)this.get(i).getBounds().getLowerBound();
+ else if(newVal > this.get(i).getBounds().getUpperBound())
+ newVal = (int)this.get(i).getBounds().getUpperBound();
this.setInt(i, newVal);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/games/measurement/RecordItemLocationMeasure.java b/src/main/java/net/sourceforge/cilib/games/measurement/RecordItemLocationMeasure.java
index c13f42b..0a7a9fd 100644
--- a/src/main/java/net/sourceforge/cilib/games/measurement/RecordItemLocationMeasure.java
+++ b/src/main/java/net/sourceforge/cilib/games/measurement/RecordItemLocationMeasure.java
@@ -25,6 +25,7 @@ import net.sourceforge.cilib.games.game.Game;
import net.sourceforge.cilib.games.items.GameItem;
import net.sourceforge.cilib.games.states.GameState;
import net.sourceforge.cilib.games.states.ListGameState;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.container.Vector;
@@ -36,9 +37,9 @@ import net.sourceforge.cilib.type.types.container.Vector;
*/
public class RecordItemLocationMeasure extends SingleAgentMeasure {
private static final long serialVersionUID = -7742916583743476119L;
- Vector locations;
+ private Vector locations;
+
public RecordItemLocationMeasure() {
- super();
locations = new Vector();
}
@@ -81,7 +82,7 @@ public class RecordItemLocationMeasure extends SingleAgentMeasure {
if(!(state instanceof ListGameState))
throw new RuntimeException("Impliment for other state types");
GameItem item = ((ListGameState)state).getItem(itemToken);
- locations.add(item.getLocation().getClone());
+ locations.add((Numeric) item.getLocation().getClone());
}
}
diff --git a/src/main/java/net/sourceforge/cilib/measurement/multiple/CompositeMeasurement.java b/src/main/java/net/sourceforge/cilib/measurement/multiple/CompositeMeasurement.java
index 20fe3e0..268eb28 100644
--- a/src/main/java/net/sourceforge/cilib/measurement/multiple/CompositeMeasurement.java
+++ b/src/main/java/net/sourceforge/cilib/measurement/multiple/CompositeMeasurement.java
@@ -28,7 +28,7 @@ import net.sourceforge.cilib.algorithm.population.MultiPopulationBasedAlgorithm;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* Measurement to perform measurements on a set of contained {@code Algorithm}
@@ -68,7 +68,7 @@ public class CompositeMeasurement implements Measurement {
*/
@Override
public Type getValue(Algorithm algorithm) {
- Vector vector = new Vector();
+ TypeList vector = new TypeList();
MultiPopulationBasedAlgorithm multi = (MultiPopulationBasedAlgorithm) algorithm;
diff --git a/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalFront.java b/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalFront.java
index 74023ab..e3330c8 100644
--- a/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalFront.java
+++ b/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalFront.java
@@ -30,7 +30,7 @@ import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.problem.MOFitness;
import net.sourceforge.cilib.problem.OptimisationSolution;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* <p>
@@ -62,11 +62,11 @@ public class ParetoOptimalFront implements Measurement {
@Override
public Type getValue(Algorithm algorithm) {
- Vector allFitnessValues = new Vector();
+ TypeList allFitnessValues = new TypeList();
Collection<OptimisationSolution> solutions = Archive.get();
for (OptimisationSolution solution : solutions) {
MOFitness fitnesses = (MOFitness) solution.getFitness();
- Vector fitnessValues = new Vector();
+ TypeList fitnessValues = new TypeList();
for (int i = 0; i < fitnesses.getDimension(); ++i) {
Fitness fitness = fitnesses.getFitness(i);
fitnessValues.add(fitness);
diff --git a/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalSet.java b/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalSet.java
index b40e1ff..b2486a4 100644
--- a/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalSet.java
+++ b/src/main/java/net/sourceforge/cilib/measurement/multiple/ParetoOptimalSet.java
@@ -28,6 +28,7 @@ import net.sourceforge.cilib.measurement.Measurement;
import net.sourceforge.cilib.moo.archive.Archive;
import net.sourceforge.cilib.problem.OptimisationSolution;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -59,7 +60,7 @@ public class ParetoOptimalSet implements Measurement {
@Override
public Type getValue(Algorithm algorithm) {
- Vector allPositions = new Vector();
+ TypeList allPositions = new TypeList();
Collection<OptimisationSolution> solutions = Archive.get();
for (OptimisationSolution solution : solutions) {
Vector position = (Vector) solution.getPosition();
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/FFNNTopology.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/FFNNTopology.java
index a762513..ffaedf9 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/FFNNTopology.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/FFNNTopology.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import net.sourceforge.cilib.neuralnetwork.foundation.NNPattern;
import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkTopology;
import net.sourceforge.cilib.type.types.Real;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -102,7 +103,7 @@ public class FFNNTopology implements NeuralNetworkTopology {
* (non-Javadoc)
* @see net.sourceforge.cilib.NeuralNetwork.Foundation.NeuralNetworkTopology#evaluate(net.sourceforge.cilib.NeuralNetwork.Foundation.NNPattern)
*/
- public Vector evaluate(NNPattern p) {
+ public TypeList evaluate(NNPattern p) {
// Still need to check here for right length vector then exception
// Does not delete the activation of hidden or output units, used to feed back...
// zeroes activation before doing a feedforward though...
@@ -143,7 +144,7 @@ public class FFNNTopology implements NeuralNetworkTopology {
}
// convert to ArrayList...
- Vector temp = new Vector();
+ TypeList temp = new TypeList();
output = new ArrayList<Double>();
for (int i = 0; i < nrOutput; i++) {
temp.add(new Real(outputResult[i]));
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/TrainAndTestNN.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/TrainAndTestNN.java
index f53a8d3..afe82d4 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/TrainAndTestNN.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/basicFFNN/TrainAndTestNN.java
@@ -34,6 +34,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.datacontainers.StandardPatter
import net.sourceforge.cilib.neuralnetwork.generic.errorfunctions.MSEErrorFunction;
import net.sourceforge.cilib.stoppingcondition.MaximumIterations;
import net.sourceforge.cilib.type.types.Real;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -110,7 +111,7 @@ public final class TrainAndTestNN {
StandardPattern p = new StandardPattern(in, null);
- Vector result = neuralNetworkTopology.evaluate(p);
+ TypeList result = neuralNetworkTopology.evaluate(p);
//output line - add any status here that reports on the manual pattern entered.
System.out.println("test result: 1 and 1 = 0.6 --> " + ((Real) result.get(0)).getReal());
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/EvaluationMediator.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/EvaluationMediator.java
index 64a37d9..d218bf5 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/EvaluationMediator.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/EvaluationMediator.java
@@ -29,6 +29,7 @@ import net.sourceforge.cilib.algorithm.SingularAlgorithm;
import net.sourceforge.cilib.neuralnetwork.foundation.epochstrategy.EmptyEpochStrategy;
import net.sourceforge.cilib.neuralnetwork.foundation.epochstrategy.EpochStrategy;
import net.sourceforge.cilib.problem.OptimisationSolution;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
@@ -104,7 +105,7 @@ public class EvaluationMediator extends SingularAlgorithm {
this.epochStrategy.performIteration(this);
}
- public void computeErrorIteration(NNError[] err, Vector output, NNPattern input){
+ public void computeErrorIteration(NNError[] err, TypeList output, NNPattern input){
for (int e = 0; e < err.length; e++){
err[e].computeIteration(output, input);
@@ -113,7 +114,7 @@ public class EvaluationMediator extends SingularAlgorithm {
}
// This might not be needed in this class.
- public Vector evaluate(NNPattern p) {
+ public TypeList evaluate(NNPattern p) {
return topology.evaluate(p);
}
// public abstract Vector evaluate(NNPattern p);
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NNError.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NNError.java
index 3ea4e60..0a4a971 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NNError.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NNError.java
@@ -22,14 +22,14 @@
package net.sourceforge.cilib.neuralnetwork.foundation;
import net.sourceforge.cilib.problem.Fitness;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* TODO: Complete this javadoc.
*/
public interface NNError extends Fitness, Initializable {
- public void computeIteration(Vector output, NNPattern input);
+ public void computeIteration(TypeList output, NNPattern input);
public void finaliseError();
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkProblem.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkProblem.java
index b0eae27..8671d11 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkProblem.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkProblem.java
@@ -28,6 +28,7 @@ import net.sourceforge.cilib.problem.ProblemVisitor;
import net.sourceforge.cilib.problem.dataset.DataSetBuilder;
import net.sourceforge.cilib.type.DomainRegistry;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -70,7 +71,7 @@ public class NeuralNetworkProblem implements OptimisationProblem, Initializable
return evaluationStrategy.getErrorDt();
}
- public Vector evaluate(Vector in){
+ public TypeList evaluate(Vector in){
StandardPattern p = new StandardPattern(in, null);
return evaluationStrategy.evaluate(p);
}
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkTopology.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkTopology.java
index a8eacdc..5a96df0 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkTopology.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/NeuralNetworkTopology.java
@@ -22,6 +22,7 @@
package net.sourceforge.cilib.neuralnetwork.foundation;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -31,7 +32,7 @@ import net.sourceforge.cilib.type.types.container.Vector;
*/
public interface NeuralNetworkTopology extends Initializable{
- public Vector evaluate(NNPattern p);
+ public TypeList evaluate(NNPattern p);
public Vector getWeights();
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/BatchTrainingSetEpochStrategy.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/BatchTrainingSetEpochStrategy.java
index 5322126..36bcde1 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/BatchTrainingSetEpochStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/BatchTrainingSetEpochStrategy.java
@@ -23,7 +23,7 @@ package net.sourceforge.cilib.neuralnetwork.foundation.epochstrategy;
import net.sourceforge.cilib.neuralnetwork.foundation.EvaluationMediator;
import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkDataIterator;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
public class BatchTrainingSetEpochStrategy implements EpochStrategy {
@@ -37,7 +37,7 @@ public class BatchTrainingSetEpochStrategy implements EpochStrategy {
//iterate over each applicable pattern in training dataset
while (iteratorDt.hasMore()){
- Vector output = evaluationMediator.getTopology().evaluate(iteratorDt.value());
+ TypeList output = evaluationMediator.getTopology().evaluate(iteratorDt.value());
evaluationMediator.incrementEvaluationsPerEpoch();
//compute the per pattern error.
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/StochasticTrainingGeneralisationEpochStrategy.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/StochasticTrainingGeneralisationEpochStrategy.java
index a248e86..442930d 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/StochasticTrainingGeneralisationEpochStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/epochstrategy/StochasticTrainingGeneralisationEpochStrategy.java
@@ -23,6 +23,7 @@ package net.sourceforge.cilib.neuralnetwork.foundation.epochstrategy;
import net.sourceforge.cilib.neuralnetwork.foundation.EvaluationMediator;
import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkDataIterator;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
public class StochasticTrainingGeneralisationEpochStrategy implements
@@ -43,7 +44,7 @@ public class StochasticTrainingGeneralisationEpochStrategy implements
//iterate over each applicable pattern in training dataset
while(iteratorDt.hasMore()){
- Vector output = evaluationMediator.getTopology().evaluate(iteratorDt.value());
+ TypeList output = evaluationMediator.getTopology().evaluate(iteratorDt.value());
evaluationMediator.incrementEvaluationsPerEpoch();
//compute the per pattern error, use it to train the topology stochastically be default
@@ -62,7 +63,7 @@ public class StochasticTrainingGeneralisationEpochStrategy implements
while(iteratorDg.hasMore()){
- Vector outputDg = evaluationMediator.getTopology().evaluate(iteratorDg.value());
+ TypeList outputDg = evaluationMediator.getTopology().evaluate(iteratorDg.value());
//compute the per pattern error, use it to train the topology stochastically be default
evaluationMediator.computeErrorIteration(evaluationMediator.getErrorDg(), outputDg, iteratorDg.value());
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/AreaUnderROC.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/AreaUnderROC.java
index 67e09df..e105834 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/AreaUnderROC.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/AreaUnderROC.java
@@ -30,7 +30,7 @@ import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkTopology;
import net.sourceforge.cilib.type.types.Real;
import net.sourceforge.cilib.type.types.StringType;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* TODO: Fill in some javadoc.
@@ -82,7 +82,7 @@ public class AreaUnderROC implements Measurement{
//Determine winning output, determine if misclassification
NNPattern p = iterDv.value();
- Vector output = this.topology.evaluate(p);
+ TypeList output = this.topology.evaluate(p);
int winningOutput = 99999;
double winningOutputValue = 0.0;
@@ -181,7 +181,7 @@ public class AreaUnderROC implements Measurement{
}
String accuracy = String.valueOf(accuracyVal / totalPats);
- Vector v = new Vector();
+ TypeList v = new TypeList();
v.add(new Real(totalAUC));
v.add(new StringType(countString));
v.add(new StringType(matrix));
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/NNOutput.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/NNOutput.java
index e571b21..dbc8fcf 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/NNOutput.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/measurements/NNOutput.java
@@ -35,7 +35,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.datacontainers.GenericData;
import net.sourceforge.cilib.neuralnetwork.generic.datacontainers.RandomDistributionStrategy;
import net.sourceforge.cilib.type.types.StringType;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* Measurement to determine the output of a Neural Network.
@@ -89,7 +89,7 @@ public class NNOutput implements Measurement {
iteratorDc.reset();
while(iteratorDc.hasMore()){
- Vector outputDg = topology.evaluate(iteratorDc.value());
+ TypeList outputDg = topology.evaluate(iteratorDc.value());
try {
out.write(iteratorDc.value().getInput().toString() + " " + outputDg.toString());
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/GenericTopology.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/GenericTopology.java
index a07872d..8a95b00 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/GenericTopology.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/GenericTopology.java
@@ -32,6 +32,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.topologyvisitors.GenericTopol
import net.sourceforge.cilib.neuralnetwork.generic.topologyvisitors.RandomWeightInitialiser;
import net.sourceforge.cilib.neuralnetwork.generic.topologyvisitors.SpecificWeightInitialiser;
import net.sourceforge.cilib.neuralnetwork.generic.topologyvisitors.WeightExtractingVisitor;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -95,7 +96,7 @@ public abstract class GenericTopology implements NeuralNetworkTopology, Initiali
}
- public abstract Vector evaluate(NNPattern p);
+ public abstract TypeList evaluate(NNPattern p);
public ArrayList<NeuronConfig> getLayer(int index){
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/LayeredGenericTopology.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/LayeredGenericTopology.java
index 116c944..fd87cbb 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/LayeredGenericTopology.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/LayeredGenericTopology.java
@@ -26,7 +26,7 @@ import java.util.ArrayList;
import net.sourceforge.cilib.neuralnetwork.foundation.NNPattern;
import net.sourceforge.cilib.neuralnetwork.generic.neuron.NeuronConfig;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* TODO: Complete this javadoc.
@@ -49,9 +49,10 @@ public class LayeredGenericTopology extends GenericTopology {
super.initialize();
}
- public Vector evaluate(NNPattern p){
+ @Override
+ public TypeList evaluate(NNPattern p){
- Vector output = new Vector();
+ TypeList output = new TypeList();
for (int layer = 0; layer < layerList.size(); layer++){
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/datacontainers/DynamicPatternSelectionData.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/datacontainers/DynamicPatternSelectionData.java
index 0234dce..c0de472 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/datacontainers/DynamicPatternSelectionData.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/datacontainers/DynamicPatternSelectionData.java
@@ -28,7 +28,7 @@ import net.sourceforge.cilib.neuralnetwork.foundation.NNError;
import net.sourceforge.cilib.neuralnetwork.foundation.NNPattern;
import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkDataIterator;
import net.sourceforge.cilib.neuralnetwork.generic.GenericTopology;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
@@ -112,7 +112,7 @@ public class DynamicPatternSelectionData extends GenericData implements Initiali
NNPattern p = dcIter.value();
//Evaluate p against current NN topology.
- Vector output = this.topology.evaluate(p);
+ TypeList output = this.topology.evaluate(p);
//determine informativeness of p
NNError patternError = prototypeError.getClone();
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/ClassificationErrorReal.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/ClassificationErrorReal.java
index ec69c85..0b7d206 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/ClassificationErrorReal.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/ClassificationErrorReal.java
@@ -25,7 +25,7 @@ import net.sourceforge.cilib.neuralnetwork.foundation.NNError;
import net.sourceforge.cilib.neuralnetwork.foundation.NNPattern;
import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.type.types.Real;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author Stefan
@@ -47,7 +47,7 @@ public class ClassificationErrorReal implements NNError {
}
- public void computeIteration(Vector output, NNPattern input) {
+ public void computeIteration(TypeList output, NNPattern input) {
boolean isCorrect = true;
@@ -90,7 +90,7 @@ public class ClassificationErrorReal implements NNError {
throw new IllegalArgumentException("Incorrect class instance passed");
}
- return (Double.valueOf(this.percentageCorrect)).compareTo((Double) ((ClassificationErrorReal) f).getValue());
+ return (Double.valueOf(this.percentageCorrect)).compareTo(((ClassificationErrorReal) f).getValue());
}
public NNError getClone(){
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/MSEErrorFunction.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/MSEErrorFunction.java
index c0fe4ab..80c325d 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/MSEErrorFunction.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/errorfunctions/MSEErrorFunction.java
@@ -27,7 +27,7 @@ import net.sourceforge.cilib.neuralnetwork.foundation.NNPattern;
import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkData;
import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.type.types.Real;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author stefanv
@@ -96,7 +96,7 @@ public class MSEErrorFunction implements NNError, Initializable {
}
- public void computeIteration(Vector output, NNPattern input) {
+ public void computeIteration(TypeList output, NNPattern input) {
if (input.getTargetLength() != output.size()){
throw new IllegalArgumentException("Output and target lenghts don't match");
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/FFNNEvaluationMediator.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/FFNNEvaluationMediator.java
index 7fe9c67..775f849 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/FFNNEvaluationMediator.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/FFNNEvaluationMediator.java
@@ -24,12 +24,11 @@ package net.sourceforge.cilib.neuralnetwork.generic.evaluationmediators;
import java.util.List;
import net.sourceforge.cilib.algorithm.Algorithm;
-import net.sourceforge.cilib.entity.visitor.TopologyVisitor;
import net.sourceforge.cilib.neuralnetwork.foundation.EvaluationMediator;
import net.sourceforge.cilib.neuralnetwork.foundation.NNPattern;
import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkDataIterator;
import net.sourceforge.cilib.problem.OptimisationSolution;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author stefanv
@@ -72,7 +71,7 @@ public class FFNNEvaluationMediator extends EvaluationMediator {
//iterate over each applicable pattern in training dataset
while(iteratorDt.hasMore()){
- Vector output = topology.evaluate(iteratorDt.value());
+ TypeList output = topology.evaluate(iteratorDt.value());
this.nrEvaluationsPerEpoch++;
//compute the per pattern error, use it to train the topology stochastically be default
@@ -91,7 +90,7 @@ public class FFNNEvaluationMediator extends EvaluationMediator {
while(iteratorDg.hasMore()){
- Vector outputDg = topology.evaluate(iteratorDg.value());
+ TypeList outputDg = topology.evaluate(iteratorDg.value());
//compute the per pattern error, use it to train the topology stochastically be default
this.computeErrorIteration(this.errorDg, outputDg, iteratorDg.value());
@@ -107,7 +106,7 @@ public class FFNNEvaluationMediator extends EvaluationMediator {
}
- public Vector evaluate(NNPattern p) {
+ public TypeList evaluate(NNPattern p) {
return topology.evaluate(p);
}
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/SAILAEvaluationMediator.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/SAILAEvaluationMediator.java
index 31c04e0..d8dc137 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/SAILAEvaluationMediator.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/evaluationmediators/SAILAEvaluationMediator.java
@@ -32,7 +32,7 @@ import net.sourceforge.cilib.neuralnetwork.foundation.NeuralNetworkDataIterator;
import net.sourceforge.cilib.neuralnetwork.generic.datacontainers.SAILARealData;
import net.sourceforge.cilib.neuralnetwork.generic.errorfunctions.MSEErrorFunction;
import net.sourceforge.cilib.problem.OptimisationSolution;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
@@ -118,7 +118,7 @@ public class SAILAEvaluationMediator extends EvaluationMediator {
iteratorDg = data.getGeneralisationSetIterator();
//set the initial error to the error on Dt = 1 pattern.
- Vector tmpO = topology.evaluate(iteratorDt.value());
+ TypeList tmpO = topology.evaluate(iteratorDt.value());
subsetBeginErrorDt.computeIteration(tmpO, iteratorDt.value());
subsetBeginErrorDg.computeIteration(tmpO, iteratorDg.value());
subsetBeginErrorDt.finaliseError();
@@ -156,7 +156,7 @@ public class SAILAEvaluationMediator extends EvaluationMediator {
//iterate over training set
while(iteratorDt.hasMore()){
- Vector outputDt = topology.evaluate(iteratorDt.value());
+ TypeList outputDt = topology.evaluate(iteratorDt.value());
//compute the per pattern error, use it to train the topology stochastically by default
this.computeErrorIteration(this.errorDt, outputDt, iteratorDt.value());
@@ -174,7 +174,7 @@ public class SAILAEvaluationMediator extends EvaluationMediator {
while(iteratorDg.hasMore()){
- Vector outputDg = topology.evaluate(iteratorDg.value());
+ TypeList outputDg = topology.evaluate(iteratorDg.value());
//compute the per pattern error, use it to train the topology stochastically be default
this.computeErrorIteration(this.errorDg, outputDg, iteratorDg.value());
@@ -234,7 +234,7 @@ public class SAILAEvaluationMediator extends EvaluationMediator {
}
//save the local var this.errorDt[0] as previous
- errorDtPrevious.setValue(((Double) this.errorDt[0].getValue()).doubleValue());
+ errorDtPrevious.setValue((this.errorDt[0].getValue()).doubleValue());
//criterion 4: Error on Dg increases too much
@@ -242,19 +242,19 @@ public class SAILAEvaluationMediator extends EvaluationMediator {
//averageNew = (averageOld * periodsOld + new_sample) / (periodsOld + 1)
epochNumber++;
- averageErrorDg = ((double) (averageErrorDg * (epochNumber - 1)) + ((Double) this.errorDg[0].getValue()).doubleValue()) / (double) epochNumber;
+ averageErrorDg = ((averageErrorDg * (epochNumber - 1)) + (this.errorDg[0].getValue()).doubleValue()) / (double) epochNumber;
history.add(this.errorDt[0]);
double errorDgStdDev = 0;
for(int i = 0; i < history.size(); i++){
- errorDgStdDev += Math.pow(((Double) history.get(i).getValue()).doubleValue() - averageErrorDg, 2);
+ errorDgStdDev += Math.pow((history.get(i).getValue()).doubleValue() - averageErrorDg, 2);
}
errorDgStdDev = Math.sqrt(errorDgStdDev / (double) history.size());
- if (((Double) this.errorDg[0].getValue()).doubleValue() > (averageErrorDg + errorDgStdDev)) {
+ if ((this.errorDg[0].getValue()).doubleValue() > (averageErrorDg + errorDgStdDev)) {
terminate = true;
System.out.println("___________SAILA Termination criterion 4: Validation error rising too much, overfitting detected");
}
@@ -272,15 +272,15 @@ public class SAILAEvaluationMediator extends EvaluationMediator {
subsetEpochCounter = 0;
//criterion 2 reset
- ((MSEErrorFunction) subsetBeginErrorDt).setValue(((Double) this.errorDt[0].getValue()).doubleValue());
- ((MSEErrorFunction) subsetBeginErrorDg).setValue(((Double) this.errorDg[0].getValue()).doubleValue());
+ ((MSEErrorFunction) subsetBeginErrorDt).setValue((this.errorDt[0].getValue()).doubleValue());
+ ((MSEErrorFunction) subsetBeginErrorDg).setValue((this.errorDg[0].getValue()).doubleValue());
}
data.shuffleTrainingSet();
}
- public Vector evaluate(NNPattern p) {
+ public TypeList evaluate(NNPattern p) {
return topology.evaluate(p);
}
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/topologyvisitors/WeightExtractingVisitor.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/topologyvisitors/WeightExtractingVisitor.java
index 32525ae..f52099e 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/topologyvisitors/WeightExtractingVisitor.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/topologyvisitors/WeightExtractingVisitor.java
@@ -23,6 +23,7 @@ package net.sourceforge.cilib.neuralnetwork.generic.topologyvisitors;
import net.sourceforge.cilib.neuralnetwork.generic.Weight;
import net.sourceforge.cilib.neuralnetwork.generic.neuron.NeuronConfig;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -42,7 +43,7 @@ public class WeightExtractingVisitor implements GenericTopologyVisitor {
Weight[] neuronWeights = n.getInputWeights();
for (int i = 0; i < neuronWeights.length; i++){
- weights.add(neuronWeights[i].getWeightValue().getClone());
+ weights.add((Numeric) neuronWeights[i].getWeightValue().getClone());
}
}
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/ErrorSignal.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/ErrorSignal.java
index 2bbc6c7..46a669c 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/ErrorSignal.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/ErrorSignal.java
@@ -25,7 +25,7 @@ import java.util.ArrayList;
import net.sourceforge.cilib.neuralnetwork.generic.Weight;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author stefanv
@@ -36,7 +36,7 @@ public interface ErrorSignal {
public Type computeBaseDelta(Type desired, Type output, Type outputFunctionDerivative);
public Type computeRecursiveDelta(Type outputFunctionDerivative,
- Vector delta,
+ TypeList delta,
ArrayList<Weight> w,
Type output);
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/FFNN_GD_TrainingStrategy.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/FFNN_GD_TrainingStrategy.java
index bbc65cb..9779639 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/FFNN_GD_TrainingStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/FFNN_GD_TrainingStrategy.java
@@ -33,7 +33,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.Weight;
import net.sourceforge.cilib.neuralnetwork.generic.neuron.NeuronConfig;
import net.sourceforge.cilib.type.types.Real;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author stefanv
@@ -112,11 +112,11 @@ public class FFNN_GD_TrainingStrategy implements TrainingStrategy, Observer {
NNPattern p = (NNPattern) args;
ArrayList<NeuronConfig> updateNeuronList = new ArrayList<NeuronConfig>();
- Vector deltaUpdateList = new Vector();
+ TypeList deltaUpdateList = new TypeList();
//iterate over output layer
LayerIterator outputIter = topology.getLayerIterator(topology.getNrLayers() - 1);
- Vector prevDeltaList = new Vector(outputIter.getNrNeurons());
+ TypeList prevDeltaList = new TypeList(outputIter.getNrNeurons());
LayerIterator prevIter = null;
for (NeuronConfig oi = outputIter.value(); outputIter.hasMore(); outputIter.nextNeuron()){
@@ -140,7 +140,7 @@ public class FFNN_GD_TrainingStrategy implements TrainingStrategy, Observer {
//Iterate backwards over all remaining layers L = #nrlayers-1 ... 1. layer 0 not done as input layer
LayerIterator layerIter = topology.getLayerIterator(layer);
- Vector deltaList = new Vector(layerIter.getNrNeurons());
+ TypeList deltaList = new TypeList(layerIter.getNrNeurons());
//iterate over all neurons in layer L
for (NeuronConfig li = layerIter.value(); layerIter.hasMore(); layerIter.nextNeuron()){
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/SquaredErrorFunction.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/SquaredErrorFunction.java
index 15e52c2..f518907 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/SquaredErrorFunction.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/generic/trainingstrategies/SquaredErrorFunction.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import net.sourceforge.cilib.neuralnetwork.generic.Weight;
import net.sourceforge.cilib.type.types.Real;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -55,7 +56,7 @@ public class SquaredErrorFunction implements ErrorSignal {
* {@inheritDoc}
*/
public Type computeRecursiveDelta(Type outputFunctionDerivative,
- Vector delta, ArrayList<Weight> w, Type output) {
+ TypeList delta, ArrayList<Weight> w, Type output) {
double sumResult = 0;
for (int i = 0; i < w.size(); i++){
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestErrorINCLearnWithTrainer.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestErrorINCLearnWithTrainer.java
index c495cef..9d6bbba 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestErrorINCLearnWithTrainer.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestErrorINCLearnWithTrainer.java
@@ -38,6 +38,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.FFNN_GD_Tr
import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.SquaredErrorFunction;
import net.sourceforge.cilib.stoppingcondition.MaximumIterations;
import net.sourceforge.cilib.type.types.Real;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -142,7 +143,7 @@ in.add(new Real(1.234));
StandardPattern p = new StandardPattern(in, null);
-Vector result = topo.evaluate(p);
+TypeList result = topo.evaluate(p);
System.out.println("test result f(0.5) = 0.25 --> : " + ((Real) result.get(0)).getReal());
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestFFNNandGDTrainer.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestFFNNandGDTrainer.java
index 4b6dc50..03f0c28 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestFFNNandGDTrainer.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestFFNNandGDTrainer.java
@@ -39,6 +39,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.FFNN_GD_Tr
import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.SquaredErrorFunction;
import net.sourceforge.cilib.stoppingcondition.MaximumIterations;
import net.sourceforge.cilib.type.types.Real;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -133,7 +134,7 @@ public final class TestFFNNandGDTrainer {
StandardPattern p = new StandardPattern(in, null);
- Vector result = topo.evaluate(p);
+ TypeList result = topo.evaluate(p);
System.out.println("test result input = 0.5, output should be 0.25 --> : " + ((Real) result.get(0)).getReal());
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestNeuronAndEvaluateFFNN.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestNeuronAndEvaluateFFNN.java
index 791dca2..d7e9430 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestNeuronAndEvaluateFFNN.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestNeuronAndEvaluateFFNN.java
@@ -33,6 +33,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.ErrorSigna
import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.FFNN_GD_TrainingStrategy;
import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.SquaredErrorFunction;
import net.sourceforge.cilib.type.types.Real;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
@@ -114,7 +115,7 @@ public final class TestNeuronAndEvaluateFFNN {
targt.add(new Real(0.7666));
NNPattern p = new StandardPattern(ins, targt);
- Vector result = new Vector();
+ TypeList result = new TypeList();
ErrorSignal delta = new SquaredErrorFunction();
@@ -171,7 +172,7 @@ public final class TestNeuronAndEvaluateFFNN {
for (int counter = 0; counter < 100; counter++){
- result = new Vector();
+ result = new TypeList();
result = ffnn.evaluate(p);
real = ((Real) result.get(0)).getReal();
diff --git a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestSAILAwithTrainer.java b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestSAILAwithTrainer.java
index 03d654e..06375a2 100644
--- a/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestSAILAwithTrainer.java
+++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/testarea/TestSAILAwithTrainer.java
@@ -38,6 +38,7 @@ import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.FFNN_GD_Tr
import net.sourceforge.cilib.neuralnetwork.generic.trainingstrategies.SquaredErrorFunction;
import net.sourceforge.cilib.stoppingcondition.MaximumIterations;
import net.sourceforge.cilib.type.types.Real;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -142,7 +143,7 @@ in.add(new Real(1.234));
StandardPattern p = new StandardPattern(in, null);
-Vector result = topo.evaluate(p);
+TypeList result = topo.evaluate(p);
System.out.println("test result f(0.5) = 0.25 --> : " + ((Real) result.get(0)).getReal());
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java b/src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java
index be15611..d09a8b3 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java
@@ -19,17 +19,20 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package net.sourceforge.cilib.type.types.container;
/**
- *
+ * Implementing this interface allows an object to be "randomizable".
+ * This implies that the object is able to be set into a state that is random.
* @author gpampara
*/
public interface Randomizable {
+
+ /**
+ * Alter the state of the object in a random manner.
+ * @return {@code true} if successful, {@code false} otherwise.
+ */
public boolean randomize();
+
}
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
index 5398e22..345ce84 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
@@ -44,6 +44,10 @@ public class TypeList extends AbstractList<Type> {
this.components = new ArrayList<Type>();
}
+ public TypeList(int size) {
+ this.components = new ArrayList<Type>();
+ }
+
/**
*
* @param copy
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java b/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
index 582b6d4..ba9acab 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/Vector.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright (C) 2003 - 2008
* Computational Intelligence Research Group (CIRG@UP)
* Department of Computer Science
@@ -22,85 +22,58 @@
package net.sourceforge.cilib.type.types.container;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
-
+import java.util.List;
import net.sourceforge.cilib.container.visitor.Visitor;
import net.sourceforge.cilib.math.VectorMath;
-import net.sourceforge.cilib.type.types.TypeUtil;
import net.sourceforge.cilib.type.types.Numeric;
-import net.sourceforge.cilib.type.types.Real;
import net.sourceforge.cilib.type.types.Resetable;
-import net.sourceforge.cilib.type.types.Type;
/**
- * Concrete implementation of the {@see net.sourceforge.cilib.type.types.Vector}
- * class. Any {@see net.sourceforge.cilib.type.types.Type} object may be contained
- * within this object.
*
- * @author Gary Pampara
- * @author Edwin Peer
+ * @author gpampara
*/
-public class Vector extends AbstractList implements Resetable, VectorMath {
- private static final long serialVersionUID = 136711882764612609L;
- private ArrayList<Type> components;
+public class Vector extends AbstractList<Numeric> implements VectorMath, Resetable, Randomizable {
+ private static final long serialVersionUID = -4853190809813810272L;
+ private List<Numeric> components;
/**
- * Create a default <code>MixedVector</code> with an initial size of 0.
+ * Create a new empty {@code Vector}.
*/
public Vector() {
- components = new ArrayList<Type>();
+ this.components = new ArrayList<Numeric>();
}
-
/**
- * Create a <code>MixedVector</code> with a default size specified by <code>dimension</code>.
- *
- * @param dimension The size to initialise the <code>MixedVector</code>
+ * Create a new empty {@code Vector} with {@code size} as the initial
+ * capacity.
+ * @param size The initial capacity.
*/
- public Vector(int dimension) {
- components = new ArrayList<Type>(dimension);
- components.ensureCapacity(dimension);
+ public Vector(int size) {
+ this.components =...
[truncated message content] |
|
From: Gary P. <gpa...@gm...> - 2009-06-01 08:07:45
|
Changed the manner in which the Type Vector works. Vectors are generally
associated with mathmatical operations and as a result, the Vector has
now been made a specialization of AbstractList<E>.
For general object containment in a list type structure, please use the
TypeList class which has been added.
---
.../ClonedPopulationInitialisationStrategy.java | 2 +-
.../cilib/bioinf/rnaprediction/RNAInitialiser.java | 5 +-
.../cilib/bioinf/rnaprediction/RNAParticle.java | 7 +-
.../bioinf/rnaprediction/RNAVelocityUpdate.java | 3 +-
.../cilib/clustering/kmeans/KMeans.java | 2 +-
.../continuous/dynamic/moo/fda1/FDA1_f2.java | 2 +-
.../continuous/dynamic/moo/fda1/FDA1_h.java | 4 +-
.../continuous/dynamic/moo/fda2/FDA2_f2.java | 2 +-
.../continuous/dynamic/moo/fda2/FDA2_h.java | 6 +-
.../discrete/LongestCommonSubsequence.java | 4 +-
src/main/java/net/sourceforge/cilib/hs/HS.java | 7 +-
.../java/net/sourceforge/cilib/math/StatUtils.java | 6 +-
.../net/sourceforge/cilib/math/VectorMath.java | 29 ++--
.../cilib/type/types/container/AbstractList.java | 90 ++--------
.../cilib/type/types/container/Randomizable.java | 35 ++++
.../cilib/type/types/container/TypeList.java | 198 ++++++++++++++++++++
.../cilib/type/types/container/VectorTest.java | 106 ++++-------
17 files changed, 325 insertions(+), 183 deletions(-)
create mode 100644 src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java
create mode 100644 src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
diff --git a/src/main/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategy.java b/src/main/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategy.java
index 7996f4d..ff64e98 100644
--- a/src/main/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/algorithm/initialisation/ClonedPopulationInitialisationStrategy.java
@@ -67,7 +67,7 @@ public class ClonedPopulationInitialisationStrategy extends PopulationInitialisa
* @param problem The <tt>Problem</tt> to use in the initialisation of the topology.
* @throws InitialisationException if the initialisation cannot take place.
*/
- @SuppressWarnings("unchecked")
+ @Override
public void initialise(Topology topology, OptimisationProblem problem) {
if (problem == null)
throw new InitialisationException("No problem has been specified");
diff --git a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAInitialiser.java b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAInitialiser.java
index ff992fa..ce7a7cd 100644
--- a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAInitialiser.java
+++ b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAInitialiser.java
@@ -24,8 +24,7 @@ package net.sourceforge.cilib.bioinf.rnaprediction;
import net.sourceforge.cilib.math.random.generator.MersenneTwister;
import net.sourceforge.cilib.problem.OptimisationProblem;
import net.sourceforge.cilib.type.types.Type;
-import net.sourceforge.cilib.type.types.container.Vector;
-
+import net.sourceforge.cilib.type.types.container.TypeList;
/**
* @author mneethling
@@ -81,7 +80,7 @@ public class RNAInitialiser {
* @return The initial velocity.
*/
public Type getInitialVelocity(OptimisationProblem problem) {
- Vector mv = new Vector();
+ TypeList mv = new TypeList();
mv.add(new RNAConformation());
mv.add(new RNAConformation());
return mv;
diff --git a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAParticle.java b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAParticle.java
index 6a2d592..2483428 100644
--- a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAParticle.java
+++ b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAParticle.java
@@ -28,6 +28,7 @@ import net.sourceforge.cilib.problem.InferiorFitness;
import net.sourceforge.cilib.problem.OptimisationProblem;
import net.sourceforge.cilib.pso.particle.AbstractParticle;
import net.sourceforge.cilib.type.types.Type;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -40,7 +41,7 @@ public class RNAParticle extends AbstractParticle {
private RNAConformation position;
private RNAConformation bestPosition;
- private Vector velocity;
+ private TypeList velocity;
private Fitness bestFitness;
@@ -54,7 +55,7 @@ public class RNAParticle extends AbstractParticle {
public RNAParticle() {
position = new RNAConformation();
bestPosition = new RNAConformation();
- velocity = new Vector();
+ velocity = new TypeList();
}
/**
@@ -169,7 +170,7 @@ public class RNAParticle extends AbstractParticle {
position = (RNAConformation) i.getInitialPosition(problem);
bestPosition.clear();
bestPosition.addAll(position);
- velocity = (Vector) i.getInitialVelocity(problem);
+ velocity = (TypeList) i.getInitialVelocity(problem);
bestFitness = InferiorFitness.instance();
neighbourhoodBest = this;
//fitnessCalc = new SimpleRNAFitness();
diff --git a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAVelocityUpdate.java b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAVelocityUpdate.java
index da72fa7..230b39c 100644
--- a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAVelocityUpdate.java
+++ b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAVelocityUpdate.java
@@ -27,6 +27,7 @@ import java.util.Random;
import net.sourceforge.cilib.entity.Particle;
import net.sourceforge.cilib.math.random.generator.KnuthSubtractive;
import net.sourceforge.cilib.pso.velocityupdatestrategies.VelocityUpdateStrategy;
+import net.sourceforge.cilib.type.types.container.TypeList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -83,7 +84,7 @@ public class RNAVelocityUpdate implements VelocityUpdateStrategy {
*/
public void updateVelocity(Particle particle) {
- Vector velocity = (Vector) particle.getVelocity();
+ TypeList velocity = (TypeList) particle.getVelocity();
RNAConformation openStems = (RNAConformation) velocity.get(0);
RNAConformation closeStems = (RNAConformation) velocity.get(1);
diff --git a/src/main/java/net/sourceforge/cilib/clustering/kmeans/KMeans.java b/src/main/java/net/sourceforge/cilib/clustering/kmeans/KMeans.java
index 178ff47..beba140 100644
--- a/src/main/java/net/sourceforge/cilib/clustering/kmeans/KMeans.java
+++ b/src/main/java/net/sourceforge/cilib/clustering/kmeans/KMeans.java
@@ -155,7 +155,7 @@ public class KMeans extends SingularAlgorithm {
Vector tmp = centroidsInitialisationStrategy.initialise(helper.getClusteringProblem(), helper.getClusterableDataSet());
// this first centroid will do
- return tmp.subVector(0, centroid.getDimension() - 1);
+ return tmp.subList(0, centroid.getDimension() - 1);
}
/**
diff --git a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_f2.java b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_f2.java
index 2ef5e2c..afbfa72 100755
--- a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_f2.java
+++ b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_f2.java
@@ -146,7 +146,7 @@ public class FDA1_f2 extends ContinuousFunction {
*/
public double evaluate(Vector x) {
- Vector y = x.subVector(1, x.getDimension()-1);
+ Vector y = x.subList(1, x.getDimension()-1);
double g = this.fda1_g.evaluate(y);
double h = this.fda1_h.evaluate(x);
diff --git a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_h.java b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_h.java
index fb31ae1..b63b0c2 100755
--- a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_h.java
+++ b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_h.java
@@ -147,9 +147,9 @@ public class FDA1_h extends ContinuousFunction {
public double evaluate(Vector x) {
//only the first element
- Vector y = x.subVector(0, 0);
+ Vector y = x.subList(0, 0);
//all the elements except the first element
- Vector z = x.subVector(1, x.getDimension()-1);
+ Vector z = x.subList(1, x.getDimension()-1);
//evaluate the fda1_g function
double g = this.fda1_g.evaluate(z);
//evaluate the fda1_f1 function
diff --git a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_f2.java b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_f2.java
index 50b944a..2e5ecdd 100755
--- a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_f2.java
+++ b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_f2.java
@@ -147,7 +147,7 @@ public class FDA2_f2 extends ContinuousFunction {
public double evaluate(Vector x) {
Vector y = x;
if (x.getDimension() > 1)
- y = x.subVector(1, fda2_g.getDimension()); //-1
+ y = x.subList(1, fda2_g.getDimension()); //-1
double g = this.fda2_g.evaluate(y);
double h = this.fda2_h.evaluate(x);
diff --git a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_h.java b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_h.java
index 5f45fa2..7836cba 100755
--- a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_h.java
+++ b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda2/FDA2_h.java
@@ -217,9 +217,9 @@ public class FDA2_h extends ContinuousFunction {
Vector xII = x;
Vector xIII = x;
if (x.getDimension() > 1) {
- xI = x.subVector(0, 0);
- xII = x.subVector(1, 15);
- xIII = x.subVector(16, x.getDimension()-1);
+ xI = x.subList(0, 0);
+ xII = x.subList(1, 15);
+ xIII = x.subList(16, x.getDimension()-1);
}
double f = this.fda2_f.evaluate(xI);
diff --git a/src/main/java/net/sourceforge/cilib/functions/discrete/LongestCommonSubsequence.java b/src/main/java/net/sourceforge/cilib/functions/discrete/LongestCommonSubsequence.java
index 90e132b..34b9494 100644
--- a/src/main/java/net/sourceforge/cilib/functions/discrete/LongestCommonSubsequence.java
+++ b/src/main/java/net/sourceforge/cilib/functions/discrete/LongestCommonSubsequence.java
@@ -99,10 +99,8 @@ public class LongestCommonSubsequence extends DiscreteFunction {
*/
private int length(Vector x) {
int count = 0;
- Iterator<Type> i = x.iterator();
- while (i.hasNext()) {
- Numeric n = (Numeric) i.next();
+ for (Numeric n : x) {
if (n.getBit())
count++;
}
diff --git a/src/main/java/net/sourceforge/cilib/hs/HS.java b/src/main/java/net/sourceforge/cilib/hs/HS.java
index 4d40e29..38bb51d 100644
--- a/src/main/java/net/sourceforge/cilib/hs/HS.java
+++ b/src/main/java/net/sourceforge/cilib/hs/HS.java
@@ -33,7 +33,6 @@ import net.sourceforge.cilib.math.random.RandomNumber;
import net.sourceforge.cilib.problem.OptimisationProblem;
import net.sourceforge.cilib.problem.OptimisationSolution;
import net.sourceforge.cilib.type.types.Real;
-import net.sourceforge.cilib.type.types.container.AbstractList;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -197,7 +196,7 @@ public class HS extends SingularAlgorithm {
// Real newHarmonyValue;
for (int i = 0; i < problem.getDomain().getDimension(); ++i) {
if (random1.getUniform() < harmonyMemoryConsideringRate.getParameter()) {
- Harmony selectedHarmony = (Harmony) this.harmonyMemory.get((int) random2.getUniform(0, harmonyMemory.size()-1));
+ Harmony selectedHarmony = this.harmonyMemory.get((int) random2.getUniform(0, harmonyMemory.size()-1));
Vector selectedHarmonyContents = (Vector) selectedHarmony.getCandidateSolution();
Real newHarmonyValue = (Real) selectedHarmonyContents.get(i).getClone();
if (random1.getUniform() < pitchAdjustingRate.getParameter()) {
@@ -209,8 +208,8 @@ public class HS extends SingularAlgorithm {
newHarmonyVector.set(i, newHarmonyValue);
}
else {
- double upper = ((AbstractList) problem.getDomain().getBuiltRepresenation()).getNumeric(i).getBounds().getUpperBound();
- double lower = ((AbstractList) problem.getDomain().getBuiltRepresenation()).getNumeric(i).getBounds().getLowerBound();
+ double upper = ((Vector) problem.getDomain().getBuiltRepresenation()).get(i).getBounds().getUpperBound();
+ double lower = ((Vector) problem.getDomain().getBuiltRepresenation()).get(i).getBounds().getLowerBound();
newHarmonyVector.set(i, new Real(random3.getUniform(lower, upper)));
}
}
diff --git a/src/main/java/net/sourceforge/cilib/math/StatUtils.java b/src/main/java/net/sourceforge/cilib/math/StatUtils.java
index fa84e36..792211c 100644
--- a/src/main/java/net/sourceforge/cilib/math/StatUtils.java
+++ b/src/main/java/net/sourceforge/cilib/math/StatUtils.java
@@ -24,6 +24,7 @@ package net.sourceforge.cilib.math;
import java.util.Collection;
import net.sourceforge.cilib.problem.dataset.ClusterableDataSet.Pattern;
+import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.container.Vector;
/**
@@ -86,7 +87,7 @@ public final class StatUtils {
* Calculates the variance of the given set/cluster/collection of @{link Pattern}s.
*
* This is illustrated in Equation 4.c of:<br/>
- * @InProceedings{ 657864, author = "Maria Halkidi and Michalis Vazirgiannis", title =
+ * {@literal @}InProceedings{ 657864, author = "Maria Halkidi and Michalis Vazirgiannis", title =
* "Clustering Validity Assessment: Finding the Optimal Partitioning of a Data
* Set", booktitle = "Proceedings of the IEEE International Conference on Data
* Mining", year = "2001", isbn = "0-7695-1119-8", pages = "187--194", publisher =
@@ -104,7 +105,8 @@ public final class StatUtils {
variance.reset(); // initialize the variance to be all zeroes
for (Pattern pattern : set) {
Vector diffSquare = pattern.data.subtract(center);
- diffSquare = diffSquare.multiply(diffSquare);
+ for (Numeric numeric : diffSquare)
+ numeric.setReal(numeric.getReal()*numeric.getReal());
variance = variance.plus(diffSquare);
}
return variance.norm() / set.size();
diff --git a/src/main/java/net/sourceforge/cilib/math/VectorMath.java b/src/main/java/net/sourceforge/cilib/math/VectorMath.java
index 46efeae..e62bd6d 100644
--- a/src/main/java/net/sourceforge/cilib/math/VectorMath.java
+++ b/src/main/java/net/sourceforge/cilib/math/VectorMath.java
@@ -31,35 +31,34 @@ import net.sourceforge.cilib.type.types.container.Vector;
public interface VectorMath {
/**
- * Adding this {@see net.sourceforge.cilib.type.types.Vector} to another
- * will result in a resultant {@see net.sourceforge.cilib.type.types.Vector}.
+ * Adding this {@code Vector} to another will result in a resultant {@code Vector}.
*
- * @param vector The {@see net.sourceforge.cilib.type.types.Vector} to add to the current one
- * @return The resultant {@see net.sourceforge.cilib.type.types.Vector}
+ * @param vector The {@code Vector} to add to the current one
+ * @return The resultant {@code Vector}
*/
public Vector plus(Vector vector);
/**
- *
- * @param vector
- * @return
+ * Subtract the provided {@code Vector} from the current {@code Vector}.
+ * The result of the subtraction operation is a new {@code Vector} instance,
+ * maintaining the immutability of the operation.
+ * @param vector The {@code Vector} to subtract.
+ * @return A new {@code Vector} instance representing the result of the operation.
*/
public Vector subtract(Vector vector);
/**
- *
- * @param vector
- * @return
+ * Divide the elements of the current {@code Vector} by the provided {@code scalar}.
+ * @param scalar The value to divide all elements within the {@code Vector} by.
+ * @return A new {@code Vector} instance containing the result of the operator.
*/
- public Vector divide(Vector vector);
public Vector divide(double scalar);
/**
- *
- * @param vector
- * @return
+ * Multiply a {@code scalar} with each component in the {@code Vector}.
+ * @param scalar The scalar to multiply in.
+ * @return A new {@code Vector} instance containing the result of the operator.
*/
- public Vector multiply(Vector vector);
public Vector multiply(double scalar);
/**
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java b/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java
index a53e2b4..50fc7b6 100644
--- a/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/AbstractList.java
@@ -21,7 +21,6 @@
*/
package net.sourceforge.cilib.type.types.container;
-import net.sourceforge.cilib.type.types.Numeric;
import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.TypeUtil;
@@ -30,13 +29,13 @@ import net.sourceforge.cilib.type.types.TypeUtil;
*
* @author Gary Pampara
*/
-public abstract class AbstractList implements StructuredType<Type> {
+public abstract class AbstractList<E extends Type> implements StructuredType<E> {
private static final long serialVersionUID = -7855489699409219241L;
/**
* {@inheritDoc}
*/
- public abstract AbstractList getClone();
+ public abstract AbstractList<E> getClone();
/**
* {@inheritDoc}
@@ -53,43 +52,43 @@ public abstract class AbstractList implements StructuredType<Type> {
* @param index The index to inspect to return.
* @return The {@linkplain Type} found at <code>index</code>.
*/
- public abstract Type get(int index);
+ public abstract E get(int index);
/**
* Set the {@linkplain Type} at the index <code>index</code>.
* @param index The index to set.
* @param value The value to set.
*/
- public abstract void set(int index, Type value);
+ public abstract void set(int index, E value);
/**
* Insert the provided {@linkplain Type} at the specified {@code index}.
* @param index The index where to insert the {@linkplain Type}.
* @param value The value to set.
*/
- public abstract void insert(int index, Type value);
+ public abstract void insert(int index, E value);
/**
* Add the provided {@linkplain Type} to the end of the current list.
* @param value The {@linkplain Type} to add.
*/
- public void append(Type value) {
+ public void append(E value) {
int position = TypeUtil.getDimension(this);
insert(position, value);
}
/**
* Add the provided {@linkplain AbstractList} to the end of the current list.
- * @param vector The object to add.
+ * @param list The object to add.
* @return <code>true</code> if the operation was successful, <code>false</code> otherwise.
*/
- public abstract boolean append(AbstractList vector);
+ public abstract boolean append(AbstractList<E> list);
/**
* Prepend the provided {@linkplain Type} to the from of this list.
* @param value The {@linkplain Type} to prepend.
*/
- public void prepend(Type value) {
+ public void prepend(E value) {
insert(0, value);
}
@@ -98,56 +97,7 @@ public abstract class AbstractList implements StructuredType<Type> {
* @param vector The object to add.
* @return <code>true</code> if the operation was successful, <code>false</code> otherwise.
*/
- public abstract boolean prepend(AbstractList vector);
-
- /**
- * Get the {@linkplain Numeric} at the given <code>index</code>.
- * @param index The index of the desired {@linkplain Numeric}.
- * @return The {@linkplain Numeric} at position <code>index</code>.
- */
- public abstract Numeric getNumeric(int index);
-
- /**
- * Get the bit-value of the {@linkplain Type} at the given <code>index</code>.
- * @param index The index of the desired {@linkplain Numeric}.
- * @return The bit-value at position <code>index</code>.
- */
- public abstract boolean getBit(int index);
-
- /**
- * Set the value of the {@linkplain net.sourceforge.cilib.type.types.Bit} located at position <code>index</code>.
- * @param index The index of the bit to set the value.
- * @param value The value of the bit to set.
- */
- public abstract void setBit(int index, boolean value);
-
- /**
- * Get the value specified at {@code index} as an {@code int}.
- * @param index The index of the value to get.
- * @return The value at {@code index}.
- */
- public abstract int getInt(int index);
-
- /**
- * Set the value at {@code index} to {@code value}.
- * @param index The index of the value to set.
- * @param value The value to set.s
- */
- public abstract void setInt(int index, int value);
-
- /**
- * Get the value at {@code index} as a {@code double}.
- * @param index The index of the value to get.
- * @return The value as a {@code double}.
- */
- public abstract double getReal(int index);
-
- /**
- * Set the value at {@code index} to {@code value}.
- * @param index The index of the value to set.
- * @param value The value to set.
- */
- public abstract void setReal(int index, double value);
+ public abstract boolean prepend(AbstractList<E> list);
/**
* Create an <code>Object []</code> from this <code>Vector</code>.
@@ -156,13 +106,6 @@ public abstract class AbstractList implements StructuredType<Type> {
public abstract Object[] toArray();
/**
- * Get the {@linkplain Type} instance at the given index.
- * @param index The position of the {@linkplain Type} to return.
- * @return The {@linkplain Type} at index {@literal index}.
- */
- protected abstract Type getType(int index);
-
- /**
* Get the representation of this <tt>Vector</tt> object in the form expressed by the domain notation.
* This method calls the <code>getRepresentation</code> method for each element in the <tt>Vector</tt>.
* This method is also a bit clever in the sense that it will try to detect elements with the same
@@ -211,7 +154,7 @@ public abstract class AbstractList implements StructuredType<Type> {
* @param toIndex The last index to end the sub-vector at.
* @return The created sub-vector instance.
*/
- public abstract AbstractList subVector(int fromIndex, int toIndex);
+ public abstract AbstractList<E> subList(int fromIndex, int toIndex);
/**
* Create a new (cloned) <tt>Vector</tt> consisting of <tt>rhs</tt> that has been appended to
@@ -223,8 +166,8 @@ public abstract class AbstractList implements StructuredType<Type> {
* @return A new <tt>Vector</tt> consisting of the concatenation of <tt>lhs</tt> and
* <tt>rhs</tt>.
*/
- public static AbstractList append(AbstractList lhs, AbstractList rhs) {
- AbstractList cat = lhs.getClone();
+ public static <T extends Type> AbstractList<T> append(AbstractList<T> lhs, AbstractList<T> rhs) {
+ AbstractList<T> cat = lhs.getClone();
cat.append(rhs.getClone());
return cat;
}
@@ -299,11 +242,4 @@ public abstract class AbstractList implements StructuredType<Type> {
return toString('[', ']', delimiter);
}
- /**
- * Initialise the {@linkplain Type} to contain <code>size</code> elements all of the type
- * <code>element</code>.
- * @param size The required size
- * @param element The {@linkplain Type} to use to initialise the {@linkplain AbstractList}.
- */
- public abstract void initialise(int size, Type element);
}
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java b/src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java
new file mode 100644
index 0000000..be15611
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java
@@ -0,0 +1,35 @@
+/**
+ * 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
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.sourceforge.cilib.type.types.container;
+
+/**
+ *
+ * @author gpampara
+ */
+public interface Randomizable {
+ public boolean randomize();
+}
diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
new file mode 100644
index 0000000..5398e22
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java
@@ -0,0 +1,198 @@
+/*
+ * 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.type.types.container;
+
+import java.util.ArrayList;
+
+import java.util.Iterator;
+import java.util.List;
+import net.sourceforge.cilib.container.visitor.Visitor;
+import net.sourceforge.cilib.type.types.Type;
+
+/**
+ * Concrete implementation of the {@see net.sourceforge.cilib.type.types.Vector}
+ * class. Any {@see net.sourceforge.cilib.type.types.Type} object may be contained
+ * within this object.
+ *
+ * @author Gary Pampara
+ * @author Edwin Peer
+ */
+public class TypeList extends AbstractList<Type> {
+ private static final long serialVersionUID = 136711882764612609L;
+ private List<Type> components;
+
+ public TypeList() {
+ this.components = new ArrayList<Type>();
+ }
+
+ /**
+ *
+ * @param copy
+ */
+ public TypeList(TypeList copy) {
+ this.components = new ArrayList<Type>(copy.components.size());
+
+ for (Type type : copy.components)
+ this.components.add(type.getClone());
+ }
+
+ @Override
+ public TypeList getClone() {
+ return new TypeList(this);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+
+ if ((other == null) || (this.getClass() != other.getClass()))
+ return false;
+
+ TypeList otherList = (TypeList) other;
+ return this.components.equals(otherList.components);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode() {
+ int hash = 7;
+ hash = 31 * hash + (this.components == null ? 0 : this.components.hashCode());
+ return hash;
+ }
+
+ @Override
+ public Type get(int index) {
+ return this.components.get(index);
+ }
+
+ @Override
+ public void set(int index, Type value) {
+ this.components.set(index, value);
+ }
+
+ @Override
+ public void insert(int index, Type value) {
+ this.components.add(index, value);
+ }
+
+ @Override
+ public boolean append(AbstractList<Type> list) {
+ for (Type type : list)
+ this.components.add(type);
+
+ return true;
+ }
+
+ @Override
+ public boolean prepend(AbstractList<Type> list) {
+ for (int i = list.size()-1; i >= 0; i--)
+ this.components.add(0, list.get(i));
+
+ return true;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return this.components.toArray();
+ }
+
+ @Override
+ public TypeList subList(int fromIndex, int toIndex) {
+ List<Type> result = this.components.subList(fromIndex, toIndex);
+ TypeList sublist = new TypeList();
+
+ for (Type type : result)
+ sublist.add(type);
+
+ return sublist;
+ }
+
+ @Override
+ public boolean add(Type element) {
+ return this.components.add(element);
+ }
+
+ @Override
+ public boolean addAll(StructuredType<? extends Type> structure) {
+ for (Type type : structure)
+ this.components.add(type);
+
+ return true;
+ }
+
+ @Override
+ public void clear() {
+ this.components.clear();
+ }
+
+ @Override
+ public boolean contains(Type element) {
+ return this.components.contains(element);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.components.isEmpty();
+ }
+
+ @Override
+ public Iterator<Type> iterator() {
+ return this.components.iterator();
+ }
+
+ @Override
+ public boolean remove(Type element) {
+ return this.components.remove(element);
+ }
+
+ @Override
+ public Type remove(int index) {
+ return this.components.remove(index);
+ }
+
+ @Override
+ public boolean removeAll(StructuredType<Type> structure) {
+ for (Type type : structure)
+ this.components.remove(type);
+
+ return true;
+ }
+
+ @Override
+ public int size() {
+ return this.components.size();
+ }
+
+ @Override
+ public void accept(Visitor<Type> visitor) {
+ for (Type type : this.components)
+ if (!visitor.isDone())
+ visitor.visit(type);
+ }
+
+}
diff --git a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
index bb49872..914f37f 100644
--- a/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
+++ b/src/test/java/net/sourceforge/cilib/type/types/container/VectorTest.java
@@ -105,45 +105,19 @@ public class VectorTest {
}
@Test
- public void testNonNumericGet() {
- Vector m = new Vector();
- Set<Real> realSet = new Set<Real>();
-
- m.add(realSet);
-
- assertFalse(m.get(0) instanceof Numeric);
- assertSame(realSet, m.get(0));
-
- assertNotSame(m.get(0), vector.get(0));
- }
-
- @Test
public void testNumericSet() {
assertEquals(1.0, vector.getReal(0), 0.0);
vector.setReal(0, 99.9);
assertEquals(99.9, vector.getReal(0), 0.0);
vector.setInt(0, 2);
- assertEquals((int) 2, vector.getInt(0), 0.0);
+ assertEquals(2, vector.getInt(0), 0.0);
vector.setReal(0, 1.0);
assertEquals(1.0, vector.getReal(0), 0.0);
}
@Test
- public void testNonNumericSet() {
- Vector m = new Vector();
- Set<Object> s = new Set<Object>();
- Vector v = new Vector();
-
- m.add(s);
- m.add(v);
-
- assertSame(s, m.get(0));
- assertSame(v, m.get(1));
- }
-
- @Test
public void testDimension() {
assertFalse(vector.getDimension() == 3);
assertTrue(vector.getDimension() == 4);
@@ -409,9 +383,9 @@ public class VectorTest {
assertNotSame(sum, b);
for(int i = 0; i < 10; i++) {
- assertNotSame(a.getType(i), b.getType(i));
- assertNotSame(sum.getType(i), a.getType(i));
- assertNotSame(sum.getType(i), b.getType(i));
+ assertNotSame(a.get(i), b.get(i));
+ assertNotSame(sum.get(i), a.get(i));
+ assertNotSame(sum.get(i), b.get(i));
assertEquals(a.getReal(i), Integer.valueOf(i).doubleValue(), 0.0);
assertEquals(b.getReal(i), Double.valueOf(9.0 - i), 0.0);
@@ -453,16 +427,16 @@ public class VectorTest {
assertNotSame(difference, b);
for(int i = 0; i < 10; i++) {
- assertNotNull(a.getType(i));
- assertNotNull(b.getType(i));
- assertNotNull(difference.getType(i));
- assertNotSame(a.getType(i), b.getType(i));
- assertNotSame(difference.getType(i), a.getType(i));
- assertNotSame(difference.getType(i), b.getType(i));
+ assertNotNull(a.get(i));
+ assertNotNull(b.get(i));
+ assertNotNull(difference.get(i));
+ assertNotSame(a.get(i), b.get(i));
+ assertNotSame(difference.get(i), a.get(i));
+ assertNotSame(difference.get(i), b.get(i));
assertEquals(a.getReal(i), (double)i, 0.0);
- assertEquals(b.getReal(i), (double)(9.0 - i), 0.0);
- assertEquals(difference.getReal(i), (double)(i - (9.0 - i)), 0.0);
+ assertEquals(b.getReal(i), (9.0 - i), 0.0);
+ assertEquals(difference.getReal(i), (i - (9.0 - i)), 0.0);
}
}
@@ -505,7 +479,7 @@ public class VectorTest {
b.prepend(new Real(i));
b.prepend(new Real(0));
- ((Numeric)b.getType(0)).setReal(10);
+ b.get(0).setReal(10);
Vector divided = a.divide(b);
assertNotNull(a);
@@ -516,16 +490,16 @@ public class VectorTest {
assertNotSame(divided, b);
for(int i = 0; i < 10; i++) {
- assertNotNull(a.getType(i));
- assertNotNull(b.getType(i));
- assertNotNull(divided.getType(i));
- assertNotSame(a.getType(i), b.getType(i));
- assertNotSame(divided.getType(i), a.getType(i));
- assertNotSame(divided.getType(i), b.getType(i));
-
- assertEquals(a.getReal(i), (double)(i + 1), 0.0);
- assertEquals(b.getReal(i), (double)(10.0 - i), 0.0);
- assertEquals(divided.getReal(i), (double)((i + 1) / (10.0 - i)), 0.0);
+ assertNotNull(a.get(i));
+ assertNotNull(b.get(i));
+ assertNotNull(divided.get(i));
+ assertNotSame(a.get(i), b.get(i));
+ assertNotSame(divided.get(i), a.get(i));
+ assertNotSame(divided.get(i), b.get(i));
+
+ assertEquals(a.getReal(i), (i + 1.0), 0.0);
+ assertEquals(b.getReal(i), (10.0 - i), 0.0);
+ assertEquals(divided.getReal(i), ((i + 1) / (10.0 - i)), 0.0);
}
}
@@ -553,12 +527,12 @@ public class VectorTest {
assertNotSame(divided, a);
for(int i = 0; i < 10; i++) {
- assertNotNull(a.getType(i));
- assertNotNull(divided.getType(i));
- assertNotSame(divided.getType(i), a.getType(i));
+ assertNotNull(a.get(i));
+ assertNotNull(divided.get(i));
+ assertNotSame(divided.get(i), a.get(i));
- assertEquals(a.getReal(i), (double)i, 0.0);
- assertEquals(divided.getReal(i), (double)(i / 3.0), 0.000000001);
+ assertEquals(a.getReal(i), (double) i, 0.0);
+ assertEquals(divided.getReal(i), (i / 3.0), 0.000000001);
}
}
@@ -596,16 +570,16 @@ public class VectorTest {
assertNotSame(product, b);
for(int i = 0; i < 10; i++) {
- assertNotNull(a.getType(i));
- assertNotNull(b.getType(i));
- assertNotNull(product.getType(i));
- assertNotSame(a.getType(i), b.getType(i));
- assertNotSame(product.getType(i), a.getType(i));
- assertNotSame(product.getType(i), b.getType(i));
+ assertNotNull(a.get(i));
+ assertNotNull(b.get(i));
+ assertNotNull(product.get(i));
+ assertNotSame(a.get(i), b.get(i));
+ assertNotSame(product.get(i), a.get(i));
+ assertNotSame(product.get(i), b.get(i));
assertEquals(a.getReal(i), (double)i, 0.0);
- assertEquals(b.getReal(i), (double)(9.0 - i), 0.0);
- assertEquals(product.getReal(i), (double)(i * (9.0 - i)), 0.0);
+ assertEquals(b.getReal(i), (9.0 - i), 0.0);
+ assertEquals(product.getReal(i), (i * (9.0 - i)), 0.0);
}
}
@@ -623,12 +597,12 @@ public class VectorTest {
assertNotSame(product, a);
for(int i = 0; i < 10; i++) {
- assertNotNull(a.getType(i));
- assertNotNull(product.getType(i));
- assertNotSame(product.getType(i), a.getType(i));
+ assertNotNull(a.get(i));
+ assertNotNull(product.get(i));
+ assertNotSame(product.get(i), a.get(i));
assertEquals(a.getReal(i), (double)i, 0.0);
- assertEquals(product.getReal(i), (double)(i * 3.0), 0.0);
+ assertEquals(product.getReal(i), (i * 3.0), 0.0);
}
}
--
1.6.2.3
|
|
From: Gary P. <gpa...@gm...> - 2009-06-01 08:07:42
|
The Vector container class was overloaded with far too much responsibility. The decision was made to split the classes and have the Vector class be responsible for mathematical vector operations and that the Vector should be specialized for Numeric types. A companion container class "TypeList" has been added to perform the remainder of the fucntions that the Vector was performing. Gary Pampara (4): Vector for Numeric types. Modified Neural Networks to use Type container. Remainder of classes for Vector changes. Corrected index issue with subList(). pom.xml | 2 +- .../ClonedPopulationInitialisationStrategy.java | 2 +- .../cilib/bioinf/rnaprediction/RNAInitialiser.java | 5 +- .../cilib/bioinf/rnaprediction/RNAParticle.java | 7 +- .../bioinf/rnaprediction/RNAVelocityUpdate.java | 3 +- .../cilib/clustering/kmeans/KMeans.java | 2 +- .../cilib/cooperative/CooperativeEntity.java | 4 +- .../continuous/dynamic/moo/fda1/FDA1_f2.java | 2 +- .../continuous/dynamic/moo/fda1/FDA1_h.java | 4 +- .../continuous/dynamic/moo/fda2/FDA2_f2.java | 2 +- .../continuous/dynamic/moo/fda2/FDA2_h.java | 6 +- .../discrete/LongestCommonSubsequence.java | 4 +- .../sourceforge/cilib/games/agent/NeuralAgent.java | 3 +- .../neural/NeuralOutputInterpretationStrategy.java | 5 +- .../state/evaluation/NeuralStateEvaluator.java | 6 +- .../predatorprey/NeuralPredatorOutputStrategy.java | 13 +- .../predatorprey/NeuralPreyOutputStrategy.java | 15 +- .../cilib/games/items/GridLocation.java | 11 +- .../measurement/RecordItemLocationMeasure.java | 7 +- src/main/java/net/sourceforge/cilib/hs/HS.java | 7 +- .../java/net/sourceforge/cilib/math/StatUtils.java | 6 +- .../net/sourceforge/cilib/math/VectorMath.java | 29 +- .../measurement/multiple/CompositeMeasurement.java | 4 +- .../measurement/multiple/ParetoOptimalFront.java | 6 +- .../measurement/multiple/ParetoOptimalSet.java | 3 +- .../neuralnetwork/basicFFNN/FFNNTopology.java | 5 +- .../neuralnetwork/basicFFNN/TrainAndTestNN.java | 3 +- .../foundation/EvaluationMediator.java | 5 +- .../cilib/neuralnetwork/foundation/NNError.java | 4 +- .../foundation/NeuralNetworkProblem.java | 3 +- .../foundation/NeuralNetworkTopology.java | 3 +- .../BatchTrainingSetEpochStrategy.java | 4 +- ...chasticTrainingGeneralisationEpochStrategy.java | 5 +- .../foundation/measurements/AreaUnderROC.java | 6 +- .../foundation/measurements/NNOutput.java | 4 +- .../neuralnetwork/generic/GenericTopology.java | 3 +- .../generic/LayeredGenericTopology.java | 7 +- .../DynamicPatternSelectionData.java | 4 +- .../errorfunctions/ClassificationErrorReal.java | 6 +- .../generic/errorfunctions/MSEErrorFunction.java | 4 +- .../FFNNEvaluationMediator.java | 9 +- .../SAILAEvaluationMediator.java | 22 +- .../topologyvisitors/WeightExtractingVisitor.java | 3 +- .../generic/trainingstrategies/ErrorSignal.java | 4 +- .../FFNN_GD_TrainingStrategy.java | 8 +- .../trainingstrategies/SquaredErrorFunction.java | 3 +- .../testarea/TestErrorINCLearnWithTrainer.java | 3 +- .../testarea/TestFFNNandGDTrainer.java | 3 +- .../testarea/TestNeuronAndEvaluateFFNN.java | 5 +- .../testarea/TestSAILAwithTrainer.java | 3 +- .../problem/changestrategy/ChangeStrategy.java | 6 +- .../problem/dataset/StringDataSetBuilder.java | 3 - .../pso/dynamic/ChargedVelocityUpdateStrategy.java | 3 +- .../net/sourceforge/cilib/type/DomainBuilder.java | 38 +- .../net/sourceforge/cilib/type/types/Type.java | 29 +- .../cilib/type/types/container/AbstractList.java | 106 +--- .../cilib/type/types/container/Randomizable.java | 38 + .../cilib/type/types/container/TypeList.java | 268 +++++++ .../cilib/type/types/container/Vector.java | 726 +++++++------------- .../sourceforge/cilib/util/ClusteringUtils.java | 3 +- .../net/sourceforge/cilib/util/VectorUtils.java | 24 +- src/site/site.xml | 22 +- .../sourceforge/cilib/entity/IndividualTest.java | 2 - .../measurement/multiple/MultipleFitnessTest.java | 22 +- .../multiple/MultipleSolutionsTest.java | 6 +- .../single/BestParticlePositionTest.java | 8 +- .../cilib/measurement/single/DiameterTest.java | 16 +- .../measurement/single/ParticlePositionsTest.java | 6 +- .../cilib/measurement/single/SolutionTest.java | 6 +- .../sourceforge/cilib/type/DomainParserTest.java | 71 +- .../cilib/type/StringBasedDomainRegistryTest.java | 8 +- .../cilib/type/types/container/TypeListTest.java | 48 ++ .../cilib/type/types/container/VectorTest.java | 189 +----- .../cilib/util/ClusteringUtilsTest.java | 12 +- .../sourceforge/cilib/util/VectorUtilsTest.java | 13 - .../net/sourceforge/cilib/xml/XMLFileTest.java | 11 +- 76 files changed, 999 insertions(+), 972 deletions(-) create mode 100644 src/main/java/net/sourceforge/cilib/type/types/container/Randomizable.java create mode 100644 src/main/java/net/sourceforge/cilib/type/types/container/TypeList.java create mode 100644 src/test/java/net/sourceforge/cilib/type/types/container/TypeListTest.java |
|
From: Gary P. <gpa...@gm...> - 2009-06-01 05:17:37
|
Finally tracked the last issue with the unit tests. Will post a patch later today. On Tuesday 12 May 2009 15:11:06 Theuns Cloete wrote: > Hi all, > > I like the fact that Vector will only contain Numerics, but can't we > go one step further? How about using Java generics to achieve > something like the following: > > abstract class AbstractList<T extends Type> implements StructuredType<T>... > and then > class Vector<N extends Numeric> extends AbstractList<N> implements > Resettable, VectorMath... > > I think that will be even better! Note also that we don't need an > extra TypeList... > -- > Theuns > > On Tue, May 12, 2009 at 1:21 PM, Gary Pampara <gpa...@gm...> wrote: > > Hi all, > > > > We had a request come in from Andrich regarding making the Vector type > > only contain Numeric types with another class (which I have called > > TypeList at the moment) to maintain a list of types. > > > > There argument is that Vectors are mathematical concepts that have > > various properties and the CIlib version of a Vector should behave the > > same. > > > > I rather like this change and want to know al your opinions. > > > > Regards, > > Gary > > --------------------------------------------------------------------------- >--- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your > production scanning environment may not be a perfect world - but thanks to > Kodak, there's a perfect scanner to get the job done! With the NEW KODAK > i700 Series Scanner you'll get full speed at 300 dpi even with all image > processing features enabled. http://p.sf.net/sfu/kodak-com > _______________________________________________ > cilib-devel mailing list > cil...@li... > https://lists.sourceforge.net/lists/listinfo/cilib-devel |
|
From: Gary P. <gpa...@gm...> - 2009-05-27 09:34:13
|
The changes have been applied. We will be merging the source into master as
soon as the javadocs are finalised. (Yes we are writing documentation!)
On Tuesday 26 May 2009 11:11:56 Gary Pampara wrote:
> There are some optimisations that can be made that will make the Selection
> class more complete. I'm applying these changes at the moment.
>
> One issue is that to select a random element from the provided element list
> originally needed to have an ordering applied to all the elements and then
> to select the desired objects. This can be done in a simpler manner. I'm
> thinking in a static method that terminates the selection process after it
> completes. Having it continue allowing for a chaning on the Selection class
> would be wrong.
>
> Regards,
> Gary
>
> On Saturday 23 May 2009 02:45:47 Wiehann Matthysen wrote:
> > Fixed the EntityWeighing class by removing the erranous else clause
> > that caused one of the fitness values to be equal to InferiorFitness.
> > This broke the RouletteWheelSelection class and all of its dependants
> > such as RouletteWheelSelectionStrategy.
> >
> > Fixed the ProportionateOrdering class to correctly order the elements.
> > Also swapped the ordering around such that most fit entities that were
> > selected (or entities with higher probability of selection) are located
> > at the end of the selection (conforms to natural number ordering).
> >
> > Then, changes were made to the core selection classes such as Selection
> > and SelectionSyntax as well as Ordering and Weighing to allow for
> > selections to be performed on elements that are not necessarily
> > comparable elements. This is usefull for when you want to select a
> > random population from a list of populations (and population -- or
> > algorithm -- is not comparable). However, this meant that changes had to
> > be made to all of the Ordering as well as Weighing classes to remove
> > comparable type requirement. This requirement were also removed from
> > some of the recipe classes and were left untouched in classes such as
> > TournamentSelection where it is required (an ordering of elements is
> > required). The DefaultComparator class accesses the Entry class and
> > performs the comparison if it is required in classes such as
> > SortedOrdering.
> >
> > Some of the tests were modified to conform to the abovementioned
> > changes. Also, the WeighingTest got reintroduced and some changes were
> > made to the vepso.xml and dynamic-vepso.xml files to not make use of the
> > DescendingFitnessComparator class as all entities in cilib should be
> > ordered from least fit to most fit (the selection classes were changed
> > to take that into account).
> > ---
> > .../selection/ElitistSelectionStrategy.java | 1 -
> > .../selection/TournamentSelectionStrategy.java | 2 -
> > .../cilib/util/selection/Selection.java | 45
> > ++++++--------- .../cilib/util/selection/SelectionSyntax.java | 2
> > +-
> > .../util/selection/ordering/DefaultComparator.java | 11 +++-
> > .../cilib/util/selection/ordering/Ordering.java | 2 +-
> > .../selection/ordering/ProportionalOrdering.java | 13 ++--
> > .../util/selection/ordering/RandomOrdering.java | 2 +-
> > .../util/selection/ordering/ReverseOrdering.java | 2 +-
> > .../util/selection/ordering/RingBasedOrdering.java | 5 +-
> > .../util/selection/ordering/SortedOrdering.java | 9 ++-
> > .../util/selection/recipes/ElitistSelection.java | 11 ++--
> > .../util/selection/recipes/RandomSelection.java | 4 +-
> > .../util/selection/recipes/RankBasedSelection.java | 13 ++--
> > .../recipes/RingBasedPopulationSelection.java | 31 +----------
> > .../selection/recipes/RouletteWheelSelection.java | 3 +-
> > .../selection/recipes/TournamentSelection.java | 9 ++-
> > .../util/selection/weighing/FixedWeighing.java | 2 +-
> > .../util/selection/weighing/LinearWeighing.java | 5 +-
> > .../cilib/util/selection/weighing/Weighing.java | 2 +-
> > .../selection/weighing/entity/EntityWeighing.java | 6 +-
> > .../RouletteWheelSelectionStrategyTest.java | 15 ++---
> > .../util/selection/ordering/OrderingTest.java | 4 +-
> > .../util/selection/weighing/WeighingTest.java | 59
> > ++++++++++++++++++++ .../weighing/entity/EntityWeighingTest.java |
> > 19 ++++++- xml/dynamic-vepso.xml | 4 +-
> > xml/vepso.xml | 4 +-
> > 27 files changed, 158 insertions(+), 127 deletions(-)
> > create mode 100644
> > src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.
> >ja va
> >
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistS
> >el ectionStrategy.java
> > b/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistS
> >el ectionStrategy.java index 29fe94f..4936a9e 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistS
> >el ectionStrategy.java +++
> > b/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistS
> >el ectionStrategy.java @@ -25,7 +25,6 @@ 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.comparator.DescendingFitnessComparator;
> > import net.sourceforge.cilib.entity.topologies.TopologyHolder;
> > import net.sourceforge.cilib.util.selection.recipes.ElitistSelection;
> >
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tourname
> >nt SelectionStrategy.java
> > b/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tourname
> >nt SelectionStrategy.java index 8d615e0..2c0129d 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tourname
> >nt SelectionStrategy.java +++
> > b/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tourname
> >nt SelectionStrategy.java @@ -25,7 +25,6 @@ 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.comparator.DescendingFitnessComparator;
> > import net.sourceforge.cilib.entity.topologies.TopologyHolder;
> > import net.sourceforge.cilib.util.selection.recipes.TournamentSelection;
> >
> > @@ -70,7 +69,6 @@ public class TournamentSelectionStrategy extends
> > SelectionStrategy { public <T extends Entity> T select(Topology<T>
> > population) {
> > TournamentSelection<T> selection = new TournamentSelection<T>();
> > selection.setTournamentSize(this.tournamentProportion);
> > - selection.setComparator(new DescendingFitnessComparator<T>());
> > return selection.select(population);
> > }
> >
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java index
> > f4ac2f1..2da72ac 100644
> > --- a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
> > +++ b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
> > @@ -59,7 +59,7 @@ import
> > net.sourceforge.cilib.util.selection.weighing.Weighing; * @param <E> The
> > comparable type.
> > * @author gpampara
> > */
> > -public final class Selection<E extends Comparable> implements
> > SelectionSyntax<E> { +public final class Selection<E> implements
> > SelectionSyntax<E> {
> >
> > private List<Entry<E>> elements;
> >
> > @@ -72,8 +72,9 @@ public final class Selection<E extends Comparable>
> > implements SelectionSyntax<E> private Selection(Collection<? extends E>
> > elements) {
> > this.elements = new ArrayList<Entry<E>>(elements.size());
> >
> > - for (E element : elements)
> > + for (E element : elements) {
> > this.elements.add(new Entry<E>(element));
> > + }
> > }
> >
> > /**
> > @@ -82,7 +83,7 @@ public final class Selection<E extends Comparable>
> > implements SelectionSyntax<E> * @param elements The collection of
> > elements to operate on.
> > * @return A selection based on the provided collection.
> > */
> > - public static <T extends Comparable> Selection<T> from(Collection<?
> > extends T> elements) { + public static <T> Selection<T>
> > from(Collection<? extends T> elements) { return new
> > Selection<T>(elements); }
> >
> > @@ -90,15 +91,16 @@ public final class Selection<E extends Comparable>
> > implements SelectionSyntax<E> * Apply the provided ordering on the
> > current selection. The result of the * operation will result in a
> > modified selection.
> > * @param ordering The ordering to orderBy.
> > - * @return A selection upon which the ordering has be applied.
> > + * @return A selection upon which the ordering has been applied.
> > * @throws UnsupportedOperationException if the ordering cannot be
> > applied. */
> > @Override
> > public SelectionSyntax<E> orderBy(Ordering<E> ordering) {
> > boolean result = ordering.order(this.elements);
> >
> > - if (result)
> > + if (result) {
> > return this;
> > + }
> >
> > throw new UnsupportedOperationException("The ordering [" +
> > ordering.getClass().getSimpleName() + "] " + "cannot be applied to the
> > selection. Please ensure that the intention of the ordering is
> > correct."); @@ -107,15 +109,16 @@ public final class Selection<E extends
> > Comparable> implements SelectionSyntax<E> /**
> > * Apply the provided weighing on the current selection. The result
> > of the * operation will result in new weighed selection.
> > - * @param weighing The weighing to orderBy.
> > - * @return A selection upon which the weighing has be applied.
> > + * @param weighing The weighing to weighWith.
> > + * @return A selection upon which the weighing has been applied.
> > */
> > @Override
> > public SelectionSyntax<E> weigh(Weighing<E> weighing) {
> > boolean result = weighing.weigh(this.elements);
> >
> > - if (result)
> > + if (result) {
> > return this;
> > + }
> >
> > throw new UnsupportedOperationException("The weighing [" +
> > weighing.getClass().getSimpleName() + "]" + "cannot be applied to the
> > selection. Please ensure that the intention of the weighing is
> > correct."); @@ -173,8 +176,9 @@ public final class Selection<E extends
> > Comparable> implements SelectionSyntax<E> public List<E> select() {
> > List<E> result = new ArrayList<E>();
> >
> > - for (Entry<E> entry : elements)
> > + for (Entry<E> entry : elements) {
> > result.add(entry.getElement());
> > + }
> >
> > return result;
> > }
> > @@ -189,7 +193,6 @@ public final class Selection<E extends Comparable>
> > implements SelectionSyntax<E> return this.elements;
> > }
> >
> > -
> > /**
> > * This class provides the notion of an entry within a list
> > * for the selection process.
> > @@ -199,7 +202,8 @@ public final class Selection<E extends Comparable>
> > implements SelectionSyntax<E> * can be recored and used during the
> > selection process.
> > * @param <E> The {@see Comparable} type.
> > */
> > - public final static class Entry<E extends Comparable> implements
> > Comparable { + public final static class Entry<E> {
> > +
> > private final E element;
> > private double weight;
> >
> > @@ -247,11 +251,13 @@ public final class Selection<E extends Comparable>
> > implements SelectionSyntax<E> */
> > @Override
> > public boolean equals(Object obj) {
> > - if (obj == this)
> > + if (obj == this) {
> > return true;
> > + }
> >
> > - if ((obj == null) || (this.getClass() != obj.getClass()))
> > + if ((obj == null) || (this.getClass() != obj.getClass())) {
> > return false;
> > + }
> >
> > Entry<E> other = (Entry<E>) obj;
> > return this.element.equals(other.element);
> > @@ -274,18 +280,5 @@ public final class Selection<E extends Comparable>
> > implements SelectionSyntax<E> public String toString() {
> > return this.element.toString();
> > }
> > -
> > - /**
> > - * Compare the current decorated {@code element} with the
> > provided - * object instance.
> > - * @param o The instance to test.
> > - * @return {@code 0} if equal, {@code -1} if the current element
> > - * is less than the provided instance, {@code 1}
> > otherwise. - */
> > - @Override
> > - public int compareTo(Object o) {
> > - Entry<E> other = (Entry<E>) o;
> > - return this.element.compareTo(other.element);
> > - }
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> > index 3ba5613..1bb1f8b 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> > +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> > @@ -29,7 +29,7 @@ import
> > net.sourceforge.cilib.util.selection.weighing.Weighing; * @author Wiehann
> > Matthysen
> > * @param <E>
> > */
> > -public interface SelectionSyntax<E extends Comparable> {
> > +public interface SelectionSyntax<E> {
> >
> > public SelectionSyntax<E> orderBy(Ordering<E> ordering);
> >
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComp
> >ar ator.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComp
> >ar ator.java index 9b80982..4a44798 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComp
> >ar ator.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComp
> >ar ator.java @@ -22,11 +22,16 @@
> > package net.sourceforge.cilib.util.selection.ordering;
> >
> > import java.util.Comparator;
> > +import net.sourceforge.cilib.util.selection.Selection.Entry;
> >
> > -public class DefaultComparator<E extends Comparable> implements
> > Comparator<E> { +/**
> > + * @author Wiehann Matthysen
> > + * @param <E>
> > + */
> > +public class DefaultComparator<E extends Comparable> implements
> > Comparator<Entry<E>> {
> >
> > @Override
> > - public int compare(E o1, E o2) {
> > - return o1.compareTo(o2);
> > + public int compare(Entry<E> o1, Entry<E> o2) {
> > + return o1.getElement().compareTo(o2.getElement());
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.ja
> >va
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.ja
> >va index 00f6b0d..ad34630 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.ja
> >va +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.ja
> >va @@ -30,7 +30,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @param <E> The type to
> > apply the ordering to.
> > * @author gpampara
> > */
> > -public interface Ordering<E extends Comparable> {
> > +public interface Ordering<E> {
> >
> > /**
> > * Apply the ordering on the provided list.
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Proportiona
> >lO rdering.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Proportiona
> >lO rdering.java index 04dd378..538f06c 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Proportiona
> >lO rdering.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Proportiona
> >lO rdering.java @@ -30,7 +30,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @author Wiehann
> > Matthysen * @param <E>
> > */
> > -public class ProportionalOrdering<E extends Comparable> implements
> > Ordering<E> { +public class ProportionalOrdering<E> implements
> > Ordering<E> {
> >
> > private Random generator;
> >
> > @@ -61,14 +61,13 @@ public class ProportionalOrdering<E extends
> > Comparable> implements Ordering<E> { double randomValue =
> > this.generator.nextDouble() * total; double marker = 0.0;
> > int j = i;
> > - for (; j < elements.size() - 1 && marker < randomValue; ++j)
> > { - marker += elements.get(j).getWeight();
> > - }
> > - // Swap elements i and j.
> > - Selection.Entry<E> elementJ = elements.set(j,
> > elements.set(i, elements.get(j))); + do {
> > + marker += elements.get(j++).getWeight();
> > + } while (j < elements.size() && marker >= randomValue);
> > + // Swap elements i and j - 1.
> > + Selection.Entry<E> elementJ = elements.set(j - 1,
> > elements.set(i, elements.get(j - 1))); total -= elementJ.getWeight();
> > }
> > -
> > return true;
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrder
> >in g.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrder
> >in g.java index 202a962..32a76f0 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrder
> >in g.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrder
> >in g.java @@ -33,7 +33,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @param <E> The
> > comparable type.
> > * @author gpampara
> > */
> > -public class RandomOrdering<E extends Comparable> implements Ordering<E>
> > { +public class RandomOrdering<E> implements Ordering<E> {
> >
> > private Random generator;
> >
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrde
> >ri ng.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrde
> >ri ng.java index 6a85fae..3b00ad6 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrde
> >ri ng.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrde
> >ri ng.java @@ -29,7 +29,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @author Wiehann
> > Matthysen * @param <E>
> > */
> > -public class ReverseOrdering<E extends Comparable> implements
> > Ordering<E> { +public class ReverseOrdering<E> implements Ordering<E> {
> >
> > @Override
> > public boolean order(List<Selection.Entry<E>> elements) {
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOr
> >de ring.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOr
> >de ring.java index 8927f8a..0cd8395 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOr
> >de ring.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOr
> >de ring.java @@ -29,7 +29,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @author Wiehann
> > Matthysen * @param <E>
> > */
> > -public class RingBasedOrdering<E extends Comparable> implements
> > Ordering<E> { +public class RingBasedOrdering<E> implements Ordering<E> {
> >
> > private E marker;
> >
> > @@ -51,9 +51,8 @@ public class RingBasedOrdering<E extends Comparable>
> > implements Ordering<E> {
> >
> > int position = 0;
> > for (Selection.Entry<E> entry : elements) {
> > - if (this.marker.compareTo(entry.getElement()) == 0)
> > + if (this.marker.equals(entry.getElement()))
> > break;
> > -
> > position++;
> > }
> >
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrder
> >in g.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrder
> >in g.java index e080c07..4787233 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrder
> >in g.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrder
> >in g.java @@ -25,6 +25,7 @@ import java.util.Collections;
> > import java.util.Comparator;
> > import java.util.List;
> > import net.sourceforge.cilib.util.selection.Selection;
> > +import net.sourceforge.cilib.util.selection.Selection.Entry;
> >
> > /**
> > * Apply a sorting operation to the provided list, ordering the list
> > naturally @@ -34,9 +35,9 @@ import
> > net.sourceforge.cilib.util.selection.Selection; */
> > public class SortedOrdering<E extends Comparable> implements Ordering<E>
> > {
> >
> > - private Comparator<E> comparator;
> > + private Comparator<Entry<E>> comparator;
> >
> > - public SortedOrdering(Comparator<E> comparator) {
> > + public SortedOrdering(Comparator<Entry<E>> comparator) {
> > this.comparator = comparator;
> > }
> >
> > @@ -50,8 +51,8 @@ public class SortedOrdering<E extends Comparable>
> > implements Ordering<E> { * @return {@code true} if successful, {@code
> > false} otherwise. */
> > @Override
> > - public boolean order(List<Selection.Entry<E>> element) {
> > - Collections.sort(element);
> > + public boolean order(List<Selection.Entry<E>> elements) {
> > + Collections.sort(elements, this.comparator);
> > return true;
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelec
> >ti on.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelec
> >ti on.java index 2e92e16..f9c9c6f 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelec
> >ti on.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelec
> >ti on.java @@ -25,6 +25,7 @@ import java.util.Collection;
> > import java.util.Comparator;
> > import java.util.List;
> > import net.sourceforge.cilib.util.selection.Selection;
> > +import net.sourceforge.cilib.util.selection.Selection.Entry;
> > import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
> > import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
> >
> > @@ -35,9 +36,9 @@ import
> > net.sourceforge.cilib.util.selection.ordering.SortedOrdering; public
> > class ElitistSelection<E extends Comparable> implements
> > SelectionRecipe<E> { private static final long serialVersionUID =
> > -5432603299031620114L;
> >
> > - private Comparator<E> comparator;
> > + private Comparator<Entry<E>> comparator;
> >
> > - public ElitistSelection(Comparator<E> comparator) {
> > + public ElitistSelection(Comparator<Entry<E>> comparator) {
> > this.comparator = comparator;
> > }
> >
> > @@ -49,11 +50,11 @@ public class ElitistSelection<E extends Comparable>
> > implements SelectionRecipe<E this.comparator = copy.comparator;
> > }
> >
> > - public void setComparator(Comparator<E> comparator) {
> > + public void setComparator(Comparator<Entry<E>> comparator) {
> > this.comparator = comparator;
> > }
> >
> > - public Comparator<E> getComparator() {
> > + public Comparator<Entry<E>> getComparator() {
> > return this.comparator;
> > }
> >
> > @@ -64,7 +65,7 @@ public class ElitistSelection<E extends Comparable>
> > implements SelectionRecipe<E
> >
> > @Override
> > public E select(Collection<? extends E> elements) {
> > - List<E> selection = Selection.from(elements).orderBy(new
> > SortedOrdering(this.comparator)).last().select(); + List<E>
> > selection = Selection.from(elements).orderBy(new
> > SortedOrdering<E>(this.comparator)).last().select(); return
> > selection.get(0);
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelect
> >io n.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelect
> >io n.java index d30d1de..0eb1401 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelect
> >io n.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelect
> >io n.java @@ -32,7 +32,7 @@ import
> > net.sourceforge.cilib.util.selection.ordering.RandomOrdering; * @author
> > Wiehann Matthysen
> > * @param <E>
> > */
> > -public class RandomSelection<E extends Comparable> implements
> > SelectionRecipe<E> { +public class RandomSelection<E> implements
> > SelectionRecipe<E> {
> > private static final long serialVersionUID = -5099663528040315048L;
> >
> > private Random random;
> > @@ -56,7 +56,7 @@ public class RandomSelection<E extends Comparable>
> > implements SelectionRecipe<E>
> >
> > @Override
> > public E select(Collection<? extends E> elements) {
> > - List<E> selection = Selection.from(elements).orderBy(new
> > RandomOrdering<E>(this.random)).first().select(); + List<E>
> > selection = Selection.from(elements).orderBy(new
> > RandomOrdering<E>(this.random)).last().select(); return selection.get(0);
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSel
> >ec tion.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSel
> >ec tion.java index 75b13bf..779a855 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSel
> >ec tion.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSel
> >ec tion.java @@ -27,6 +27,7 @@ import java.util.List;
> > import net.sourceforge.cilib.math.random.generator.MersenneTwister;
> > import net.sourceforge.cilib.math.random.generator.Random;
> > import net.sourceforge.cilib.util.selection.Selection;
> > +import net.sourceforge.cilib.util.selection.Selection.Entry;
> > import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
> > import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
> > import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
> > @@ -38,15 +39,15 @@ import
> > net.sourceforge.cilib.util.selection.ordering.SortedOrdering; public
> > class RankBasedSelection<E extends Comparable> implements
> > SelectionRecipe<E> { private static final long serialVersionUID =
> > -2387196820773731607L;
> >
> > - private Comparator<E> comparator;
> > + private Comparator<Entry<E>> comparator;
> > private Random random;
> >
> > - public RankBasedSelection(Comparator<E> comparator, Random random) {
> > + public RankBasedSelection(Comparator<Entry<E>> comparator, Random
> > random) { this.comparator = comparator;
> > this.random = random;
> > }
> >
> > - public RankBasedSelection(Comparator<E> comparator) {
> > + public RankBasedSelection(Comparator<Entry<E>> comparator) {
> > this(comparator, new MersenneTwister());
> > }
> >
> > @@ -59,11 +60,11 @@ public class RankBasedSelection<E extends Comparable>
> > implements SelectionRecipe this.random = copy.random.getClone();
> > }
> >
> > - public void setComparator(Comparator<E> comparator) {
> > + public void setComparator(Comparator<Entry<E>> comparator) {
> > this.comparator = comparator;
> > }
> >
> > - public Comparator<E> getComparator() {
> > + public Comparator<Entry<E>> getComparator() {
> > return this.comparator;
> > }
> >
> > @@ -74,7 +75,7 @@ public class RankBasedSelection<E extends Comparable>
> > implements SelectionRecipe
> >
> > @Override
> > public E select(Collection<? extends E> elements) {
> > - List<E> selection = Selection.from(elements).orderBy(new
> > SortedOrdering<E>(this.comparator)).first(this.random.nextInt(elements.si
> >ze ())).orderBy(new RandomOrdering<E>(this.random)).first().select(); +
> > List<E> selection = Selection.from(elements).orderBy(new
> > SortedOrdering<E>(this.comparator)).last(this.random.nextInt(elements.siz
> >e( ))).orderBy(new RandomOrdering<E>(this.random)).last().select(); return
> > selection.get(0);
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPop
> >ul ationSelection.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPop
> >ul ationSelection.java index 5da4287..4886855 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPop
> >ul ationSelection.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPop
> >ul ationSelection.java @@ -21,9 +21,7 @@
> > */
> > package net.sourceforge.cilib.util.selection.recipes;
> >
> > -import java.util.ArrayList;
> > import java.util.Collection;
> > -import java.util.List;
> > import net.sourceforge.cilib.algorithm.Algorithm;
> > import
> > net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
> > import net.sourceforge.cilib.util.selection.Selection;
> > @@ -48,33 +46,6 @@ public class RingBasedPopulationSelection implements
> > SelectionRecipe<PopulationB
> >
> > @Override
> > public PopulationBasedAlgorithm select(Collection<? extends
> > PopulationBasedAlgorithm> elements) { -
> > PopulationBasedAlgorithmWrapper targetPBA = new
> > PopulationBasedAlgorithmWrapper((PopulationBasedAlgorithm)Algorithm.get()
> >); -
> > - List<PopulationBasedAlgorithmWrapper> list = new
> > ArrayList<PopulationBasedAlgorithmWrapper>(); - for
> > (PopulationBasedAlgorithm p : elements) {
> > - PopulationBasedAlgorithmWrapper wrapper = new
> > PopulationBasedAlgorithmWrapper(p); - list.add(wrapper);
> > - }
> > -
> > - PopulationBasedAlgorithmWrapper wrapper =
> > Selection.from(list).orderBy(new
> > RingBasedOrdering<PopulationBasedAlgorithmWrapper>(targetPBA)).first().si
> >ng leSelect(); - return wrapper.get();
> > + return Selection.from(elements).orderBy(new
> > RingBasedOrdering<PopulationBasedAlgorithm>((PopulationBasedAlgorithm)Alg
> >or ithm.get())).first().singleSelect(); }
> > -
> > - private class PopulationBasedAlgorithmWrapper implements Comparable
> > { - private final PopulationBasedAlgorithm algorithm;
> > -
> > - public PopulationBasedAlgorithmWrapper(PopulationBasedAlgorithm
> > algorithm) { - this.algorithm = algorithm;
> > - }
> > -
> > - public PopulationBasedAlgorithm get() {
> > - return algorithm;
> > - }
> > -
> > - @Override
> > - public int compareTo(Object o) {
> > - return 0;
> > - }
> > - }
> > -
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWhee
> >lS election.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWhee
> >lS election.java index 8b4bf1f..e0205e8 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWhee
> >lS election.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWhee
> >lS election.java @@ -22,7 +22,6 @@
> > package net.sourceforge.cilib.util.selection.recipes;
> >
> > import java.util.Collection;
> > -import java.util.List;
> > import net.sourceforge.cilib.math.random.generator.MersenneTwister;
> > import net.sourceforge.cilib.math.random.generator.Random;
> > import net.sourceforge.cilib.util.selection.Selection;
> > @@ -73,7 +72,7 @@ public class RouletteWheelSelection<E extends
> > Comparable> implements SelectionRe
> >
> > @Override
> > public E select(Collection<? extends E> elements) {
> > - E selection =
> > Selection.from(elements).weigh(this.weighing).orderBy(new
> > ProportionalOrdering<E>(this.random)).first().singleSelect(); + E
> > selection = Selection.from(elements).weigh(this.weighing).orderBy(new
> > ProportionalOrdering<E>(this.random)).last().singleSelect(); return
> > selection;
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSe
> >le ction.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSe
> >le ction.java index f030665..093e569 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSe
> >le ction.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSe
> >le ction.java @@ -28,6 +28,7 @@ import
> > net.sourceforge.cilib.controlparameter.ProportionalControlParameter;
> > import net.sourceforge.cilib.math.random.generator.MersenneTwister;
> > import net.sourceforge.cilib.math.random.generator.Random;
> > import net.sourceforge.cilib.util.selection.Selection;
> > +import net.sourceforge.cilib.util.selection.Selection.Entry;
> > import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
> > import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
> > import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
> > @@ -40,7 +41,7 @@ public class TournamentSelection<E extends Comparable>
> > implements SelectionRecip private static final long serialVersionUID =
> > -6689673224380247931L;
> >
> > private ControlParameter tournamentProportion;
> > - private Comparator<E> comparator;
> > + private Comparator<Entry<E>> comparator;
> > private Random random;
> >
> > public TournamentSelection() {
> > @@ -68,11 +69,11 @@ public class TournamentSelection<E extends
> > Comparable> implements SelectionRecip this.tournamentProportion =
> > tournamanetSize; }
> >
> > - public void setComparator(Comparator<E> comparator) {
> > + public void setComparator(Comparator<Entry<E>> comparator) {
> > this.comparator = comparator;
> > }
> >
> > - public Comparator<E> getComparator() {
> > + public Comparator<Entry<E>> getComparator() {
> > return this.comparator;
> > }
> >
> > @@ -80,6 +81,6 @@ public class TournamentSelection<E extends Comparable>
> > implements SelectionRecip public E select(Collection<? extends E>
> > elements) {
> > int tournamentSize =
> > Double.valueOf(this.tournamentProportion.getParameter() *
> > elements.size()).intValue(); return Selection.from(elements).orderBy(new
> > RandomOrdering<E>(this.random)). -
> > first(tournamentSize).orderBy(new
> > SortedOrdering<E>(this.comparator)).first().select().get(0); +
> > last(tournamentSize).orderBy(new
> > SortedOrdering<E>(this.comparator)).last().select().get(0); }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighi
> >ng .java
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighi
> >ng .java index 5152de4..7a6a217 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighi
> >ng .java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighi
> >ng .java @@ -28,7 +28,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @author Wiehann
> > Matthysen * @param <E>
> > */
> > -public class FixedWeighing<E extends Comparable> implements Weighing<E>
> > { +public class FixedWeighing<E> implements Weighing<E> {
> > private static final long serialVersionUID = -6990220691744842964L;
> >
> > private double weight;
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeigh
> >in g.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeigh
> >in g.java index 21d1adc..64ce536 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeigh
> >in g.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeigh
> >in g.java @@ -28,7 +28,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @author Wiehann
> > Matthysen * @param <E>
> > */
> > -public class LinearWeighing<E extends Comparable> implements Weighing<E>
> > { +public class LinearWeighing<E> implements Weighing<E> {
> > private static final long serialVersionUID = 3294682425241945584L;
> >
> > private double min;
> > @@ -37,7 +37,7 @@ public class LinearWeighing<E extends Comparable>
> > implements Weighing<E> { public LinearWeighing() {
> > this(0.0, 1.0);
> > }
> > -
> > +
> > public LinearWeighing(double min, double max) {
> > this.min = min;
> > this.max = max;
> > @@ -76,7 +76,6 @@ public class LinearWeighing<E extends Comparable>
> > implements Weighing<E> { for (Selection.Entry<E> element : elements) {
> > element.setWeight(objectIndex++ * stepSize + this.min);
> > }
> > -
> > return true;
> > }
> > }
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.ja
> >va
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.ja
> >va index 158f931..9fd703d 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.ja
> >va +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.ja
> >va @@ -29,7 +29,7 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @author Wiehann
> > Matthysen
> > * @param <E>
> > */
> > -public interface Weighing<E extends Comparable> extends Cloneable {
> > +public interface Weighing<E> extends Cloneable {
> >
> > @Override
> > public Weighing<E> getClone();
> > diff --git
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty Weighing.java
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty Weighing.java index 0feb33c..05ec7e7 100644
> > ---
> > a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty Weighing.java +++
> > b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty Weighing.java @@ -35,8 +35,8 @@ import
> > net.sourceforge.cilib.util.selection.Selection; * @param <E>
> > */
> > public class EntityWeighing<E extends Entity> implements Weighing<E> {
> > - private static final long serialVersionUID = 5906567326258195932L;
> >
> > + private static final long serialVersionUID = 5906567326258195932L;
> > private EntityFitness<E> entityFitness;
> >
> > public EntityWeighing(EntityFitness<E> entityFitness) {
> > @@ -63,7 +63,7 @@ public class EntityWeighing<E extends Entity>
> > implements Weighing<E> { if (minMaxFitness.getKey() ==
> > InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getKey()) <
> > 0) {
> > minMaxFitness.setKey(fitness);
> > }
> > - else if (minMaxFitness.getValue() ==
> > InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getValue())
> > > 0) { + if (minMaxFitness.getValue() ==
> > InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getValue())
> > > 0) { minMaxFitness.setValue(fitness);
> > }
> > }
> > @@ -72,7 +72,6 @@ public class EntityWeighing<E extends Entity>
> > implements Weighing<E> {
> >
> > @Override
> > public boolean weigh(List<Selection.Entry<E>> entities) {
> > -// List<Pair<Double, E>> weighedEntities = new
> > ArrayList<Pair<Double, E>>(entities.size()); Pair<Fitness, Fitness>
> > minMaxFitness = getMinMaxFitness(entities);
> >
> > if (minMaxFitness.getKey() == InferiorFitness.instance() ||
> > @@ -85,7 +84,6 @@ public class EntityWeighing<E extends Entity>
> > implements Weighing<E> { for (Selection.Entry<E> entity : entities) {
> > double weight =
> > (this.entityFitness.getFitness(entity.getElement()).getValue() -
> > minMaxFitness.getKey().getValue()) / minMaxDifference;
> > entity.setWeight(weight);
> > -// weighedEntities.add(new Pair<Double, E>(weight, entity));
> > }
> >
> > return true;
> > diff --git
> > a/src/test/java/net/sourceforge/cilib/entity/operators/selection/Roulette
> >Wh eelSelectionStrategyTest.java
> > b/src/test/java/net/sourceforge/cilib/entity/operators/selection/Roulette
> >Wh eelSelectionStrategyTest.java index 4b69fc7..d030f6d 100644
> > ---
> > a/src/test/java/net/sourceforge/cilib/entity/operators/selection/Roulette
> >Wh eelSelectionStrategyTest.java +++
> > b/src/test/java/net/sourceforge/cilib/entity/operators/selection/Roulette
> >Wh eelSelectionStrategyTest.java @@ -23,7 +23,6 @@
> > */
> > package net.sourceforge.cilib.entity.operators.selection;
> >
> > -
> > import junit.framework.Assert;
> > import net.sourceforge.cilib.ec.Individual;
> > import net.sourceforge.cilib.entity.Entity;
> > @@ -34,7 +33,6 @@ import
> > net.sourceforge.cilib.problem.MaximisationFitness;
> >
> > import net.sourceforge.cilib.problem.MinimisationFitness;
> > import org.junit.Before;
> > -import org.junit.Ignore;
> > import org.junit.Test;
> >
> > /**
> > @@ -48,7 +46,7 @@ import org.junit.Test;
> > * </p>
> > */
> > public class RouletteWheelSelectionStrategyTest {
> > -
> > +
> > private Topology<Individual> topology;
> > private Individual individual1;
> > private Individual individual2;
> > @@ -57,7 +55,7 @@ public class RouletteWheelSelectionStrategyTest {
> > @Before
> > public void createDummyTopology() {
> > topology = new GBestTopology<Individual>();
> > -
> > +
> > individual1 = new Individual();
> > individual2 = new Individual();
> > individual3 = new Individual();
> > @@ -83,20 +81,19 @@ public class RouletteWheelSelectionStrategyTest {
> >
> > Assert.assertNotNull(entity);
> > Assert.assertTrue(topology.contains(entity));
> > - Assert.assertEquals(entity, individual3);
> > + Assert.assertSame(entity, individual3);
> > }
> >
> > @Test
> > public void maximizationSelection() {
> > - individual1.getProperties().put(EntityType.FITNESS, new
> > MaximisationFitness(90000.0)); // Should be the best entity -
> > individual2.getProperties().put(EntityType.FITNESS, new
> > MaximisationFitness(0.5)); +
> > individual1.getProperties().put(EntityType.FITNESS, new
> > MaximisationFitness(0.5)); +
> > individual2.getProperties().put(EntityType.FITNESS, new
> > MaximisationFitness(90000.0)); // Should be the best entity
> > individual3.getProperties().put(EntityType.FITNESS, new
> > MaximisationFitness(0.5));
> >
> > RouletteWheelSelectionStrategy rouletteWheelSelectionStrategy =
> > new RouletteWheelSelectionStrategy(); Entity entity =
> > rouletteWheelSelectionStrategy.select(topology);
> >
> > Assert.assertNotNull(entity);
> > - Assert.assertTrue(entity.equals(individual1));
> > + Assert.assertTrue(entity.equals(individual2));
> > }
> > -
> > }
> > diff --git
> > a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTes
> >t. java
> > b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTes
> >t. java index 5dc48e3..6bdc981 100644
> > ---
> > a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTes
> >t. java +++
> > b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTes
> >t. java @@ -52,7 +52,6 @@ public class OrderingTest {
> > List<Selection.Entry<Integer>> entries =
> > Selection.from(elements).entries(); boolean ordered = new
> > ReverseOrdering<Integer>().order(entries); Assert.assertTrue(ordered);
> > -
> > for (int i = 0; i < 9; ++i) {
> > Assert.assertEquals(elements.size() - i,
> > entries.get(i).getElement().intValue()); }
> > @@ -64,7 +63,6 @@ public class OrderingTest {
> > List<Selection.Entry<Integer>> entries =
> > Selection.from(elements).entries(); boolean ordered = new
> > RingBasedOrdering<Integer>(5).order(entries); Assert.assertTrue(ordered);
> > - System.out.println("entries: " + entries);
> > Assert.assertEquals(6, entries.get(0).getElement().intValue());
> > Assert.assertEquals(7, entries.get(1).getElement().intValue());
> > Assert.assertEquals(8, entries.get(2).getElement().intValue());
> > @@ -75,7 +73,7 @@ public class OrderingTest {
> > Assert.assertEquals(4, entries.get(7).getElement().intValue());
> > Assert.assertEquals(5, entries.get(8).getElement().intValue());
> > }
> > -
> > +
> > @Test
> > public void sortedOrdering() {
> > List<Integer> elements = Arrays.asList(9, 8, 7, 6, 5, 4, 3, 2,
> > 1); diff --git
> > a/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTes
> >t. java
> > b/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTes
> >t. java new file mode 100644
> > index 0000000..286b687
> > --- /dev/null
> > +++
> > b/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTes
> >t. java @@ -0,0 +1,59 @@
> > +/**
> > + * 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.weighing;
> > +
> > +import java.util.Arrays;
> > +import java.util.List;
> > +import net.sourceforge.cilib.util.selection.Selection;
> > +import net.sourceforge.cilib.util.selection.Selection.Entry;
> > +import org.junit.Assert;
> > +import org.junit.Test;
> > +
> > +/**
> > + * @author Wiehann Matthysen
> > + */
> > +public class WeighingTest {
> > +
> > + @Test
> > + public void fixedWeighing() {
> > + List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8,
> > 9); + List<Entry<Integer>> weighedElements =
> > Selection.from(elements).weigh(new FixedWeighing(1.0)).entries(); +
> > for (int i = 0; i < weighedElements.size(); ++i) {
> > + Assert.assertEquals(1.0, weighedElements.get(i).getWeight(),
> > 0.0001); + }
> > + }
> > +
> > + @Test
> > + public void linearWeighing() {
> > + List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8,
> > 9); + List<Entry<Integer>> weighedElements =
> > Selection.from(elements).weigh(new
> > LinearWeighing<Integer>(0.0,1.0)).entries(); +
> > Assert.assertEquals(0.0, weighedElements.get(0).getWeight(), 0.0001);
> > + Assert.assertEquals(0.125, weighedElements.get(1).getWeight(),
> > 0.0001); + Assert.assertEquals(0.25,
> > weighedElements.get(2).getWeight(), 0.0001); +
> > Assert.assertEquals(0.375, weighedElements.get(3).getWeight(), 0.0001);
> > + Assert.assertEquals(0.5, weighedElements.get(4).getWeight(),
> > 0.0001); + Assert.assertEquals(0.625,
> > weighedElements.get(5).getWeight(), 0.0001); +
> > Assert.assertEquals(0.75, weighedElements.get(6).getWeight(), 0.0001);
> > + Assert.assertEquals(0.875, weighedElements.get(7).getWeight(),
> > 0.0001); + Assert.assertEquals(1.0,
> > weighedElements.get(8).getWeight(), 0.0001); + }
> > +}
> > diff --git
> > a/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty WeighingTest.java
> > b/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty WeighingTest.java index c2d0c7a..f8d23ef 100644
> > ---
> > a/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty WeighingTest.java +++
> > b/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Enti
> >ty WeighingTest.java @@ -27,6 +27,7 @@ import
> > net.sourceforge.cilib.ec.Individual;
> > import net.sourceforge.cilib.entity.EntityType;
> > import net.sourceforge.cilib.problem.Fitness;
> > import net.sourceforge.cilib.problem.MaximisationFitness;
> > +import net.sourceforge.cilib.problem.MinimisationFitness;
> > import net.sourceforge.cilib.util.selection.Selection;
> > import net.sourceforge.cilib.util.selection.Selection.Entry;
> > import org.junit.Assert;
> > @@ -38,7 +39,7 @@ import org.junit.Test;
> > public class EntityWeighingTest {
> >
> > @Test
> > - public void entityWeighing() {
> > + public void entityWeighingMaximise() {
> > Individual i1 = createIndividual(new MaximisationFitness(1.0));
> > Individual i2 = createIndividual(new MaximisationFitness(2.0));
> > Individual i3 = createIndividual(new MaximisationFitness(3.0));
> > @@ -53,6 +54,22 @@ public class EntityWeighingTest {
> > Assert.assertEquals(1.0, entries.get(2).getWeight(), 0.0001);
> > }
> >
> > + @Test
> > + public void entityWeighingMinimise() {
> > + Individual i1 = createIndividual(new MinimisationFitness(1.0));
> > + Individual i2 = createIndividual(new MinimisationFitness(2.0));
> > + Individual i3 = createIndividual(new MinimisationFitness(3.0));
> > +
> > + List<Individual> individuals = Arrays.asList(i1, i2, i3);
> > + List<Selection.Entry<Individual>> entries =
> > Selection.from(individuals).entries(); +
> > EntityWeighing<Individual> weighing = new EntityWeighing<Individual>(); +
> > weighing.weigh(entries);
> > +
> > + Assert.assertEquals(1.0, entries.get(0).getWeight(), 0.0001);
> > + Assert.assertEquals(0.5, entries.get(1).getWeight(), 0.0001);
> > + Assert.assertEquals(0.0, entries.get(2).getWeight(), 0.0001);
> > + }
> > +
> > private Individual createIndividual(Fitness fitness) {
> > Individual i = new Individual();
> > i.getProperties().put(EntityType.FITNESS, fitness);
> > diff --git a/xml/dynamic-vepso.xml b/xml/dynamic-vepso.xml
> > index 7d83de6..0fc7941 100644
> > --- a/xml/dynamic-vepso.xml
> > +++ b/xml/dynamic-vepso.xml
> > @@ -16,9 +16,7 @@
> > <globalGuideSelectionStrategy
> > class="pso.moo.guideselectionstrategies.VEPSOGuideSelectionStrategy">
> > <knowledgeTransferStrategy
> > class="algorithm.population.knowledgetransferstrategies.SelectiveKnowledg
> >eT ransferStrategy"> <populationSelection
> > class="util.selection.recipes.RingBasedPopulationSelection"/> -
> > <entitySelection
> > class="util.selection.recipes.TournamentSelection"> -
> > <comparator
> > class="entity.comparator.DescendingFitnessComparator"/> -
> > </entitySelection>
> > + <entitySelection
> > class="util.selection.recipes.TournamentSelection"/>
> > </knowledgeTransferStrategy>
> > </globalGuideSelectionStrategy>
> > <globalGuideUpdateStrategy
> > class="pso.moo.guideupdatestrategies.StandardGuideUpdateStrategy"/> diff
> > --git a/xml/vepso.xml b/xml/vepso.xml
> > index a56d454..58f41c9 100644
> > --- a/xml/vepso.xml
> > +++ b/xml/vepso.xml
> > @@ -15,9 +15,7 @@
> > <globalGuideSelectionStrategy
> > class="pso.moo.guideselectionstrategies.VEPSOGuideSelectionStrategy">
> > <knowledgeTransferStrategy
> > class="algorithm.population.knowledgetransferstrategies.SelectiveKnowledg
> >eT ransferStrategy"> <populationSelection
> > class="util.selection.recipes.RingBasedPopulationSelection"/> -
> > <entitySelection
> > class="util.selection.recipes.TournamentSelection"> -
> > <comparator
> > class="entity.comparator.DescendingFitnessComparator"/> -
> > </entitySelection>
> > + <entitySelection
> > class="util.selection.recipes.TournamentSelection"/>
> > </knowledgeTransferStrategy>
> > </globalGuideSelectionStrategy>
> > <globalGuideUpdateStrategy
> > class="pso.moo.guideupdatestrategies.StandardGuideUpdateStrategy"/>
>
> ---------------------------------------------------------------------------
>--- Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is
> a gathering of tech-side developers & brand creativity professionals. Meet
> the minds behind Google Creative Lab, Visual Complexity, Processing, &
> iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
> Group, R/GA, & Big Spaceship. http://www.creativitycat.com
> _______________________________________________
> cilib-devel mailing list
> cil...@li...
> https://lists.sourceforge.net/lists/listinfo/cilib-devel
|
|
From: Gary P. <gpa...@gm...> - 2009-05-26 09:12:13
|
There are some optimisations that can be made that will make the Selection
class more complete. I'm applying these changes at the moment.
One issue is that to select a random element from the provided element list
originally needed to have an ordering applied to all the elements and then to
select the desired objects. This can be done in a simpler manner. I'm thinking
in a static method that terminates the selection process after it completes.
Having it continue allowing for a chaning on the Selection class would be
wrong.
Regards,
Gary
On Saturday 23 May 2009 02:45:47 Wiehann Matthysen wrote:
> Fixed the EntityWeighing class by removing the erranous else clause
> that caused one of the fitness values to be equal to InferiorFitness.
> This broke the RouletteWheelSelection class and all of its dependants
> such as RouletteWheelSelectionStrategy.
>
> Fixed the ProportionateOrdering class to correctly order the elements.
> Also swapped the ordering around such that most fit entities that were
> selected (or entities with higher probability of selection) are located
> at the end of the selection (conforms to natural number ordering).
>
> Then, changes were made to the core selection classes such as Selection
> and SelectionSyntax as well as Ordering and Weighing to allow for
> selections to be performed on elements that are not necessarily
> comparable elements. This is usefull for when you want to select a
> random population from a list of populations (and population -- or
> algorithm -- is not comparable). However, this meant that changes had to
> be made to all of the Ordering as well as Weighing classes to remove
> comparable type requirement. This requirement were also removed from
> some of the recipe classes and were left untouched in classes such as
> TournamentSelection where it is required (an ordering of elements is
> required). The DefaultComparator class accesses the Entry class and
> performs the comparison if it is required in classes such as
> SortedOrdering.
>
> Some of the tests were modified to conform to the abovementioned
> changes. Also, the WeighingTest got reintroduced and some changes were
> made to the vepso.xml and dynamic-vepso.xml files to not make use of the
> DescendingFitnessComparator class as all entities in cilib should be
> ordered from least fit to most fit (the selection classes were changed
> to take that into account).
> ---
> .../selection/ElitistSelectionStrategy.java | 1 -
> .../selection/TournamentSelectionStrategy.java | 2 -
> .../cilib/util/selection/Selection.java | 45 ++++++---------
> .../cilib/util/selection/SelectionSyntax.java | 2 +-
> .../util/selection/ordering/DefaultComparator.java | 11 +++-
> .../cilib/util/selection/ordering/Ordering.java | 2 +-
> .../selection/ordering/ProportionalOrdering.java | 13 ++--
> .../util/selection/ordering/RandomOrdering.java | 2 +-
> .../util/selection/ordering/ReverseOrdering.java | 2 +-
> .../util/selection/ordering/RingBasedOrdering.java | 5 +-
> .../util/selection/ordering/SortedOrdering.java | 9 ++-
> .../util/selection/recipes/ElitistSelection.java | 11 ++--
> .../util/selection/recipes/RandomSelection.java | 4 +-
> .../util/selection/recipes/RankBasedSelection.java | 13 ++--
> .../recipes/RingBasedPopulationSelection.java | 31 +----------
> .../selection/recipes/RouletteWheelSelection.java | 3 +-
> .../selection/recipes/TournamentSelection.java | 9 ++-
> .../util/selection/weighing/FixedWeighing.java | 2 +-
> .../util/selection/weighing/LinearWeighing.java | 5 +-
> .../cilib/util/selection/weighing/Weighing.java | 2 +-
> .../selection/weighing/entity/EntityWeighing.java | 6 +-
> .../RouletteWheelSelectionStrategyTest.java | 15 ++---
> .../util/selection/ordering/OrderingTest.java | 4 +-
> .../util/selection/weighing/WeighingTest.java | 59
> ++++++++++++++++++++ .../weighing/entity/EntityWeighingTest.java |
> 19 ++++++- xml/dynamic-vepso.xml | 4 +-
> xml/vepso.xml | 4 +-
> 27 files changed, 158 insertions(+), 127 deletions(-)
> create mode 100644
> src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.ja
>va
>
> diff --git
> a/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSel
>ectionStrategy.java
> b/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSel
>ectionStrategy.java index 29fe94f..4936a9e 100644
> ---
> a/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSel
>ectionStrategy.java +++
> b/src/main/java/net/sourceforge/cilib/entity/operators/selection/ElitistSel
>ectionStrategy.java @@ -25,7 +25,6 @@ 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.comparator.DescendingFitnessComparator; import
> net.sourceforge.cilib.entity.topologies.TopologyHolder;
> import net.sourceforge.cilib.util.selection.recipes.ElitistSelection;
>
> diff --git
> a/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tournament
>SelectionStrategy.java
> b/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tournament
>SelectionStrategy.java index 8d615e0..2c0129d 100644
> ---
> a/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tournament
>SelectionStrategy.java +++
> b/src/main/java/net/sourceforge/cilib/entity/operators/selection/Tournament
>SelectionStrategy.java @@ -25,7 +25,6 @@ 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.comparator.DescendingFitnessComparator; import
> net.sourceforge.cilib.entity.topologies.TopologyHolder;
> import net.sourceforge.cilib.util.selection.recipes.TournamentSelection;
>
> @@ -70,7 +69,6 @@ public class TournamentSelectionStrategy extends
> SelectionStrategy { public <T extends Entity> T select(Topology<T>
> population) {
> TournamentSelection<T> selection = new TournamentSelection<T>();
> selection.setTournamentSize(this.tournamentProportion);
> - selection.setComparator(new DescendingFitnessComparator<T>());
> return selection.select(population);
> }
>
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
> b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java index
> f4ac2f1..2da72ac 100644
> --- a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
> +++ b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
> @@ -59,7 +59,7 @@ import
> net.sourceforge.cilib.util.selection.weighing.Weighing; * @param <E> The
> comparable type.
> * @author gpampara
> */
> -public final class Selection<E extends Comparable> implements
> SelectionSyntax<E> { +public final class Selection<E> implements
> SelectionSyntax<E> {
>
> private List<Entry<E>> elements;
>
> @@ -72,8 +72,9 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> private Selection(Collection<? extends E>
> elements) {
> this.elements = new ArrayList<Entry<E>>(elements.size());
>
> - for (E element : elements)
> + for (E element : elements) {
> this.elements.add(new Entry<E>(element));
> + }
> }
>
> /**
> @@ -82,7 +83,7 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> * @param elements The collection of elements
> to operate on.
> * @return A selection based on the provided collection.
> */
> - public static <T extends Comparable> Selection<T> from(Collection<?
> extends T> elements) { + public static <T> Selection<T>
> from(Collection<? extends T> elements) { return new Selection<T>(elements);
> }
>
> @@ -90,15 +91,16 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> * Apply the provided ordering on the current
> selection. The result of the * operation will result in a modified
> selection.
> * @param ordering The ordering to orderBy.
> - * @return A selection upon which the ordering has be applied.
> + * @return A selection upon which the ordering has been applied.
> * @throws UnsupportedOperationException if the ordering cannot be
> applied. */
> @Override
> public SelectionSyntax<E> orderBy(Ordering<E> ordering) {
> boolean result = ordering.order(this.elements);
>
> - if (result)
> + if (result) {
> return this;
> + }
>
> throw new UnsupportedOperationException("The ordering [" +
> ordering.getClass().getSimpleName() + "] " + "cannot be applied to the
> selection. Please ensure that the intention of the ordering is correct.");
> @@ -107,15 +109,16 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> /**
> * Apply the provided weighing on the current selection. The result of
> the * operation will result in new weighed selection.
> - * @param weighing The weighing to orderBy.
> - * @return A selection upon which the weighing has be applied.
> + * @param weighing The weighing to weighWith.
> + * @return A selection upon which the weighing has been applied.
> */
> @Override
> public SelectionSyntax<E> weigh(Weighing<E> weighing) {
> boolean result = weighing.weigh(this.elements);
>
> - if (result)
> + if (result) {
> return this;
> + }
>
> throw new UnsupportedOperationException("The weighing [" +
> weighing.getClass().getSimpleName() + "]" + "cannot be applied to the
> selection. Please ensure that the intention of the weighing is correct.");
> @@ -173,8 +176,9 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> public List<E> select() {
> List<E> result = new ArrayList<E>();
>
> - for (Entry<E> entry : elements)
> + for (Entry<E> entry : elements) {
> result.add(entry.getElement());
> + }
>
> return result;
> }
> @@ -189,7 +193,6 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> return this.elements;
> }
>
> -
> /**
> * This class provides the notion of an entry within a list
> * for the selection process.
> @@ -199,7 +202,8 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> * can be recored and used during the
> selection process.
> * @param <E> The {@see Comparable} type.
> */
> - public final static class Entry<E extends Comparable> implements
> Comparable { + public final static class Entry<E> {
> +
> private final E element;
> private double weight;
>
> @@ -247,11 +251,13 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> */
> @Override
> public boolean equals(Object obj) {
> - if (obj == this)
> + if (obj == this) {
> return true;
> + }
>
> - if ((obj == null) || (this.getClass() != obj.getClass()))
> + if ((obj == null) || (this.getClass() != obj.getClass())) {
> return false;
> + }
>
> Entry<E> other = (Entry<E>) obj;
> return this.element.equals(other.element);
> @@ -274,18 +280,5 @@ public final class Selection<E extends Comparable>
> implements SelectionSyntax<E> public String toString() {
> return this.element.toString();
> }
> -
> - /**
> - * Compare the current decorated {@code element} with the provided
> - * object instance.
> - * @param o The instance to test.
> - * @return {@code 0} if equal, {@code -1} if the current element
> - * is less than the provided instance, {@code 1}
> otherwise. - */
> - @Override
> - public int compareTo(Object o) {
> - Entry<E> other = (Entry<E>) o;
> - return this.element.compareTo(other.element);
> - }
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> index 3ba5613..1bb1f8b 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> +++
> b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
> @@ -29,7 +29,7 @@ import
> net.sourceforge.cilib.util.selection.weighing.Weighing; * @author Wiehann
> Matthysen
> * @param <E>
> */
> -public interface SelectionSyntax<E extends Comparable> {
> +public interface SelectionSyntax<E> {
>
> public SelectionSyntax<E> orderBy(Ordering<E> ordering);
>
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultCompar
>ator.java
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultCompar
>ator.java index 9b80982..4a44798 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultCompar
>ator.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultCompar
>ator.java @@ -22,11 +22,16 @@
> package net.sourceforge.cilib.util.selection.ordering;
>
> import java.util.Comparator;
> +import net.sourceforge.cilib.util.selection.Selection.Entry;
>
> -public class DefaultComparator<E extends Comparable> implements
> Comparator<E> { +/**
> + * @author Wiehann Matthysen
> + * @param <E>
> + */
> +public class DefaultComparator<E extends Comparable> implements
> Comparator<Entry<E>> {
>
> @Override
> - public int compare(E o1, E o2) {
> - return o1.compareTo(o2);
> + public int compare(Entry<E> o1, Entry<E> o2) {
> + return o1.getElement().compareTo(o2.getElement());
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
> index 00f6b0d..ad34630 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
> +++
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
> @@ -30,7 +30,7 @@ import net.sourceforge.cilib.util.selection.Selection; *
> @param <E> The type to apply the ordering to.
> * @author gpampara
> */
> -public interface Ordering<E extends Comparable> {
> +public interface Ordering<E> {
>
> /**
> * Apply the ordering on the provided list.
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalO
>rdering.java
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalO
>rdering.java index 04dd378..538f06c 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalO
>rdering.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalO
>rdering.java @@ -30,7 +30,7 @@ import
> net.sourceforge.cilib.util.selection.Selection; * @author Wiehann Matthysen
> * @param <E>
> */
> -public class ProportionalOrdering<E extends Comparable> implements
> Ordering<E> { +public class ProportionalOrdering<E> implements Ordering<E>
> {
>
> private Random generator;
>
> @@ -61,14 +61,13 @@ public class ProportionalOrdering<E extends Comparable>
> implements Ordering<E> { double randomValue = this.generator.nextDouble() *
> total; double marker = 0.0;
> int j = i;
> - for (; j < elements.size() - 1 && marker < randomValue; ++j) {
> - marker += elements.get(j).getWeight();
> - }
> - // Swap elements i and j.
> - Selection.Entry<E> elementJ = elements.set(j, elements.set(i,
> elements.get(j))); + do {
> + marker += elements.get(j++).getWeight();
> + } while (j < elements.size() && marker >= randomValue);
> + // Swap elements i and j - 1.
> + Selection.Entry<E> elementJ = elements.set(j - 1,
> elements.set(i, elements.get(j - 1))); total -= elementJ.getWeight();
> }
> -
> return true;
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrderin
>g.java
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrderin
>g.java index 202a962..32a76f0 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrderin
>g.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrderin
>g.java @@ -33,7 +33,7 @@ import
> net.sourceforge.cilib.util.selection.Selection; * @param <E> The comparable
> type.
> * @author gpampara
> */
> -public class RandomOrdering<E extends Comparable> implements Ordering<E> {
> +public class RandomOrdering<E> implements Ordering<E> {
>
> private Random generator;
>
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrderi
>ng.java
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrderi
>ng.java index 6a85fae..3b00ad6 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrderi
>ng.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrderi
>ng.java @@ -29,7 +29,7 @@ import
> net.sourceforge.cilib.util.selection.Selection; * @author Wiehann Matthysen
> * @param <E>
> */
> -public class ReverseOrdering<E extends Comparable> implements Ordering<E>
> { +public class ReverseOrdering<E> implements Ordering<E> {
>
> @Override
> public boolean order(List<Selection.Entry<E>> elements) {
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrde
>ring.java
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrde
>ring.java index 8927f8a..0cd8395 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrde
>ring.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrde
>ring.java @@ -29,7 +29,7 @@ import
> net.sourceforge.cilib.util.selection.Selection; * @author Wiehann Matthysen
> * @param <E>
> */
> -public class RingBasedOrdering<E extends Comparable> implements
> Ordering<E> { +public class RingBasedOrdering<E> implements Ordering<E> {
>
> private E marker;
>
> @@ -51,9 +51,8 @@ public class RingBasedOrdering<E extends Comparable>
> implements Ordering<E> {
>
> int position = 0;
> for (Selection.Entry<E> entry : elements) {
> - if (this.marker.compareTo(entry.getElement()) == 0)
> + if (this.marker.equals(entry.getElement()))
> break;
> -
> position++;
> }
>
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrderin
>g.java
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrderin
>g.java index e080c07..4787233 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrderin
>g.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrderin
>g.java @@ -25,6 +25,7 @@ import java.util.Collections;
> import java.util.Comparator;
> import java.util.List;
> import net.sourceforge.cilib.util.selection.Selection;
> +import net.sourceforge.cilib.util.selection.Selection.Entry;
>
> /**
> * Apply a sorting operation to the provided list, ordering the list
> naturally @@ -34,9 +35,9 @@ import
> net.sourceforge.cilib.util.selection.Selection; */
> public class SortedOrdering<E extends Comparable> implements Ordering<E> {
>
> - private Comparator<E> comparator;
> + private Comparator<Entry<E>> comparator;
>
> - public SortedOrdering(Comparator<E> comparator) {
> + public SortedOrdering(Comparator<Entry<E>> comparator) {
> this.comparator = comparator;
> }
>
> @@ -50,8 +51,8 @@ public class SortedOrdering<E extends Comparable>
> implements Ordering<E> { * @return {@code true} if successful, {@code
> false} otherwise. */
> @Override
> - public boolean order(List<Selection.Entry<E>> element) {
> - Collections.sort(element);
> + public boolean order(List<Selection.Entry<E>> elements) {
> + Collections.sort(elements, this.comparator);
> return true;
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelecti
>on.java
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelecti
>on.java index 2e92e16..f9c9c6f 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelecti
>on.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelecti
>on.java @@ -25,6 +25,7 @@ import java.util.Collection;
> import java.util.Comparator;
> import java.util.List;
> import net.sourceforge.cilib.util.selection.Selection;
> +import net.sourceforge.cilib.util.selection.Selection.Entry;
> import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
> import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
>
> @@ -35,9 +36,9 @@ import
> net.sourceforge.cilib.util.selection.ordering.SortedOrdering; public class
> ElitistSelection<E extends Comparable> implements SelectionRecipe<E> {
> private static final long serialVersionUID = -5432603299031620114L;
>
> - private Comparator<E> comparator;
> + private Comparator<Entry<E>> comparator;
>
> - public ElitistSelection(Comparator<E> comparator) {
> + public ElitistSelection(Comparator<Entry<E>> comparator) {
> this.comparator = comparator;
> }
>
> @@ -49,11 +50,11 @@ public class ElitistSelection<E extends Comparable>
> implements SelectionRecipe<E this.comparator = copy.comparator;
> }
>
> - public void setComparator(Comparator<E> comparator) {
> + public void setComparator(Comparator<Entry<E>> comparator) {
> this.comparator = comparator;
> }
>
> - public Comparator<E> getComparator() {
> + public Comparator<Entry<E>> getComparator() {
> return this.comparator;
> }
>
> @@ -64,7 +65,7 @@ public class ElitistSelection<E extends Comparable>
> implements SelectionRecipe<E
>
> @Override
> public E select(Collection<? extends E> elements) {
> - List<E> selection = Selection.from(elements).orderBy(new
> SortedOrdering(this.comparator)).last().select(); + List<E>
> selection = Selection.from(elements).orderBy(new
> SortedOrdering<E>(this.comparator)).last().select(); return
> selection.get(0);
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelectio
>n.java
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelectio
>n.java index d30d1de..0eb1401 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelectio
>n.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelectio
>n.java @@ -32,7 +32,7 @@ import
> net.sourceforge.cilib.util.selection.ordering.RandomOrdering; * @author
> Wiehann Matthysen
> * @param <E>
> */
> -public class RandomSelection<E extends Comparable> implements
> SelectionRecipe<E> { +public class RandomSelection<E> implements
> SelectionRecipe<E> {
> private static final long serialVersionUID = -5099663528040315048L;
>
> private Random random;
> @@ -56,7 +56,7 @@ public class RandomSelection<E extends Comparable>
> implements SelectionRecipe<E>
>
> @Override
> public E select(Collection<? extends E> elements) {
> - List<E> selection = Selection.from(elements).orderBy(new
> RandomOrdering<E>(this.random)).first().select(); + List<E>
> selection = Selection.from(elements).orderBy(new
> RandomOrdering<E>(this.random)).last().select(); return selection.get(0);
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelec
>tion.java
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelec
>tion.java index 75b13bf..779a855 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelec
>tion.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelec
>tion.java @@ -27,6 +27,7 @@ import java.util.List;
> import net.sourceforge.cilib.math.random.generator.MersenneTwister;
> import net.sourceforge.cilib.math.random.generator.Random;
> import net.sourceforge.cilib.util.selection.Selection;
> +import net.sourceforge.cilib.util.selection.Selection.Entry;
> import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
> import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
> import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
> @@ -38,15 +39,15 @@ import
> net.sourceforge.cilib.util.selection.ordering.SortedOrdering; public class
> RankBasedSelection<E extends Comparable> implements SelectionRecipe<E> {
> private static final long serialVersionUID = -2387196820773731607L;
>
> - private Comparator<E> comparator;
> + private Comparator<Entry<E>> comparator;
> private Random random;
>
> - public RankBasedSelection(Comparator<E> comparator, Random random) {
> + public RankBasedSelection(Comparator<Entry<E>> comparator, Random
> random) { this.comparator = comparator;
> this.random = random;
> }
>
> - public RankBasedSelection(Comparator<E> comparator) {
> + public RankBasedSelection(Comparator<Entry<E>> comparator) {
> this(comparator, new MersenneTwister());
> }
>
> @@ -59,11 +60,11 @@ public class RankBasedSelection<E extends Comparable>
> implements SelectionRecipe this.random = copy.random.getClone();
> }
>
> - public void setComparator(Comparator<E> comparator) {
> + public void setComparator(Comparator<Entry<E>> comparator) {
> this.comparator = comparator;
> }
>
> - public Comparator<E> getComparator() {
> + public Comparator<Entry<E>> getComparator() {
> return this.comparator;
> }
>
> @@ -74,7 +75,7 @@ public class RankBasedSelection<E extends Comparable>
> implements SelectionRecipe
>
> @Override
> public E select(Collection<? extends E> elements) {
> - List<E> selection = Selection.from(elements).orderBy(new
> SortedOrdering<E>(this.comparator)).first(this.random.nextInt(elements.size
>())).orderBy(new RandomOrdering<E>(this.random)).first().select(); +
> List<E> selection = Selection.from(elements).orderBy(new
> SortedOrdering<E>(this.comparator)).last(this.random.nextInt(elements.size(
>))).orderBy(new RandomOrdering<E>(this.random)).last().select(); return
> selection.get(0);
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopul
>ationSelection.java
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopul
>ationSelection.java index 5da4287..4886855 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopul
>ationSelection.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopul
>ationSelection.java @@ -21,9 +21,7 @@
> */
> package net.sourceforge.cilib.util.selection.recipes;
>
> -import java.util.ArrayList;
> import java.util.Collection;
> -import java.util.List;
> import net.sourceforge.cilib.algorithm.Algorithm;
> import
> net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import
> net.sourceforge.cilib.util.selection.Selection;
> @@ -48,33 +46,6 @@ public class RingBasedPopulationSelection implements
> SelectionRecipe<PopulationB
>
> @Override
> public PopulationBasedAlgorithm select(Collection<? extends
> PopulationBasedAlgorithm> elements) { -
> PopulationBasedAlgorithmWrapper targetPBA = new
> PopulationBasedAlgorithmWrapper((PopulationBasedAlgorithm)Algorithm.get());
> -
> - List<PopulationBasedAlgorithmWrapper> list = new
> ArrayList<PopulationBasedAlgorithmWrapper>(); - for
> (PopulationBasedAlgorithm p : elements) {
> - PopulationBasedAlgorithmWrapper wrapper = new
> PopulationBasedAlgorithmWrapper(p); - list.add(wrapper);
> - }
> -
> - PopulationBasedAlgorithmWrapper wrapper =
> Selection.from(list).orderBy(new
> RingBasedOrdering<PopulationBasedAlgorithmWrapper>(targetPBA)).first().sing
>leSelect(); - return wrapper.get();
> + return Selection.from(elements).orderBy(new
> RingBasedOrdering<PopulationBasedAlgorithm>((PopulationBasedAlgorithm)Algor
>ithm.get())).first().singleSelect(); }
> -
> - private class PopulationBasedAlgorithmWrapper implements Comparable {
> - private final PopulationBasedAlgorithm algorithm;
> -
> - public PopulationBasedAlgorithmWrapper(PopulationBasedAlgorithm
> algorithm) { - this.algorithm = algorithm;
> - }
> -
> - public PopulationBasedAlgorithm get() {
> - return algorithm;
> - }
> -
> - @Override
> - public int compareTo(Object o) {
> - return 0;
> - }
> - }
> -
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelS
>election.java
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelS
>election.java index 8b4bf1f..e0205e8 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelS
>election.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelS
>election.java @@ -22,7 +22,6 @@
> package net.sourceforge.cilib.util.selection.recipes;
>
> import java.util.Collection;
> -import java.util.List;
> import net.sourceforge.cilib.math.random.generator.MersenneTwister;
> import net.sourceforge.cilib.math.random.generator.Random;
> import net.sourceforge.cilib.util.selection.Selection;
> @@ -73,7 +72,7 @@ public class RouletteWheelSelection<E extends Comparable>
> implements SelectionRe
>
> @Override
> public E select(Collection<? extends E> elements) {
> - E selection =
> Selection.from(elements).weigh(this.weighing).orderBy(new
> ProportionalOrdering<E>(this.random)).first().singleSelect(); + E
> selection = Selection.from(elements).weigh(this.weighing).orderBy(new
> ProportionalOrdering<E>(this.random)).last().singleSelect(); return
> selection;
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSele
>ction.java
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSele
>ction.java index f030665..093e569 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSele
>ction.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSele
>ction.java @@ -28,6 +28,7 @@ import
> net.sourceforge.cilib.controlparameter.ProportionalControlParameter; import
> net.sourceforge.cilib.math.random.generator.MersenneTwister; import
> net.sourceforge.cilib.math.random.generator.Random;
> import net.sourceforge.cilib.util.selection.Selection;
> +import net.sourceforge.cilib.util.selection.Selection.Entry;
> import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
> import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
> import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
> @@ -40,7 +41,7 @@ public class TournamentSelection<E extends Comparable>
> implements SelectionRecip private static final long serialVersionUID =
> -6689673224380247931L;
>
> private ControlParameter tournamentProportion;
> - private Comparator<E> comparator;
> + private Comparator<Entry<E>> comparator;
> private Random random;
>
> public TournamentSelection() {
> @@ -68,11 +69,11 @@ public class TournamentSelection<E extends Comparable>
> implements SelectionRecip this.tournamentProportion = tournamanetSize;
> }
>
> - public void setComparator(Comparator<E> comparator) {
> + public void setComparator(Comparator<Entry<E>> comparator) {
> this.comparator = comparator;
> }
>
> - public Comparator<E> getComparator() {
> + public Comparator<Entry<E>> getComparator() {
> return this.comparator;
> }
>
> @@ -80,6 +81,6 @@ public class TournamentSelection<E extends Comparable>
> implements SelectionRecip public E select(Collection<? extends E> elements)
> {
> int tournamentSize =
> Double.valueOf(this.tournamentProportion.getParameter() *
> elements.size()).intValue(); return Selection.from(elements).orderBy(new
> RandomOrdering<E>(this.random)). -
> first(tournamentSize).orderBy(new
> SortedOrdering<E>(this.comparator)).first().select().get(0); +
> last(tournamentSize).orderBy(new
> SortedOrdering<E>(this.comparator)).last().select().get(0); }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing
>.java
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing
>.java index 5152de4..7a6a217 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing
>.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing
>.java @@ -28,7 +28,7 @@ import
> net.sourceforge.cilib.util.selection.Selection; * @author Wiehann Matthysen
> * @param <E>
> */
> -public class FixedWeighing<E extends Comparable> implements Weighing<E> {
> +public class FixedWeighing<E> implements Weighing<E> {
> private static final long serialVersionUID = -6990220691744842964L;
>
> private double weight;
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighin
>g.java
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighin
>g.java index 21d1adc..64ce536 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighin
>g.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighin
>g.java @@ -28,7 +28,7 @@ import
> net.sourceforge.cilib.util.selection.Selection; * @author Wiehann Matthysen
> * @param <E>
> */
> -public class LinearWeighing<E extends Comparable> implements Weighing<E> {
> +public class LinearWeighing<E> implements Weighing<E> {
> private static final long serialVersionUID = 3294682425241945584L;
>
> private double min;
> @@ -37,7 +37,7 @@ public class LinearWeighing<E extends Comparable>
> implements Weighing<E> { public LinearWeighing() {
> this(0.0, 1.0);
> }
> -
> +
> public LinearWeighing(double min, double max) {
> this.min = min;
> this.max = max;
> @@ -76,7 +76,6 @@ public class LinearWeighing<E extends Comparable>
> implements Weighing<E> { for (Selection.Entry<E> element : elements) {
> element.setWeight(objectIndex++ * stepSize + this.min);
> }
> -
> return true;
> }
> }
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
> index 158f931..9fd703d 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
> +++
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
> @@ -29,7 +29,7 @@ import net.sourceforge.cilib.util.selection.Selection; *
> @author Wiehann Matthysen
> * @param <E>
> */
> -public interface Weighing<E extends Comparable> extends Cloneable {
> +public interface Weighing<E> extends Cloneable {
>
> @Override
> public Weighing<E> getClone();
> diff --git
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>Weighing.java
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>Weighing.java index 0feb33c..05ec7e7 100644
> ---
> a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>Weighing.java +++
> b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>Weighing.java @@ -35,8 +35,8 @@ import
> net.sourceforge.cilib.util.selection.Selection; * @param <E>
> */
> public class EntityWeighing<E extends Entity> implements Weighing<E> {
> - private static final long serialVersionUID = 5906567326258195932L;
>
> + private static final long serialVersionUID = 5906567326258195932L;
> private EntityFitness<E> entityFitness;
>
> public EntityWeighing(EntityFitness<E> entityFitness) {
> @@ -63,7 +63,7 @@ public class EntityWeighing<E extends Entity> implements
> Weighing<E> { if (minMaxFitness.getKey() == InferiorFitness.instance() ||
> fitness.compareTo(minMaxFitness.getKey()) < 0) {
> minMaxFitness.setKey(fitness);
> }
> - else if (minMaxFitness.getValue() ==
> InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getValue()) >
> 0) { + if (minMaxFitness.getValue() ==
> InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getValue()) >
> 0) { minMaxFitness.setValue(fitness);
> }
> }
> @@ -72,7 +72,6 @@ public class EntityWeighing<E extends Entity> implements
> Weighing<E> {
>
> @Override
> public boolean weigh(List<Selection.Entry<E>> entities) {
> -// List<Pair<Double, E>> weighedEntities = new
> ArrayList<Pair<Double, E>>(entities.size()); Pair<Fitness, Fitness>
> minMaxFitness = getMinMaxFitness(entities);
>
> if (minMaxFitness.getKey() == InferiorFitness.instance() ||
> @@ -85,7 +84,6 @@ public class EntityWeighing<E extends Entity> implements
> Weighing<E> { for (Selection.Entry<E> entity : entities) {
> double weight =
> (this.entityFitness.getFitness(entity.getElement()).getValue() -
> minMaxFitness.getKey().getValue()) / minMaxDifference;
> entity.setWeight(weight);
> -// weighedEntities.add(new Pair<Double, E>(weight, entity));
> }
>
> return true;
> diff --git
> a/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWh
>eelSelectionStrategyTest.java
> b/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWh
>eelSelectionStrategyTest.java index 4b69fc7..d030f6d 100644
> ---
> a/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWh
>eelSelectionStrategyTest.java +++
> b/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWh
>eelSelectionStrategyTest.java @@ -23,7 +23,6 @@
> */
> package net.sourceforge.cilib.entity.operators.selection;
>
> -
> import junit.framework.Assert;
> import net.sourceforge.cilib.ec.Individual;
> import net.sourceforge.cilib.entity.Entity;
> @@ -34,7 +33,6 @@ import net.sourceforge.cilib.problem.MaximisationFitness;
>
> import net.sourceforge.cilib.problem.MinimisationFitness;
> import org.junit.Before;
> -import org.junit.Ignore;
> import org.junit.Test;
>
> /**
> @@ -48,7 +46,7 @@ import org.junit.Test;
> * </p>
> */
> public class RouletteWheelSelectionStrategyTest {
> -
> +
> private Topology<Individual> topology;
> private Individual individual1;
> private Individual individual2;
> @@ -57,7 +55,7 @@ public class RouletteWheelSelectionStrategyTest {
> @Before
> public void createDummyTopology() {
> topology = new GBestTopology<Individual>();
> -
> +
> individual1 = new Individual();
> individual2 = new Individual();
> individual3 = new Individual();
> @@ -83,20 +81,19 @@ public class RouletteWheelSelectionStrategyTest {
>
> Assert.assertNotNull(entity);
> Assert.assertTrue(topology.contains(entity));
> - Assert.assertEquals(entity, individual3);
> + Assert.assertSame(entity, individual3);
> }
>
> @Test
> public void maximizationSelection() {
> - individual1.getProperties().put(EntityType.FITNESS, new
> MaximisationFitness(90000.0)); // Should be the best entity -
> individual2.getProperties().put(EntityType.FITNESS, new
> MaximisationFitness(0.5)); +
> individual1.getProperties().put(EntityType.FITNESS, new
> MaximisationFitness(0.5)); +
> individual2.getProperties().put(EntityType.FITNESS, new
> MaximisationFitness(90000.0)); // Should be the best entity
> individual3.getProperties().put(EntityType.FITNESS, new
> MaximisationFitness(0.5));
>
> RouletteWheelSelectionStrategy rouletteWheelSelectionStrategy =
> new RouletteWheelSelectionStrategy(); Entity entity =
> rouletteWheelSelectionStrategy.select(topology);
>
> Assert.assertNotNull(entity);
> - Assert.assertTrue(entity.equals(individual1));
> + Assert.assertTrue(entity.equals(individual2));
> }
> -
> }
> diff --git
> a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.
>java
> b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.
>java index 5dc48e3..6bdc981 100644
> ---
> a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.
>java +++
> b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.
>java @@ -52,7 +52,6 @@ public class OrderingTest {
> List<Selection.Entry<Integer>> entries =
> Selection.from(elements).entries(); boolean ordered = new
> ReverseOrdering<Integer>().order(entries); Assert.assertTrue(ordered);
> -
> for (int i = 0; i < 9; ++i) {
> Assert.assertEquals(elements.size() - i,
> entries.get(i).getElement().intValue()); }
> @@ -64,7 +63,6 @@ public class OrderingTest {
> List<Selection.Entry<Integer>> entries =
> Selection.from(elements).entries(); boolean ordered = new
> RingBasedOrdering<Integer>(5).order(entries); Assert.assertTrue(ordered);
> - System.out.println("entries: " + entries);
> Assert.assertEquals(6, entries.get(0).getElement().intValue());
> Assert.assertEquals(7, entries.get(1).getElement().intValue());
> Assert.assertEquals(8, entries.get(2).getElement().intValue());
> @@ -75,7 +73,7 @@ public class OrderingTest {
> Assert.assertEquals(4, entries.get(7).getElement().intValue());
> Assert.assertEquals(5, entries.get(8).getElement().intValue());
> }
> -
> +
> @Test
> public void sortedOrdering() {
> List<Integer> elements = Arrays.asList(9, 8, 7, 6, 5, 4, 3, 2, 1);
> diff --git
> a/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.
>java
> b/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.
>java new file mode 100644
> index 0000000..286b687
> --- /dev/null
> +++
> b/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.
>java @@ -0,0 +1,59 @@
> +/**
> + * 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.weighing;
> +
> +import java.util.Arrays;
> +import java.util.List;
> +import net.sourceforge.cilib.util.selection.Selection;
> +import net.sourceforge.cilib.util.selection.Selection.Entry;
> +import org.junit.Assert;
> +import org.junit.Test;
> +
> +/**
> + * @author Wiehann Matthysen
> + */
> +public class WeighingTest {
> +
> + @Test
> + public void fixedWeighing() {
> + List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
> + List<Entry<Integer>> weighedElements =
> Selection.from(elements).weigh(new FixedWeighing(1.0)).entries(); +
> for (int i = 0; i < weighedElements.size(); ++i) {
> + Assert.assertEquals(1.0, weighedElements.get(i).getWeight(),
> 0.0001); + }
> + }
> +
> + @Test
> + public void linearWeighing() {
> + List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
> + List<Entry<Integer>> weighedElements =
> Selection.from(elements).weigh(new
> LinearWeighing<Integer>(0.0,1.0)).entries(); +
> Assert.assertEquals(0.0, weighedElements.get(0).getWeight(), 0.0001); +
> Assert.assertEquals(0.125, weighedElements.get(1).getWeight(),
> 0.0001); + Assert.assertEquals(0.25,
> weighedElements.get(2).getWeight(), 0.0001); +
> Assert.assertEquals(0.375, weighedElements.get(3).getWeight(), 0.0001); +
> Assert.assertEquals(0.5, weighedElements.get(4).getWeight(),
> 0.0001); + Assert.assertEquals(0.625,
> weighedElements.get(5).getWeight(), 0.0001); +
> Assert.assertEquals(0.75, weighedElements.get(6).getWeight(), 0.0001); +
> Assert.assertEquals(0.875, weighedElements.get(7).getWeight(),
> 0.0001); + Assert.assertEquals(1.0,
> weighedElements.get(8).getWeight(), 0.0001); + }
> +}
> diff --git
> a/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>WeighingTest.java
> b/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>WeighingTest.java index c2d0c7a..f8d23ef 100644
> ---
> a/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>WeighingTest.java +++
> b/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/Entity
>WeighingTest.java @@ -27,6 +27,7 @@ import
> net.sourceforge.cilib.ec.Individual;
> import net.sourceforge.cilib.entity.EntityType;
> import net.sourceforge.cilib.problem.Fitness;
> import net.sourceforge.cilib.problem.MaximisationFitness;
> +import net.sourceforge.cilib.problem.MinimisationFitness;
> import net.sourceforge.cilib.util.selection.Selection;
> import net.sourceforge.cilib.util.selection.Selection.Entry;
> import org.junit.Assert;
> @@ -38,7 +39,7 @@ import org.junit.Test;
> public class EntityWeighingTest {
>
> @Test
> - public void entityWeighing() {
> + public void entityWeighingMaximise() {
> Individual i1 = createIndividual(new MaximisationFitness(1.0));
> Individual i2 = createIndividual(new MaximisationFitness(2.0));
> Individual i3 = createIndividual(new MaximisationFitness(3.0));
> @@ -53,6 +54,22 @@ public class EntityWeighingTest {
> Assert.assertEquals(1.0, entries.get(2).getWeight(), 0.0001);
> }
>
> + @Test
> + public void entityWeighingMinimise() {
> + Individual i1 = createIndividual(new MinimisationFitness(1.0));
> + Individual i2 = createIndividual(new MinimisationFitness(2.0));
> + Individual i3 = createIndividual(new MinimisationFitness(3.0));
> +
> + List<Individual> individuals = Arrays.asList(i1, i2, i3);
> + List<Selection.Entry<Individual>> entries =
> Selection.from(individuals).entries(); + EntityWeighing<Individual>
> weighing = new EntityWeighing<Individual>(); +
> weighing.weigh(entries);
> +
> + Assert.assertEquals(1.0, entries.get(0).getWeight(), 0.0001);
> + Assert.assertEquals(0.5, entries.get(1).getWeight(), 0.0001);
> + Assert.assertEquals(0.0, entries.get(2).getWeight(), 0.0001);
> + }
> +
> private Individual createIndividual(Fitness fitness) {
> Individual i = new Individual();
> i.getProperties().put(EntityType.FITNESS, fitness);
> diff --git a/xml/dynamic-vepso.xml b/xml/dynamic-vepso.xml
> index 7d83de6..0fc7941 100644
> --- a/xml/dynamic-vepso.xml
> +++ b/xml/dynamic-vepso.xml
> @@ -16,9 +16,7 @@
> <globalGuideSelectionStrategy
> class="pso.moo.guideselectionstrategies.VEPSOGuideSelectionStrategy">
> <knowledgeTransferStrategy
> class="algorithm.population.knowledgetransferstrategies.SelectiveKnowledgeT
>ransferStrategy"> <populationSelection
> class="util.selection.recipes.RingBasedPopulationSelection"/> -
> <entitySelection
> class="util.selection.recipes.TournamentSelection"> -
> <comparator
> class="entity.comparator.DescendingFitnessComparator"/> -
> </entitySelection>
> + <entitySelection
> class="util.selection.recipes.TournamentSelection"/>
> </knowledgeTransferStrategy>
> </globalGuideSelectionStrategy>
> <globalGuideUpdateStrategy
> class="pso.moo.guideupdatestrategies.StandardGuideUpdateStrategy"/> diff
> --git a/xml/vepso.xml b/xml/vepso.xml
> index a56d454..58f41c9 100644
> --- a/xml/vepso.xml
> +++ b/xml/vepso.xml
> @@ -15,9 +15,7 @@
> <globalGuideSelectionStrategy
> class="pso.moo.guideselectionstrategies.VEPSOGuideSelectionStrategy">
> <knowledgeTransferStrategy
> class="algorithm.population.knowledgetransferstrategies.SelectiveKnowledgeT
>ransferStrategy"> <populationSelection
> class="util.selection.recipes.RingBasedPopulationSelection"/> -
> <entitySelection
> class="util.selection.recipes.TournamentSelection"> -
> <comparator
> class="entity.comparator.DescendingFitnessComparator"/> -
> </entitySelection>
> + <entitySelection
> class="util.selection.recipes.TournamentSelection"/>
> </knowledgeTransferStrategy>
> </globalGuideSelectionStrategy>
> <globalGuideUpdateStrategy
> class="pso.moo.guideupdatestrategies.StandardGuideUpdateStrategy"/>
|
|
From: Wiehann M. <wcm...@gm...> - 2009-05-23 02:44:50
|
This patch-set is the collection of patches that Gary and I worked on the last couple of days. It defines the new selection EDSL specification as well as utility classes (called recipes) that can be conveniently used in XML to achieve Tournament selection, Roulette Wheel Selection, Random Selection, Rank-based Selection and Ring-based Selection. |
|
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] |
|
From: Wiehann M. <wcm...@gm...> - 2009-05-23 00:47:37
|
From: Gary Pampara <gpa...@gm...>
I'll wait for you to look at this first before applying to 'next'
---
.../selection/ElitistSelectionStrategy.java | 2 +-
.../solutionweighing/AntiClusterWeighing.java | 30 ++--
.../archive/solutionweighing/SolutionWeighing.java | 10 +-
.../cilib/util/selection/OrderingSyntax.java | 33 ----
.../cilib/util/selection/Selection.java | 159 +++++++++++++++++---
.../cilib/util/selection/SelectionSyntax.java | 12 ++-
.../cilib/util/selection/WeighedSelection.java | 102 -------------
.../cilib/util/selection/WeighingSyntax.java | 34 ----
.../cilib/util/selection/ordering/Ordering.java | 5 +-
.../selection/ordering/ProportionalOrdering.java | 16 +-
.../util/selection/ordering/RandomOrdering.java | 6 +-
.../util/selection/ordering/ReverseOrdering.java | 5 +-
.../util/selection/ordering/RingBasedOrdering.java | 27 +++-
.../util/selection/ordering/SortedOrdering.java | 5 +-
.../util/selection/recipes/ElitistSelection.java | 2 +-
.../util/selection/recipes/RandomSelection.java | 4 +-
.../util/selection/recipes/RankBasedSelection.java | 2 +-
.../recipes/RingBasedPopulationSelection.java | 30 ++++-
.../selection/recipes/RouletteWheelSelection.java | 4 +-
.../selection/recipes/TournamentSelection.java | 4 +-
.../util/selection/weighing/FixedWeighing.java | 23 ++--
.../util/selection/weighing/LinearWeighing.java | 23 ++--
.../cilib/util/selection/weighing/Weighing.java | 6 +-
.../selection/weighing/entity/EntityWeighing.java | 23 ++--
.../RouletteWheelSelectionStrategyTest.java | 3 +-
.../solutionweighing/SolutionWeighingTest.java | 22 ++--
.../util/selection/ordering/OrderingTest.java | 37 +++--
.../selection/recipes/SelectionRecipeTest.java | 2 +-
.../util/selection/weighing/WeighingTest.java | 59 -------
.../weighing/entity/EntityWeighingTest.java | 13 +-
30 files changed, 331 insertions(+), 372 deletions(-)
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/WeighedSelection.java
delete mode 100644 src/main/java/net/sourceforge/cilib/util/selection/WeighingSyntax.java
delete mode 100644 src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.java
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 2a2cea5..29fe94f 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
@@ -60,7 +60,7 @@ public class ElitistSelectionStrategy extends SelectionStrategy {
*/
@Override
public <T extends Entity> T select(Topology<T> population) {
- return new ElitistSelection<T>(new DescendingFitnessComparator<T>()).select(population);
+ return new ElitistSelection<T>().select(population);
}
/**
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
index 184cf5a..ce39f43 100644
--- a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/AntiClusterWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/AntiClusterWeighing.java
@@ -21,16 +21,16 @@
*/
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;
+import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
/**
* <p>
@@ -64,11 +64,11 @@ public class AntiClusterWeighing implements SolutionWeighing {
}
@Override
- public List<Pair<Double, OptimisationSolution>> weigh(List<OptimisationSolution> solutions) {
+ public boolean weigh(List<Selection.Entry<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();
+ Iterator<? extends Entry<OptimisationSolution>> solutionIterator = solutions.iterator();
+ MOFitness tempFitness = (MOFitness) solutionIterator.next().getElement().getFitness();
Fitness[] minFitnesses = new Fitness[tempFitness.getDimension()];
Fitness[] maxFitnesses = new Fitness[tempFitness.getDimension()];
for (int i = 0; i < tempFitness.getDimension(); ++i) {
@@ -78,8 +78,8 @@ public class AntiClusterWeighing implements SolutionWeighing {
// 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();
+ Entry<OptimisationSolution> optimisationSolution = solutionIterator.next();
+ MOFitness fitnesses = (MOFitness) optimisationSolution.getElement().getFitness();
for (int i = 0; i < fitnesses.getDimension(); ++i) {
Double fitnessValue = fitnesses.getFitness(i).getValue();
if (fitnessValue < minFitnesses[i].getValue()) {
@@ -92,14 +92,14 @@ public class AntiClusterWeighing implements SolutionWeighing {
// 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) {
+// List<Pair<Double, OptimisationSolution>> weighedOptimisationSolutions = new ArrayList<Pair<Double, OptimisationSolution>>();
+ for (Selection.Entry<OptimisationSolution> fromSolution : solutions) {
double totalDistance = 0.0;
- MOFitness fromFitnesses = (MOFitness) fromSolution.getFitness();
- for (OptimisationSolution toSolution : solutions) {
+ MOFitness fromFitnesses = (MOFitness) fromSolution.getElement().getFitness();
+ for (Selection.Entry<OptimisationSolution> toSolution : solutions) {
if (fromSolution != toSolution) {
double distance = 0.0;
- MOFitness toFitnesses = (MOFitness) toSolution.getFitness();
+ MOFitness toFitnesses = (MOFitness) toSolution.getElement().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);
@@ -107,9 +107,11 @@ public class AntiClusterWeighing implements SolutionWeighing {
totalDistance += Math.sqrt(distance);
}
}
- weighedOptimisationSolutions.add(new Pair<Double, OptimisationSolution>((totalDistance != 0.0) ? 1.0 / totalDistance : Double.MAX_VALUE, fromSolution));
+ fromSolution.setWeight((totalDistance != 0.0) ? 1.0 / totalDistance : Double.MAX_VALUE);
+// weighedOptimisationSolutions.add(new Pair<Double, OptimisationSolution>((totalDistance != 0.0) ? 1.0 / totalDistance : Double.MAX_VALUE, fromSolution));
}
- return weighedOptimisationSolutions;
+// return weighedOptimisationSolutions;
+ return true;
}
}
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
index 39f509d..b46b8ba 100644
--- a/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighing.java
@@ -4,17 +4,17 @@
* 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
@@ -23,10 +23,10 @@ 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;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* <p>
@@ -42,5 +42,5 @@ public interface SolutionWeighing extends Weighing<OptimisationSolution>, Clonea
public abstract SolutionWeighing getClone();
@Override
- public List<Pair<Double, OptimisationSolution>> weigh(List<OptimisationSolution> elements);
+ public boolean weigh(List<Selection.Entry<OptimisationSolution>> elements);
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java b/src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java
deleted file mode 100644
index de29db5..0000000
--- a/src/main/java/net/sourceforge/cilib/util/selection/OrderingSyntax.java
+++ /dev/null
@@ -1,33 +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.util.selection;
-
-import net.sourceforge.cilib.util.selection.ordering.Ordering;
-
-/**
- * @author Wiehann Matthysen
- * @param <E>
- */
-public interface OrderingSyntax<E> {
-
- public SelectionSyntax<E> apply(Ordering<E> ordering);
-}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
index bdad64b..f4ac2f1 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
@@ -24,7 +24,6 @@ package net.sourceforge.cilib.util.selection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import net.sourceforge.cilib.container.Pair;
import net.sourceforge.cilib.util.selection.ordering.Ordering;
import net.sourceforge.cilib.util.selection.weighing.Weighing;
@@ -43,8 +42,8 @@ import net.sourceforge.cilib.util.selection.weighing.Weighing;
* would be done as follows:
* </p>
* <pre>
- * List<T> selection = Selection.from(population).apply(new RandomOrdering<T>()).first(tournamentSize)
- * .apply(new SortedOrdering<T>()).last().select();
+ * List<T> selection = Selection.from(population).orderBy(new RandomOrdering<T>()).first(tournamentSize)
+ * .orderBy(new SortedOrdering<T>()).last().select();
*
* return selection.get(0);
* </pre>
@@ -60,9 +59,9 @@ import net.sourceforge.cilib.util.selection.weighing.Weighing;
* @param <E> The comparable type.
* @author gpampara
*/
-public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>, WeighingSyntax<E> {
+public final class Selection<E extends Comparable> implements SelectionSyntax<E> {
- private List<E> elements;
+ private List<Entry<E>> elements;
/**
* Assign the Selection to take palce on the porvided collection. The
@@ -71,7 +70,10 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
* @param elements The elements on which the selection should take place.
*/
private Selection(Collection<? extends E> elements) {
- this.elements = new ArrayList(elements);
+ this.elements = new ArrayList<Entry<E>>(elements.size());
+
+ for (E element : elements)
+ this.elements.add(new Entry<E>(element));
}
/**
@@ -80,24 +82,23 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
* @param elements The collection of elements to operate on.
* @return A selection based on the provided collection.
*/
- public static <T> Selection<T> from(Collection<? extends T> elements) {
+ public static <T extends Comparable> Selection<T> from(Collection<? extends T> elements) {
return new Selection<T>(elements);
}
/**
* Apply the provided ordering on the current selection. The result of the
* operation will result in a modified selection.
- * @param ordering The ordering to apply.
+ * @param ordering The ordering to orderBy.
* @return A selection upon which the ordering has be applied.
* @throws UnsupportedOperationException if the ordering cannot be applied.
*/
@Override
- public Selection<E> apply(Ordering<E> ordering) {
+ public SelectionSyntax<E> orderBy(Ordering<E> ordering) {
boolean result = ordering.order(this.elements);
- if (result) {
+ if (result)
return this;
- }
throw new UnsupportedOperationException("The ordering [" + ordering.getClass().getSimpleName() + "] " +
"cannot be applied to the selection. Please ensure that the intention of the ordering is correct.");
@@ -106,13 +107,18 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
/**
* Apply the provided weighing on the current selection. The result of the
* operation will result in new weighed selection.
- * @param weighing The weighing to apply.
+ * @param weighing The weighing to orderBy.
* @return A selection upon which the weighing has be applied.
*/
@Override
- public WeighedSelection<E> apply(Weighing<E> weighing) {
- List<Pair<Double, E>> weighedElements = weighing.weigh(this.elements);
- return new WeighedSelection<E>(weighedElements);
+ public SelectionSyntax<E> weigh(Weighing<E> weighing) {
+ boolean result = weighing.weigh(this.elements);
+
+ if (result)
+ return this;
+
+ throw new UnsupportedOperationException("The weighing [" + weighing.getClass().getSimpleName() + "]" +
+ "cannot be applied to the selection. Please ensure that the intention of the weighing is correct.");
}
/**
@@ -121,7 +127,7 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
* @return A selection containing the first element.
*/
@Override
- public Selection<E> first() {
+ public SelectionSyntax<E> first() {
this.elements = this.elements.subList(0, 1);
return this;
}
@@ -133,7 +139,7 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
* @return A selection containing the first {@code number} elements.
*/
@Override
- public Selection<E> first(int number) {
+ public SelectionSyntax<E> first(int number) {
this.elements = this.elements.subList(0, number);
return this;
}
@@ -143,7 +149,7 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
* @return A selection containing the last element.
*/
@Override
- public Selection<E> last() {
+ public SelectionSyntax<E> last() {
this.elements = this.elements.subList(this.elements.size() - 1, this.elements.size());
return this;
}
@@ -154,7 +160,7 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
* @return A selection containing the last {@code number} of elements.
*/
@Override
- public Selection<E> last(int number) {
+ public SelectionSyntax<E> last(int number) {
this.elements = this.elements.subList(this.elements.size() - number, this.elements.size());
return this;
}
@@ -165,6 +171,121 @@ public final class Selection<E> implements SelectionSyntax<E>, OrderingSyntax<E>
*/
@Override
public List<E> select() {
+ List<E> result = new ArrayList<E>();
+
+ for (Entry<E> entry : elements)
+ result.add(entry.getElement());
+
+ return result;
+ }
+
+ @Override
+ public E singleSelect() {
+ return this.elements.get(0).getElement();
+ }
+
+ @Override
+ public List<Selection.Entry<E>> entries() {
return this.elements;
}
+
+
+ /**
+ * This class provides the notion of an entry within a list
+ * for the selection process.
+ * <p>
+ * This class is is final and non-instantiable to ensure that the
+ * operations are allowed to be applied, however, additional metadata
+ * can be recored and used during the selection process.
+ * @param <E> The {@see Comparable} type.
+ */
+ public final static class Entry<E extends Comparable> implements Comparable {
+ private final E element;
+ private double weight;
+
+ /**
+ * Create a new {@code Entry}. This constructor is private intentionall
+ * @param element The element to decorate. + */
+ private Entry(E element) {
+ this.element = element;
+ this.weight = 0.0;
+ }
+
+ /**
+ * Get the {@code element} that this {@code Entry} represents.
+ * @return The decorated {@code element}.
+ */
+ public E getElement() {
+ return element;
+ }
+
+ /**
+ * Obtain the weight value associated with this {@code Entry}.
+ * <p>
+ * The weight value need not be set. It is not always used.
+ *
+ * @return The {@code weight} value.
+ */
+ public double getWeight() {
+ return this.weight;
+ }
+
+ /**
+ * Set the {@code weight} value for the current {@code Entry}
+ * within the {@code Selection}.
+ * @param weight The {@code weight} value to set.
+ */
+ public void setWeight(double weight) {
+ this.weight = weight;
+ }
+
+ /**
+ * Determine if the provided {@code obj} is equal to the currently
+ * decorated element within this {@code Entry}.
+ * @param obj The object instance to compare.
+ * @return {@code true} if the objects are equal, {@code false} otherwi
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+
+ if ((obj == null) || (this.getClass() != obj.getClass()))
+ return false;
+
+ Entry<E> other = (Entry<E>) obj;
+ return this.element.equals(other.element);
+ }
+
+ /**
+ * Obtain the hash of the decorated {@code element}.
+ * @return The decorated instance's hash value.
+ */
+ @Override
+ public int hashCode() {
+ return element.hashCode();
+ }
+
+ /**
+ * Obtain the {@code String} of the decorated {@code element}.
+ * @return The {@code toString()} of the decorated element.
+ */
+ @Override
+ public String toString() {
+ return this.element.toString();
+ }
+
+ /**
+ * Compare the current decorated {@code element} with the provided
+ * object instance.
+ * @param o The instance to test.
+ * @return {@code 0} if equal, {@code -1} if the current element
+ * is less than the provided instance, {@code 1} otherwise.
+ */
+ @Override
+ public int compareTo(Object o) {
+ Entry<E> other = (Entry<E>) o;
+ return this.element.compareTo(other.element);
+ }
+ }
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
index 846a186..3ba5613 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
@@ -22,12 +22,18 @@
package net.sourceforge.cilib.util.selection;
import java.util.List;
+import net.sourceforge.cilib.util.selection.ordering.Ordering;
+import net.sourceforge.cilib.util.selection.weighing.Weighing;
/**
* @author Wiehann Matthysen
* @param <E>
*/
-public interface SelectionSyntax<E> {
+public interface SelectionSyntax<E extends Comparable> {
+
+ public SelectionSyntax<E> orderBy(Ordering<E> ordering);
+
+ public SelectionSyntax<E> weigh(Weighing<E> weighing);
public SelectionSyntax<E> first();
@@ -38,4 +44,8 @@ public interface SelectionSyntax<E> {
public SelectionSyntax<E> last(int number);
public List<E> select();
+
+ List<Selection.Entry<E>> entries();
+
+ E singleSelect();
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/WeighedSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/WeighedSelection.java
deleted file mode 100644
index 788c2d4..0000000
--- a/src/main/java/net/sourceforge/cilib/util/selection/WeighedSelection.java
+++ /dev/null
@@ -1,102 +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.util.selection;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import net.sourceforge.cilib.container.Pair;
-import net.sourceforge.cilib.util.selection.ordering.Ordering;
-import net.sourceforge.cilib.util.selection.weighing.Weighing;
-
-/**
- * @author Wiehann Matthysen
- * @param <E>
- */
-public final class WeighedSelection<E>
- implements SelectionSyntax<Pair<Double, E>>, OrderingSyntax<Pair<Double, E>>, WeighingSyntax<E> {
-
- private List<Pair<Double, E>> elements;
-
- protected WeighedSelection(Collection<Pair<Double, E>> elements) {
- this.elements = new ArrayList<Pair<Double, E>>(elements);
- }
-
- public static <T> List<T> unpack(Collection<Pair<Double, T>> elements) {
- List<T> unpackedElements = new ArrayList<T>(elements.size());
- for (Pair<Double, T> element : elements) {
- unpackedElements.add(element.getValue());
- }
- return unpackedElements;
- }
-
- @Override
- public WeighedSelection<E> apply(Ordering<Pair<Double, E>> ordering) {
- boolean result = ordering.order(this.elements);
-
- if (result) {
- return this;
- }
-
- throw new UnsupportedOperationException("The ordering [" + ordering.getClass().getSimpleName() + "] " +
- "cannot be applied to the selection. Please ensure that the intention of the ordering is correct.");
- }
-
- @Override
- public WeighedSelection<E> apply(Weighing<E> weighing) {
- this.elements = weighing.weigh(unpack(this.elements));
- return this;
- }
-
- @Override
- public WeighedSelection<E> first() {
- this.elements = this.elements.subList(0, 1);
- return this;
- }
-
- @Override
- public WeighedSelection<E> first(int number) {
- this.elements = this.elements.subList(0, number);
- return this;
- }
-
- @Override
- public WeighedSelection<E> last() {
- this.elements = this.elements.subList(this.elements.size() - 1, this.elements.size());
- return this;
- }
-
- @Override
- public WeighedSelection<E> last(int number) {
- this.elements = this.elements.subList(this.elements.size() - number, this.elements.size());
- return this;
- }
-
- @Override
- public List<Pair<Double, E>> select() {
- return this.elements;
- }
-
- public List<E> selectOriginal() {
- return unpack(this.elements);
- }
-}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/WeighingSyntax.java b/src/main/java/net/sourceforge/cilib/util/selection/WeighingSyntax.java
deleted file mode 100644
index 80abb79..0000000
--- a/src/main/java/net/sourceforge/cilib/util/selection/WeighingSyntax.java
+++ /dev/null
@@ -1,34 +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.util.selection;
-
-import net.sourceforge.cilib.container.Pair;
-import net.sourceforge.cilib.util.selection.weighing.Weighing;
-
-/**
- * @author Wiehann Matthysen
- * @param <E>
- */
-public interface WeighingSyntax<E> {
-
- public SelectionSyntax<Pair<Double, E>> apply(Weighing<E> weighing);
-}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
index 631fc79..00f6b0d 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
@@ -22,6 +22,7 @@
package net.sourceforge.cilib.util.selection.ordering;
import java.util.List;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* An ordering is a construct to define how a list of elements should be ordered.
@@ -29,12 +30,12 @@ import java.util.List;
* @param <E> The type to apply the ordering to.
* @author gpampara
*/
-public interface Ordering<E> {
+public interface Ordering<E extends Comparable> {
/**
* Apply the ordering on the provided list.
* @param elements The list to be ordered.
* @return {@code true} if successful, {@code false} otherwise.
*/
- public boolean order(List<E> elements);
+ public boolean order(List<Selection.Entry<E>> elements);
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java
index 1b326cc..04dd378 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java
@@ -23,14 +23,14 @@ package net.sourceforge.cilib.util.selection.ordering;
import java.util.List;
import java.util.Random;
-import net.sourceforge.cilib.container.Pair;
import net.sourceforge.cilib.math.random.generator.MersenneTwister;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* @author Wiehann Matthysen
* @param <E>
*/
-public class ProportionalOrdering<E> implements Ordering<Pair<Double, E>> {
+public class ProportionalOrdering<E extends Comparable> implements Ordering<E> {
private Random generator;
@@ -47,10 +47,10 @@ public class ProportionalOrdering<E> implements Ordering<Pair<Double, E>> {
* @return {@code true} if successful, {@code false} otherwise.
*/
@Override
- public boolean order(List<Pair<Double, E>> elements) {
+ public boolean order(List<Selection.Entry<E>> elements) {
double total = 0.0;
- for (Pair<Double, E> weighedObject : elements) {
- total += weighedObject.getKey();
+ for (Selection.Entry<E> weighedObject : elements) {
+ total += weighedObject.getWeight();
}
if (Double.compare(total, 0.0) == 0) {
@@ -62,11 +62,11 @@ public class ProportionalOrdering<E> implements Ordering<Pair<Double, E>> {
double marker = 0.0;
int j = i;
for (; j < elements.size() - 1 && marker < randomValue; ++j) {
- marker += elements.get(j).getKey();
+ marker += elements.get(j).getWeight();
}
// Swap elements i and j.
- Pair<Double, E> elementJ = elements.set(j, elements.set(i, elements.get(j)));
- total -= elementJ.getKey();
+ Selection.Entry<E> elementJ = elements.set(j, elements.set(i, elements.get(j)));
+ total -= elementJ.getWeight();
}
return true;
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java
index e8f3d84..202a962 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java
@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Random;
import net.sourceforge.cilib.math.random.generator.MersenneTwister;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* Apply a random ordering to the provided list. This class defines that the
@@ -32,7 +33,7 @@ import net.sourceforge.cilib.math.random.generator.MersenneTwister;
* @param <E> The comparable type.
* @author gpampara
*/
-public class RandomOrdering<E> implements Ordering<E> {
+public class RandomOrdering<E extends Comparable> implements Ordering<E> {
private Random generator;
@@ -50,8 +51,9 @@ public class RandomOrdering<E> implements Ordering<E> {
* @return {@code true} if successful, {@code false} otherwise.
*/
@Override
- public boolean order(List<E> elements) {
+ public boolean order(List<Selection.Entry<E>> elements) {
Collections.shuffle(elements, this.generator);
return true;
}
+
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java
index 3222874..6a85fae 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java
@@ -23,15 +23,16 @@ package net.sourceforge.cilib.util.selection.ordering;
import java.util.Collections;
import java.util.List;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* @author Wiehann Matthysen
* @param <E>
*/
-public class ReverseOrdering<E> implements Ordering<E> {
+public class ReverseOrdering<E extends Comparable> implements Ordering<E> {
@Override
- public boolean order(List<E> elements) {
+ public boolean order(List<Selection.Entry<E>> elements) {
Collections.reverse(elements);
return true;
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java
index cd6482b..8927f8a 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java
@@ -23,33 +23,44 @@ package net.sourceforge.cilib.util.selection.ordering;
import java.util.ArrayList;
import java.util.List;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* @author Wiehann Matthysen
* @param <E>
*/
-public class RingBasedOrdering<E> implements Ordering<E> {
+public class RingBasedOrdering<E extends Comparable> implements Ordering<E> {
private E marker;
- public RingBasedOrdering(E marker) {
- this.marker = marker;
- }
-
public RingBasedOrdering() {
this.marker = null;
}
+ public RingBasedOrdering(E marker) {
+ this.marker = marker;
+ }
+
/**
* @param elements
* @return {@code true} if successful, {@code false} otherwise.
*/
@Override
- public boolean order(List<E> elements) {
- List<E> temp = new ArrayList<E>(elements);
+ public boolean order(List<Selection.Entry<E>> elements) {
+ List<Selection.Entry<E>> tmp = new ArrayList<Selection.Entry<E>>(elements);
+
+ int position = 0;
+ for (Selection.Entry<E> entry : elements) {
+ if (this.marker.compareTo(entry.getElement()) == 0)
+ break;
+
+ position++;
+ }
+
for (int i = 0; i < elements.size(); ++i) {
- elements.set(i, temp.get((temp.indexOf(this.marker) + 1 + i) % elements.size()));
+ elements.set(i, tmp.get((position + 1 + i) % elements.size()));
}
+
return true;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java
index 813f88e..e080c07 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java
@@ -24,6 +24,7 @@ package net.sourceforge.cilib.util.selection.ordering;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* Apply a sorting operation to the provided list, ordering the list naturally
@@ -49,8 +50,8 @@ public class SortedOrdering<E extends Comparable> implements Ordering<E> {
* @return {@code true} if successful, {@code false} otherwise.
*/
@Override
- public boolean order(List<E> element) {
- Collections.sort(element, this.comparator);
+ public boolean order(List<Selection.Entry<E>> element) {
+ Collections.sort(element);
return true;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java
index 166bea2..2e92e16 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java
@@ -64,7 +64,7 @@ public class ElitistSelection<E extends Comparable> implements SelectionRecipe<E
@Override
public E select(Collection<? extends E> elements) {
- List<E> selection = Selection.from(elements).apply(new SortedOrdering(this.comparator)).first().select();
+ List<E> selection = Selection.from(elements).orderBy(new SortedOrdering(this.comparator)).last().select();
return selection.get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java
index 223cb7a..d30d1de 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java
@@ -32,7 +32,7 @@ import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
* @author Wiehann Matthysen
* @param <E>
*/
-public class RandomSelection<E> implements SelectionRecipe<E> {
+public class RandomSelection<E extends Comparable> implements SelectionRecipe<E> {
private static final long serialVersionUID = -5099663528040315048L;
private Random random;
@@ -56,7 +56,7 @@ public class RandomSelection<E> implements SelectionRecipe<E> {
@Override
public E select(Collection<? extends E> elements) {
- List<E> selection = Selection.from(elements).apply(new RandomOrdering<E>(this.random)).first().select();
+ List<E> selection = Selection.from(elements).orderBy(new RandomOrdering<E>(this.random)).first().select();
return selection.get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java
index b8bbe02..75b13bf 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java
@@ -74,7 +74,7 @@ public class RankBasedSelection<E extends Comparable> implements SelectionRecipe
@Override
public E select(Collection<? extends E> elements) {
- List<E> selection = Selection.from(elements).apply(new SortedOrdering<E>(this.comparator)).first(this.random.nextInt(elements.size())).apply(new RandomOrdering<E>(this.random)).first().select();
+ List<E> selection = Selection.from(elements).orderBy(new SortedOrdering<E>(this.comparator)).first(this.random.nextInt(elements.size())).orderBy(new RandomOrdering<E>(this.random)).first().select();
return selection.get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java
index 3eb5ee4..5da4287 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java
@@ -21,7 +21,9 @@
*/
package net.sourceforge.cilib.util.selection.recipes;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import net.sourceforge.cilib.algorithm.Algorithm;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.util.selection.Selection;
@@ -46,7 +48,33 @@ public class RingBasedPopulationSelection implements SelectionRecipe<PopulationB
@Override
public PopulationBasedAlgorithm select(Collection<? extends PopulationBasedAlgorithm> elements) {
- return Selection.from(elements).apply(new RingBasedOrdering<PopulationBasedAlgorithm>((PopulationBasedAlgorithm)Algorithm.get())).first().select().get(0);
+ PopulationBasedAlgorithmWrapper targetPBA = new PopulationBasedAlgorithmWrapper((PopulationBasedAlgorithm)Algorithm.get());
+
+ List<PopulationBasedAlgorithmWrapper> list = new ArrayList<PopulationBasedAlgorithmWrapper>();
+ for (PopulationBasedAlgorithm p : elements) {
+ PopulationBasedAlgorithmWrapper wrapper = new PopulationBasedAlgorithmWrapper(p);
+ list.add(wrapper);
+ }
+
+ PopulationBasedAlgorithmWrapper wrapper = Selection.from(list).orderBy(new RingBasedOrdering<PopulationBasedAlgorithmWrapper>(targetPBA)).first().singleSelect();
+ return wrapper.get();
+ }
+
+ private class PopulationBasedAlgorithmWrapper implements Comparable {
+ private final PopulationBasedAlgorithm algorithm;
+
+ public PopulationBasedAlgorithmWrapper(PopulationBasedAlgorithm algorithm) {
+ this.algorithm = algorithm;
+ }
+
+ public PopulationBasedAlgorithm get() {
+ return algorithm;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ return 0;
+ }
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java
index a344eb1..8b4bf1f 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java
@@ -73,7 +73,7 @@ public class RouletteWheelSelection<E extends Comparable> implements SelectionRe
@Override
public E select(Collection<? extends E> elements) {
- List<E> selection = Selection.from(elements).apply(this.weighing).apply(new ProportionalOrdering<E>(this.random)).first().selectOriginal();
- return selection.get(0);
+ E selection = Selection.from(elements).weigh(this.weighing).orderBy(new ProportionalOrdering<E>(this.random)).first().singleSelect();
+ return selection;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java
index 78621e8..f030665 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java
@@ -79,7 +79,7 @@ public class TournamentSelection<E extends Comparable> implements SelectionRecip
@Override
public E select(Collection<? extends E> elements) {
int tournamentSize = Double.valueOf(this.tournamentProportion.getParameter() * elements.size()).intValue();
- return Selection.from(elements).apply(new RandomOrdering<E>(this.random)).
- first(tournamentSize).apply(new SortedOrdering<E>(this.comparator)).first().select().get(0);
+ return Selection.from(elements).orderBy(new RandomOrdering<E>(this.random)).
+ first(tournamentSize).orderBy(new SortedOrdering<E>(this.comparator)).first().select().get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java
index f06215d..5152de4 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java
@@ -21,27 +21,26 @@
*/
package net.sourceforge.cilib.util.selection.weighing;
-import java.util.ArrayList;
import java.util.List;
-import net.sourceforge.cilib.container.Pair;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* @author Wiehann Matthysen
* @param <E>
*/
-public class FixedWeighing<E> implements Weighing<E> {
+public class FixedWeighing<E extends Comparable> implements Weighing<E> {
private static final long serialVersionUID = -6990220691744842964L;
private double weight;
+ public FixedWeighing() {
+ this(0.0);
+ }
+
public FixedWeighing(double weight) {
this.weight = weight;
}
- public FixedWeighing() {
- this(0.0);
- }
-
public FixedWeighing(FixedWeighing<E> copy) {
this.weight = copy.weight;
}
@@ -60,11 +59,11 @@ public class FixedWeighing<E> implements Weighing<E> {
}
@Override
- public List<Pair<Double, E>> weigh(List<E> elements) {
- List<Pair<Double, E>> weighedElements = new ArrayList<Pair<Double, E>>(elements.size());
- for (E object : elements) {
- weighedElements.add(new Pair<Double, E>(this.weight, object));
+ public boolean weigh(List<Selection.Entry<E>> elements) {
+ for (Selection.Entry<E> object : elements) {
+ object.setWeight(this.weight);
}
- return weighedElements;
+
+ return true;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java
index 673af90..21d1adc 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java
@@ -21,29 +21,28 @@
*/
package net.sourceforge.cilib.util.selection.weighing;
-import java.util.ArrayList;
import java.util.List;
-import net.sourceforge.cilib.container.Pair;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* @author Wiehann Matthysen
* @param <E>
*/
-public class LinearWeighing<E> implements Weighing<E> {
+public class LinearWeighing<E extends Comparable> implements Weighing<E> {
private static final long serialVersionUID = 3294682425241945584L;
private double min;
private double max;
+ public LinearWeighing() {
+ this(0.0, 1.0);
+ }
+
public LinearWeighing(double min, double max) {
this.min = min;
this.max = max;
}
- public LinearWeighing() {
- this(0.0, 1.0);
- }
-
public LinearWeighing(LinearWeighing<E> copy) {
this.min = copy.min;
this.max = copy.max;
@@ -71,13 +70,13 @@ public class LinearWeighing<E> implements Weighing<E> {
}
@Override
- public List<Pair<Double, E>> weigh(List<E> elements) {
- List<Pair<Double, E>> weighedElements = new ArrayList<Pair<Double, E>>(elements.size());
+ public boolean weigh(List<Selection.Entry<E>> elements) {
double stepSize = (this.max - this.min) / (elements.size() - 1);
int objectIndex = 0;
- for (E element : elements) {
- weighedElements.add(new Pair<Double, E>(objectIndex++ * stepSize + this.min, element));
+ for (Selection.Entry<E> element : elements) {
+ element.setWeight(objectIndex++ * stepSize + this.min);
}
- return weighedElements;
+
+ return true;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
index 61d6dcf..158f931 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
@@ -22,17 +22,17 @@
package net.sourceforge.cilib.util.selection.weighing;
import java.util.List;
-import net.sourceforge.cilib.container.Pair;
import net.sourceforge.cilib.util.Cloneable;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* @author Wiehann Matthysen
* @param <E>
*/
-public interface Weighing<E> extends Cloneable {
+public interface Weighing<E extends Comparable> extends Cloneable {
@Override
public Weighing<E> getClone();
- public List<Pair<Double, E>> weigh(List<E> elements);
+ public boolean weigh(List<Selection.Entry<E>> elements);
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java
index 2bf3565..0feb33c 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java
@@ -22,13 +22,13 @@
package net.sourceforge.cilib.util.selection.weighing.entity;
import net.sourceforge.cilib.util.selection.weighing.*;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.cilib.container.Pair;
import net.sourceforge.cilib.entity.Entity;
import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.problem.InferiorFitness;
+import net.sourceforge.cilib.util.selection.Selection;
/**
* @author Wiehann Matthysen
@@ -56,10 +56,10 @@ public class EntityWeighing<E extends Entity> implements Weighing<E> {
return new EntityWeighing(this);
}
- private Pair<Fitness, Fitness> getMinMaxFitness(Collection<E> entities) {
+ private Pair<Fitness, Fitness> getMinMaxFitness(Collection<Selection.Entry<E>> entities) {
Pair<Fitness, Fitness> minMaxFitness = new Pair<Fitness, Fitness>(InferiorFitness.instance(), InferiorFitness.instance());
- for (E entity : entities) {
- Fitness fitness = this.entityFitness.getFitness(entity);
+ for (Selection.Entry<E> entity : entities) {
+ Fitness fitness = this.entityFitness.getFitness(entity.getElement());
if (minMaxFitness.getKey() == InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getKey()) < 0) {
minMaxFitness.setKey(fitness);
}
@@ -71,8 +71,8 @@ public class EntityWeighing<E extends Entity> implements Weighing<E> {
}
@Override
- public List<Pair<Double, E>> weigh(List<E> entities) {
- List<Pair<Double, E>> weighedEntities = new ArrayList<Pair<Double, E>>(entities.size());
+ public boolean weigh(List<Selection.Entry<E>> entities) {
+// List<Pair<Double, E>> weighedEntities = new ArrayList<Pair<Double, E>>(entities.size());
Pair<Fitness, Fitness> minMaxFitness = getMinMaxFitness(entities);
if (minMaxFitness.getKey() == InferiorFitness.instance() ||
@@ -82,11 +82,12 @@ public class EntityWeighing<E extends Entity> implements Weighing<E> {
double minMaxDifference = minMaxFitness.getValue().getValue() - minMaxFitness.getKey().getValue();
- for (E entity : entities) {
- double weight = (this.entityFitness.getFitness(entity).getValue() - minMaxFitness.getKey().getValue()) / minMaxDifference;
- weighedEntities.add(new Pair<Double, E>(weight, entity));
+ for (Selection.Entry<E> entity : entities) {
+ double weight = (this.entityFitness.getFitness(entity.getElement()).getValue() - minMaxFitness.getKey().getValue()) / minMaxDifference;
+ entity.setWeight(weight);
+// weighedEntities.add(new Pair<Double, E>(weight, entity));
}
-
- return weighedEntities;
+
+ return true;
}
}
diff --git a/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java b/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java
index 20f0699..4b69fc7 100644
--- a/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java
+++ b/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java
@@ -34,6 +34,7 @@ import net.sourceforge.cilib.problem.MaximisationFitness;
import net.sourceforge.cilib.problem.MinimisationFitness;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -70,7 +71,7 @@ public class RouletteWheelSelectionStrategyTest {
RouletteWheelSelectionStrategy rouletteWheelSelectionStrategy = new RouletteWheelSelectionStrategy();
rouletteWheelSelectionStrategy.select(topology);
}
-
+
@Test
public void minimizationSelection() {
individual1.getProperties().put(EntityType.FITNESS, new MinimisationFitness(10000.0));
diff --git a/src/test/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighingTest.java b/src/test/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighingTest.java
index 4b36ce2..7be7d48 100644
--- a/src/test/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighingTest.java
+++ b/src/test/java/net/sourceforge/cilib/moo/archive/solutionweighing/SolutionWeighingTest.java
@@ -21,15 +21,15 @@
*/
package net.sourceforge.cilib.moo.archive.solutionweighing;
+import java.util.List;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import net.sourceforge.cilib.container.Pair;
import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.problem.MOOptimisationProblem;
import net.sourceforge.cilib.problem.MinimisationFitness;
@@ -43,6 +43,7 @@ import net.sourceforge.cilib.type.types.Type;
import net.sourceforge.cilib.type.types.container.Vector;
import net.sourceforge.cilib.util.selection.Selection;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -148,24 +149,23 @@ public class SolutionWeighingTest {
@Test
public void testAntiClusteringWeighingStrategy() {
- Collection<Pair<Double, OptimisationSolution>> weighedSolutions =
- Selection.from(solutions).apply(new AntiClusterWeighing()).select();
+ List<Entry<OptimisationSolution>> weighedSolutions = Selection.from(solutions).weigh(new AntiClusterWeighing()).entries();
- Iterator<Pair<Double, OptimisationSolution>> weighedSolutionIterator = weighedSolutions.iterator();
- Pair<Double, OptimisationSolution> weighedSolution = weighedSolutionIterator.next();
- assertEquals(0.290823093508, weighedSolution.getKey(), EPSILON);
+ Iterator<Entry<OptimisationSolution>> weighedSolutionIterator = weighedSolutions.iterator();
+ Selection.Entry<OptimisationSolution> weighedSolution = weighedSolutionIterator.next();
+ Assert.assertEquals(0.290823093508, weighedSolution.getWeight(), EPSILON);
weighedSolution = weighedSolutionIterator.next();
- assertEquals(0.367312140917, weighedSolution.getKey(), EPSILON);
+ Assert.assertEquals(0.367312140917, weighedSolution.getWeight(), EPSILON);
weighedSolution = weighedSolutionIterator.next();
- assertEquals(0.418956131219, weighedSolution.getKey(), EPSILON);
+ Assert.assertEquals(0.418956131219, weighedSolution.getWeight(), EPSILON);
weighedSolution = weighedSolutionIterator.next();
- assertEquals(0.266011104583, weighedSolution.getKey(), EPSILON);
+ Assert.assertEquals(0.266011104583, weighedSolution.getWeight(), EPSILON);
weighedSolution = weighedSolutionIterator.next();
- assertEquals(0.283305258318, weighedSolution.getKey(), EPSILON);
+ Assert.assertEquals(0.283305258318, weighedSolution.getWeight(), EPSILON);
assertThat(weighedSolutionIterator.hasNext(), is(false));
}
diff --git a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java
index c92ab5c..5dc48e3 100644
--- a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java
+++ b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java
@@ -23,6 +23,7 @@ package net.sourceforge.cilib.util.selection.ordering;
import java.util.Arrays;
import java.util.List;
+import net.sourceforge.cilib.util.selection.Selection;
import org.junit.Assert;
import org.junit.Test;
@@ -39,7 +40,8 @@ public class OrderingTest {
@Test
public void randomOrdering() {
List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
- boolean ordered = new RandomOrdering<Integer>().order(elements);
+ List<Selection.Entry<Integer>> entries = Selection.from(elements).entries();
+ boolean ordered = new RandomOrdering<Integer>().order(entries);
Assert.assertTrue(ordered);
// TODO: We need to implement this.
}
@@ -47,36 +49,41 @@ public class OrderingTest {
@Test
public void reverseOrdering() {
List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
- boolean ordered = new ReverseOrdering<Integer>().order(elements);
+ List<Selection.Entry<Integer>> entries = Selection.from(elements).entries();
+ boolean ordered = new ReverseOrdering<Integer>().order(entries);
Assert.assertTrue(ordered);
+
for (int i = 0; i < 9; ++i) {
- Assert.assertEquals(elements.size() - i, elements.get(i).intValue());
+ Assert.assertEquals(elements.size() - i, entries.get(i).getElement().intValue());
}
}
@Test
public void ringBasedOrdering() {
List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
- boolean ordered = new RingBasedOrdering<Integer>(5).order(elements);
+ List<Selection.Entry<Integer>> entries = Selection.from(elements).entries();
+ boolean ordered = new RingBasedOrdering<Integer>(5).order(entries);
Assert.assertTrue(ordered);
- Assert.assertEquals(6, elements.get(0).intValue());
- Assert.assertEquals(7, elements.get(1).intValue());
- Assert.assertEquals(8, elements.get(2).intValue());
- Assert.assertEquals(9, elements.get(3).intValue());
- Assert.assertEquals(1, elements.get(4).intValue());
- Assert.assertEquals(2, elements.get(5).intValue());
- Assert.assertEquals(3, elements.get(6).intValue());
- Assert.assertEquals(4, elements.get(7).intValue());
- Assert.assertEquals(5, elements.get(8).intValue());
+ System.out.println("entries: " + entries);
+ Assert.assertEquals(6, entries.get(0).getElement().intValue());
+ Assert.assertEquals(7, entries.get(1).getElement().intValue());
+ Assert.assertEquals(8, entries.get(2).getElement().intValue());
+ Assert.assertEquals(9, entries.get(3).getElement().intValue());
+ Assert.assertEquals(1, entries.get(4).getElement().intValue());
+ Assert.assertEquals(2, entries.get(5).getElement().intValue());
+ Assert.assertEquals(3, entries.get(6).getElement().intValue());
+ Assert.assertEquals(4, entries.get(7).getElement().intValue());
+ Assert.assertEquals(5, entries.get(8).getElement().intValue());
}
@Test
public void sortedOrdering() {
List<Integer> elements = Arrays.asList(9, 8, 7, 6, 5, 4, 3, 2, 1);
- boolean ordered = new SortedOrdering().order(elements);
+ List<Selection.Entry<Integer>> entries = Selection.from(elements).entries();
+ boolean ordered = new SortedOrdering().order(entries);
Assert.assertTrue(ordered);
for (int i = 0; i < 9; ++i) {
- Assert.assertEquals(i + 1, elements.get(i).intValue());
+ Assert.assertEquals(i + ...
[truncated message content] |
|
From: Wiehann M. <wcm...@gm...> - 2009-05-23 00:47:37
|
Fixed the EntityWeighing class by removing the erranous else clause
that caused one of the fitness values to be equal to InferiorFitness.
This broke the RouletteWheelSelection class and all of its dependants
such as RouletteWheelSelectionStrategy.
Fixed the ProportionateOrdering class to correctly order the elements.
Also swapped the ordering around such that most fit entities that were
selected (or entities with higher probability of selection) are located
at the end of the selection (conforms to natural number ordering).
Then, changes were made to the core selection classes such as Selection
and SelectionSyntax as well as Ordering and Weighing to allow for
selections to be performed on elements that are not necessarily
comparable elements. This is usefull for when you want to select a
random population from a list of populations (and population -- or
algorithm -- is not comparable). However, this meant that changes had to
be made to all of the Ordering as well as Weighing classes to remove
comparable type requirement. This requirement were also removed from
some of the recipe classes and were left untouched in classes such as
TournamentSelection where it is required (an ordering of elements is
required). The DefaultComparator class accesses the Entry class and
performs the comparison if it is required in classes such as
SortedOrdering.
Some of the tests were modified to conform to the abovementioned
changes. Also, the WeighingTest got reintroduced and some changes were
made to the vepso.xml and dynamic-vepso.xml files to not make use of the
DescendingFitnessComparator class as all entities in cilib should be
ordered from least fit to most fit (the selection classes were changed
to take that into account).
---
.../selection/ElitistSelectionStrategy.java | 1 -
.../selection/TournamentSelectionStrategy.java | 2 -
.../cilib/util/selection/Selection.java | 45 ++++++---------
.../cilib/util/selection/SelectionSyntax.java | 2 +-
.../util/selection/ordering/DefaultComparator.java | 11 +++-
.../cilib/util/selection/ordering/Ordering.java | 2 +-
.../selection/ordering/ProportionalOrdering.java | 13 ++--
.../util/selection/ordering/RandomOrdering.java | 2 +-
.../util/selection/ordering/ReverseOrdering.java | 2 +-
.../util/selection/ordering/RingBasedOrdering.java | 5 +-
.../util/selection/ordering/SortedOrdering.java | 9 ++-
.../util/selection/recipes/ElitistSelection.java | 11 ++--
.../util/selection/recipes/RandomSelection.java | 4 +-
.../util/selection/recipes/RankBasedSelection.java | 13 ++--
.../recipes/RingBasedPopulationSelection.java | 31 +----------
.../selection/recipes/RouletteWheelSelection.java | 3 +-
.../selection/recipes/TournamentSelection.java | 9 ++-
.../util/selection/weighing/FixedWeighing.java | 2 +-
.../util/selection/weighing/LinearWeighing.java | 5 +-
.../cilib/util/selection/weighing/Weighing.java | 2 +-
.../selection/weighing/entity/EntityWeighing.java | 6 +-
.../RouletteWheelSelectionStrategyTest.java | 15 ++---
.../util/selection/ordering/OrderingTest.java | 4 +-
.../util/selection/weighing/WeighingTest.java | 59 ++++++++++++++++++++
.../weighing/entity/EntityWeighingTest.java | 19 ++++++-
xml/dynamic-vepso.xml | 4 +-
xml/vepso.xml | 4 +-
27 files changed, 158 insertions(+), 127 deletions(-)
create mode 100644 src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.java
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 29fe94f..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
@@ -25,7 +25,6 @@ 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.comparator.DescendingFitnessComparator;
import net.sourceforge.cilib.entity.topologies.TopologyHolder;
import net.sourceforge.cilib.util.selection.recipes.ElitistSelection;
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 8d615e0..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
@@ -25,7 +25,6 @@ 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.comparator.DescendingFitnessComparator;
import net.sourceforge.cilib.entity.topologies.TopologyHolder;
import net.sourceforge.cilib.util.selection.recipes.TournamentSelection;
@@ -70,7 +69,6 @@ public class TournamentSelectionStrategy extends SelectionStrategy {
public <T extends Entity> T select(Topology<T> population) {
TournamentSelection<T> selection = new TournamentSelection<T>();
selection.setTournamentSize(this.tournamentProportion);
- selection.setComparator(new DescendingFitnessComparator<T>());
return selection.select(population);
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
index f4ac2f1..2da72ac 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/Selection.java
@@ -59,7 +59,7 @@ import net.sourceforge.cilib.util.selection.weighing.Weighing;
* @param <E> The comparable type.
* @author gpampara
*/
-public final class Selection<E extends Comparable> implements SelectionSyntax<E> {
+public final class Selection<E> implements SelectionSyntax<E> {
private List<Entry<E>> elements;
@@ -72,8 +72,9 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
private Selection(Collection<? extends E> elements) {
this.elements = new ArrayList<Entry<E>>(elements.size());
- for (E element : elements)
+ for (E element : elements) {
this.elements.add(new Entry<E>(element));
+ }
}
/**
@@ -82,7 +83,7 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
* @param elements The collection of elements to operate on.
* @return A selection based on the provided collection.
*/
- public static <T extends Comparable> Selection<T> from(Collection<? extends T> elements) {
+ public static <T> Selection<T> from(Collection<? extends T> elements) {
return new Selection<T>(elements);
}
@@ -90,15 +91,16 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
* Apply the provided ordering on the current selection. The result of the
* operation will result in a modified selection.
* @param ordering The ordering to orderBy.
- * @return A selection upon which the ordering has be applied.
+ * @return A selection upon which the ordering has been applied.
* @throws UnsupportedOperationException if the ordering cannot be applied.
*/
@Override
public SelectionSyntax<E> orderBy(Ordering<E> ordering) {
boolean result = ordering.order(this.elements);
- if (result)
+ if (result) {
return this;
+ }
throw new UnsupportedOperationException("The ordering [" + ordering.getClass().getSimpleName() + "] " +
"cannot be applied to the selection. Please ensure that the intention of the ordering is correct.");
@@ -107,15 +109,16 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
/**
* Apply the provided weighing on the current selection. The result of the
* operation will result in new weighed selection.
- * @param weighing The weighing to orderBy.
- * @return A selection upon which the weighing has be applied.
+ * @param weighing The weighing to weighWith.
+ * @return A selection upon which the weighing has been applied.
*/
@Override
public SelectionSyntax<E> weigh(Weighing<E> weighing) {
boolean result = weighing.weigh(this.elements);
- if (result)
+ if (result) {
return this;
+ }
throw new UnsupportedOperationException("The weighing [" + weighing.getClass().getSimpleName() + "]" +
"cannot be applied to the selection. Please ensure that the intention of the weighing is correct.");
@@ -173,8 +176,9 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
public List<E> select() {
List<E> result = new ArrayList<E>();
- for (Entry<E> entry : elements)
+ for (Entry<E> entry : elements) {
result.add(entry.getElement());
+ }
return result;
}
@@ -189,7 +193,6 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
return this.elements;
}
-
/**
* This class provides the notion of an entry within a list
* for the selection process.
@@ -199,7 +202,8 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
* can be recored and used during the selection process.
* @param <E> The {@see Comparable} type.
*/
- public final static class Entry<E extends Comparable> implements Comparable {
+ public final static class Entry<E> {
+
private final E element;
private double weight;
@@ -247,11 +251,13 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
*/
@Override
public boolean equals(Object obj) {
- if (obj == this)
+ if (obj == this) {
return true;
+ }
- if ((obj == null) || (this.getClass() != obj.getClass()))
+ if ((obj == null) || (this.getClass() != obj.getClass())) {
return false;
+ }
Entry<E> other = (Entry<E>) obj;
return this.element.equals(other.element);
@@ -274,18 +280,5 @@ public final class Selection<E extends Comparable> implements SelectionSyntax<E>
public String toString() {
return this.element.toString();
}
-
- /**
- * Compare the current decorated {@code element} with the provided
- * object instance.
- * @param o The instance to test.
- * @return {@code 0} if equal, {@code -1} if the current element
- * is less than the provided instance, {@code 1} otherwise.
- */
- @Override
- public int compareTo(Object o) {
- Entry<E> other = (Entry<E>) o;
- return this.element.compareTo(other.element);
- }
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
index 3ba5613..1bb1f8b 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/SelectionSyntax.java
@@ -29,7 +29,7 @@ import net.sourceforge.cilib.util.selection.weighing.Weighing;
* @author Wiehann Matthysen
* @param <E>
*/
-public interface SelectionSyntax<E extends Comparable> {
+public interface SelectionSyntax<E> {
public SelectionSyntax<E> orderBy(Ordering<E> ordering);
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComparator.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComparator.java
index 9b80982..4a44798 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComparator.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/DefaultComparator.java
@@ -22,11 +22,16 @@
package net.sourceforge.cilib.util.selection.ordering;
import java.util.Comparator;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
-public class DefaultComparator<E extends Comparable> implements Comparator<E> {
+/**
+ * @author Wiehann Matthysen
+ * @param <E>
+ */
+public class DefaultComparator<E extends Comparable> implements Comparator<Entry<E>> {
@Override
- public int compare(E o1, E o2) {
- return o1.compareTo(o2);
+ public int compare(Entry<E> o1, Entry<E> o2) {
+ return o1.getElement().compareTo(o2.getElement());
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
index 00f6b0d..ad34630 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/Ordering.java
@@ -30,7 +30,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @param <E> The type to apply the ordering to.
* @author gpampara
*/
-public interface Ordering<E extends Comparable> {
+public interface Ordering<E> {
/**
* Apply the ordering on the provided list.
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java
index 04dd378..538f06c 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ProportionalOrdering.java
@@ -30,7 +30,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @author Wiehann Matthysen
* @param <E>
*/
-public class ProportionalOrdering<E extends Comparable> implements Ordering<E> {
+public class ProportionalOrdering<E> implements Ordering<E> {
private Random generator;
@@ -61,14 +61,13 @@ public class ProportionalOrdering<E extends Comparable> implements Ordering<E> {
double randomValue = this.generator.nextDouble() * total;
double marker = 0.0;
int j = i;
- for (; j < elements.size() - 1 && marker < randomValue; ++j) {
- marker += elements.get(j).getWeight();
- }
- // Swap elements i and j.
- Selection.Entry<E> elementJ = elements.set(j, elements.set(i, elements.get(j)));
+ do {
+ marker += elements.get(j++).getWeight();
+ } while (j < elements.size() && marker >= randomValue);
+ // Swap elements i and j - 1.
+ Selection.Entry<E> elementJ = elements.set(j - 1, elements.set(i, elements.get(j - 1)));
total -= elementJ.getWeight();
}
-
return true;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java
index 202a962..32a76f0 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RandomOrdering.java
@@ -33,7 +33,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @param <E> The comparable type.
* @author gpampara
*/
-public class RandomOrdering<E extends Comparable> implements Ordering<E> {
+public class RandomOrdering<E> implements Ordering<E> {
private Random generator;
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java
index 6a85fae..3b00ad6 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/ReverseOrdering.java
@@ -29,7 +29,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @author Wiehann Matthysen
* @param <E>
*/
-public class ReverseOrdering<E extends Comparable> implements Ordering<E> {
+public class ReverseOrdering<E> implements Ordering<E> {
@Override
public boolean order(List<Selection.Entry<E>> elements) {
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java
index 8927f8a..0cd8395 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/RingBasedOrdering.java
@@ -29,7 +29,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @author Wiehann Matthysen
* @param <E>
*/
-public class RingBasedOrdering<E extends Comparable> implements Ordering<E> {
+public class RingBasedOrdering<E> implements Ordering<E> {
private E marker;
@@ -51,9 +51,8 @@ public class RingBasedOrdering<E extends Comparable> implements Ordering<E> {
int position = 0;
for (Selection.Entry<E> entry : elements) {
- if (this.marker.compareTo(entry.getElement()) == 0)
+ if (this.marker.equals(entry.getElement()))
break;
-
position++;
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java
index e080c07..4787233 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/ordering/SortedOrdering.java
@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
/**
* Apply a sorting operation to the provided list, ordering the list naturally
@@ -34,9 +35,9 @@ import net.sourceforge.cilib.util.selection.Selection;
*/
public class SortedOrdering<E extends Comparable> implements Ordering<E> {
- private Comparator<E> comparator;
+ private Comparator<Entry<E>> comparator;
- public SortedOrdering(Comparator<E> comparator) {
+ public SortedOrdering(Comparator<Entry<E>> comparator) {
this.comparator = comparator;
}
@@ -50,8 +51,8 @@ public class SortedOrdering<E extends Comparable> implements Ordering<E> {
* @return {@code true} if successful, {@code false} otherwise.
*/
@Override
- public boolean order(List<Selection.Entry<E>> element) {
- Collections.sort(element);
+ public boolean order(List<Selection.Entry<E>> elements) {
+ Collections.sort(elements, this.comparator);
return true;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java
index 2e92e16..f9c9c6f 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/ElitistSelection.java
@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
@@ -35,9 +36,9 @@ import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
public class ElitistSelection<E extends Comparable> implements SelectionRecipe<E> {
private static final long serialVersionUID = -5432603299031620114L;
- private Comparator<E> comparator;
+ private Comparator<Entry<E>> comparator;
- public ElitistSelection(Comparator<E> comparator) {
+ public ElitistSelection(Comparator<Entry<E>> comparator) {
this.comparator = comparator;
}
@@ -49,11 +50,11 @@ public class ElitistSelection<E extends Comparable> implements SelectionRecipe<E
this.comparator = copy.comparator;
}
- public void setComparator(Comparator<E> comparator) {
+ public void setComparator(Comparator<Entry<E>> comparator) {
this.comparator = comparator;
}
- public Comparator<E> getComparator() {
+ public Comparator<Entry<E>> getComparator() {
return this.comparator;
}
@@ -64,7 +65,7 @@ public class ElitistSelection<E extends Comparable> implements SelectionRecipe<E
@Override
public E select(Collection<? extends E> elements) {
- List<E> selection = Selection.from(elements).orderBy(new SortedOrdering(this.comparator)).last().select();
+ List<E> selection = Selection.from(elements).orderBy(new SortedOrdering<E>(this.comparator)).last().select();
return selection.get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java
index d30d1de..0eb1401 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RandomSelection.java
@@ -32,7 +32,7 @@ import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
* @author Wiehann Matthysen
* @param <E>
*/
-public class RandomSelection<E extends Comparable> implements SelectionRecipe<E> {
+public class RandomSelection<E> implements SelectionRecipe<E> {
private static final long serialVersionUID = -5099663528040315048L;
private Random random;
@@ -56,7 +56,7 @@ public class RandomSelection<E extends Comparable> implements SelectionRecipe<E>
@Override
public E select(Collection<? extends E> elements) {
- List<E> selection = Selection.from(elements).orderBy(new RandomOrdering<E>(this.random)).first().select();
+ List<E> selection = Selection.from(elements).orderBy(new RandomOrdering<E>(this.random)).last().select();
return selection.get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java
index 75b13bf..779a855 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RankBasedSelection.java
@@ -27,6 +27,7 @@ import java.util.List;
import net.sourceforge.cilib.math.random.generator.MersenneTwister;
import net.sourceforge.cilib.math.random.generator.Random;
import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
@@ -38,15 +39,15 @@ import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
public class RankBasedSelection<E extends Comparable> implements SelectionRecipe<E> {
private static final long serialVersionUID = -2387196820773731607L;
- private Comparator<E> comparator;
+ private Comparator<Entry<E>> comparator;
private Random random;
- public RankBasedSelection(Comparator<E> comparator, Random random) {
+ public RankBasedSelection(Comparator<Entry<E>> comparator, Random random) {
this.comparator = comparator;
this.random = random;
}
- public RankBasedSelection(Comparator<E> comparator) {
+ public RankBasedSelection(Comparator<Entry<E>> comparator) {
this(comparator, new MersenneTwister());
}
@@ -59,11 +60,11 @@ public class RankBasedSelection<E extends Comparable> implements SelectionRecipe
this.random = copy.random.getClone();
}
- public void setComparator(Comparator<E> comparator) {
+ public void setComparator(Comparator<Entry<E>> comparator) {
this.comparator = comparator;
}
- public Comparator<E> getComparator() {
+ public Comparator<Entry<E>> getComparator() {
return this.comparator;
}
@@ -74,7 +75,7 @@ public class RankBasedSelection<E extends Comparable> implements SelectionRecipe
@Override
public E select(Collection<? extends E> elements) {
- List<E> selection = Selection.from(elements).orderBy(new SortedOrdering<E>(this.comparator)).first(this.random.nextInt(elements.size())).orderBy(new RandomOrdering<E>(this.random)).first().select();
+ List<E> selection = Selection.from(elements).orderBy(new SortedOrdering<E>(this.comparator)).last(this.random.nextInt(elements.size())).orderBy(new RandomOrdering<E>(this.random)).last().select();
return selection.get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java
index 5da4287..4886855 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RingBasedPopulationSelection.java
@@ -21,9 +21,7 @@
*/
package net.sourceforge.cilib.util.selection.recipes;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import net.sourceforge.cilib.algorithm.Algorithm;
import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm;
import net.sourceforge.cilib.util.selection.Selection;
@@ -48,33 +46,6 @@ public class RingBasedPopulationSelection implements SelectionRecipe<PopulationB
@Override
public PopulationBasedAlgorithm select(Collection<? extends PopulationBasedAlgorithm> elements) {
- PopulationBasedAlgorithmWrapper targetPBA = new PopulationBasedAlgorithmWrapper((PopulationBasedAlgorithm)Algorithm.get());
-
- List<PopulationBasedAlgorithmWrapper> list = new ArrayList<PopulationBasedAlgorithmWrapper>();
- for (PopulationBasedAlgorithm p : elements) {
- PopulationBasedAlgorithmWrapper wrapper = new PopulationBasedAlgorithmWrapper(p);
- list.add(wrapper);
- }
-
- PopulationBasedAlgorithmWrapper wrapper = Selection.from(list).orderBy(new RingBasedOrdering<PopulationBasedAlgorithmWrapper>(targetPBA)).first().singleSelect();
- return wrapper.get();
+ return Selection.from(elements).orderBy(new RingBasedOrdering<PopulationBasedAlgorithm>((PopulationBasedAlgorithm)Algorithm.get())).first().singleSelect();
}
-
- private class PopulationBasedAlgorithmWrapper implements Comparable {
- private final PopulationBasedAlgorithm algorithm;
-
- public PopulationBasedAlgorithmWrapper(PopulationBasedAlgorithm algorithm) {
- this.algorithm = algorithm;
- }
-
- public PopulationBasedAlgorithm get() {
- return algorithm;
- }
-
- @Override
- public int compareTo(Object o) {
- return 0;
- }
- }
-
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java
index 8b4bf1f..e0205e8 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/RouletteWheelSelection.java
@@ -22,7 +22,6 @@
package net.sourceforge.cilib.util.selection.recipes;
import java.util.Collection;
-import java.util.List;
import net.sourceforge.cilib.math.random.generator.MersenneTwister;
import net.sourceforge.cilib.math.random.generator.Random;
import net.sourceforge.cilib.util.selection.Selection;
@@ -73,7 +72,7 @@ public class RouletteWheelSelection<E extends Comparable> implements SelectionRe
@Override
public E select(Collection<? extends E> elements) {
- E selection = Selection.from(elements).weigh(this.weighing).orderBy(new ProportionalOrdering<E>(this.random)).first().singleSelect();
+ E selection = Selection.from(elements).weigh(this.weighing).orderBy(new ProportionalOrdering<E>(this.random)).last().singleSelect();
return selection;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java
index f030665..093e569 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/recipes/TournamentSelection.java
@@ -28,6 +28,7 @@ import net.sourceforge.cilib.controlparameter.ProportionalControlParameter;
import net.sourceforge.cilib.math.random.generator.MersenneTwister;
import net.sourceforge.cilib.math.random.generator.Random;
import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
import net.sourceforge.cilib.util.selection.ordering.DefaultComparator;
import net.sourceforge.cilib.util.selection.ordering.RandomOrdering;
import net.sourceforge.cilib.util.selection.ordering.SortedOrdering;
@@ -40,7 +41,7 @@ public class TournamentSelection<E extends Comparable> implements SelectionRecip
private static final long serialVersionUID = -6689673224380247931L;
private ControlParameter tournamentProportion;
- private Comparator<E> comparator;
+ private Comparator<Entry<E>> comparator;
private Random random;
public TournamentSelection() {
@@ -68,11 +69,11 @@ public class TournamentSelection<E extends Comparable> implements SelectionRecip
this.tournamentProportion = tournamanetSize;
}
- public void setComparator(Comparator<E> comparator) {
+ public void setComparator(Comparator<Entry<E>> comparator) {
this.comparator = comparator;
}
- public Comparator<E> getComparator() {
+ public Comparator<Entry<E>> getComparator() {
return this.comparator;
}
@@ -80,6 +81,6 @@ public class TournamentSelection<E extends Comparable> implements SelectionRecip
public E select(Collection<? extends E> elements) {
int tournamentSize = Double.valueOf(this.tournamentProportion.getParameter() * elements.size()).intValue();
return Selection.from(elements).orderBy(new RandomOrdering<E>(this.random)).
- first(tournamentSize).orderBy(new SortedOrdering<E>(this.comparator)).first().select().get(0);
+ last(tournamentSize).orderBy(new SortedOrdering<E>(this.comparator)).last().select().get(0);
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java
index 5152de4..7a6a217 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/FixedWeighing.java
@@ -28,7 +28,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @author Wiehann Matthysen
* @param <E>
*/
-public class FixedWeighing<E extends Comparable> implements Weighing<E> {
+public class FixedWeighing<E> implements Weighing<E> {
private static final long serialVersionUID = -6990220691744842964L;
private double weight;
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java
index 21d1adc..64ce536 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/LinearWeighing.java
@@ -28,7 +28,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @author Wiehann Matthysen
* @param <E>
*/
-public class LinearWeighing<E extends Comparable> implements Weighing<E> {
+public class LinearWeighing<E> implements Weighing<E> {
private static final long serialVersionUID = 3294682425241945584L;
private double min;
@@ -37,7 +37,7 @@ public class LinearWeighing<E extends Comparable> implements Weighing<E> {
public LinearWeighing() {
this(0.0, 1.0);
}
-
+
public LinearWeighing(double min, double max) {
this.min = min;
this.max = max;
@@ -76,7 +76,6 @@ public class LinearWeighing<E extends Comparable> implements Weighing<E> {
for (Selection.Entry<E> element : elements) {
element.setWeight(objectIndex++ * stepSize + this.min);
}
-
return true;
}
}
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
index 158f931..9fd703d 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/Weighing.java
@@ -29,7 +29,7 @@ import net.sourceforge.cilib.util.selection.Selection;
* @author Wiehann Matthysen
* @param <E>
*/
-public interface Weighing<E extends Comparable> extends Cloneable {
+public interface Weighing<E> extends Cloneable {
@Override
public Weighing<E> getClone();
diff --git a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java
index 0feb33c..05ec7e7 100644
--- a/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java
+++ b/src/main/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighing.java
@@ -35,8 +35,8 @@ import net.sourceforge.cilib.util.selection.Selection;
* @param <E>
*/
public class EntityWeighing<E extends Entity> implements Weighing<E> {
- private static final long serialVersionUID = 5906567326258195932L;
+ private static final long serialVersionUID = 5906567326258195932L;
private EntityFitness<E> entityFitness;
public EntityWeighing(EntityFitness<E> entityFitness) {
@@ -63,7 +63,7 @@ public class EntityWeighing<E extends Entity> implements Weighing<E> {
if (minMaxFitness.getKey() == InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getKey()) < 0) {
minMaxFitness.setKey(fitness);
}
- else if (minMaxFitness.getValue() == InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getValue()) > 0) {
+ if (minMaxFitness.getValue() == InferiorFitness.instance() || fitness.compareTo(minMaxFitness.getValue()) > 0) {
minMaxFitness.setValue(fitness);
}
}
@@ -72,7 +72,6 @@ public class EntityWeighing<E extends Entity> implements Weighing<E> {
@Override
public boolean weigh(List<Selection.Entry<E>> entities) {
-// List<Pair<Double, E>> weighedEntities = new ArrayList<Pair<Double, E>>(entities.size());
Pair<Fitness, Fitness> minMaxFitness = getMinMaxFitness(entities);
if (minMaxFitness.getKey() == InferiorFitness.instance() ||
@@ -85,7 +84,6 @@ public class EntityWeighing<E extends Entity> implements Weighing<E> {
for (Selection.Entry<E> entity : entities) {
double weight = (this.entityFitness.getFitness(entity.getElement()).getValue() - minMaxFitness.getKey().getValue()) / minMaxDifference;
entity.setWeight(weight);
-// weighedEntities.add(new Pair<Double, E>(weight, entity));
}
return true;
diff --git a/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java b/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java
index 4b69fc7..d030f6d 100644
--- a/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java
+++ b/src/test/java/net/sourceforge/cilib/entity/operators/selection/RouletteWheelSelectionStrategyTest.java
@@ -23,7 +23,6 @@
*/
package net.sourceforge.cilib.entity.operators.selection;
-
import junit.framework.Assert;
import net.sourceforge.cilib.ec.Individual;
import net.sourceforge.cilib.entity.Entity;
@@ -34,7 +33,6 @@ import net.sourceforge.cilib.problem.MaximisationFitness;
import net.sourceforge.cilib.problem.MinimisationFitness;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -48,7 +46,7 @@ import org.junit.Test;
* </p>
*/
public class RouletteWheelSelectionStrategyTest {
-
+
private Topology<Individual> topology;
private Individual individual1;
private Individual individual2;
@@ -57,7 +55,7 @@ public class RouletteWheelSelectionStrategyTest {
@Before
public void createDummyTopology() {
topology = new GBestTopology<Individual>();
-
+
individual1 = new Individual();
individual2 = new Individual();
individual3 = new Individual();
@@ -83,20 +81,19 @@ public class RouletteWheelSelectionStrategyTest {
Assert.assertNotNull(entity);
Assert.assertTrue(topology.contains(entity));
- Assert.assertEquals(entity, individual3);
+ Assert.assertSame(entity, individual3);
}
@Test
public void maximizationSelection() {
- individual1.getProperties().put(EntityType.FITNESS, new MaximisationFitness(90000.0)); // Should be the best entity
- individual2.getProperties().put(EntityType.FITNESS, new MaximisationFitness(0.5));
+ individual1.getProperties().put(EntityType.FITNESS, new MaximisationFitness(0.5));
+ individual2.getProperties().put(EntityType.FITNESS, new MaximisationFitness(90000.0)); // Should be the best entity
individual3.getProperties().put(EntityType.FITNESS, new MaximisationFitness(0.5));
RouletteWheelSelectionStrategy rouletteWheelSelectionStrategy = new RouletteWheelSelectionStrategy();
Entity entity = rouletteWheelSelectionStrategy.select(topology);
Assert.assertNotNull(entity);
- Assert.assertTrue(entity.equals(individual1));
+ Assert.assertTrue(entity.equals(individual2));
}
-
}
diff --git a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java
index 5dc48e3..6bdc981 100644
--- a/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java
+++ b/src/test/java/net/sourceforge/cilib/util/selection/ordering/OrderingTest.java
@@ -52,7 +52,6 @@ public class OrderingTest {
List<Selection.Entry<Integer>> entries = Selection.from(elements).entries();
boolean ordered = new ReverseOrdering<Integer>().order(entries);
Assert.assertTrue(ordered);
-
for (int i = 0; i < 9; ++i) {
Assert.assertEquals(elements.size() - i, entries.get(i).getElement().intValue());
}
@@ -64,7 +63,6 @@ public class OrderingTest {
List<Selection.Entry<Integer>> entries = Selection.from(elements).entries();
boolean ordered = new RingBasedOrdering<Integer>(5).order(entries);
Assert.assertTrue(ordered);
- System.out.println("entries: " + entries);
Assert.assertEquals(6, entries.get(0).getElement().intValue());
Assert.assertEquals(7, entries.get(1).getElement().intValue());
Assert.assertEquals(8, entries.get(2).getElement().intValue());
@@ -75,7 +73,7 @@ public class OrderingTest {
Assert.assertEquals(4, entries.get(7).getElement().intValue());
Assert.assertEquals(5, entries.get(8).getElement().intValue());
}
-
+
@Test
public void sortedOrdering() {
List<Integer> elements = Arrays.asList(9, 8, 7, 6, 5, 4, 3, 2, 1);
diff --git a/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.java b/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.java
new file mode 100644
index 0000000..286b687
--- /dev/null
+++ b/src/test/java/net/sourceforge/cilib/util/selection/weighing/WeighingTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.weighing;
+
+import java.util.Arrays;
+import java.util.List;
+import net.sourceforge.cilib.util.selection.Selection;
+import net.sourceforge.cilib.util.selection.Selection.Entry;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Wiehann Matthysen
+ */
+public class WeighingTest {
+
+ @Test
+ public void fixedWeighing() {
+ List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
+ List<Entry<Integer>> weighedElements = Selection.from(elements).weigh(new FixedWeighing(1.0)).entries();
+ for (int i = 0; i < weighedElements.size(); ++i) {
+ Assert.assertEquals(1.0, weighedElements.get(i).getWeight(), 0.0001);
+ }
+ }
+
+ @Test
+ public void linearWeighing() {
+ List<Integer> elements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
+ List<Entry<Integer>> weighedElements = Selection.from(elements).weigh(new LinearWeighing<Integer>(0.0,1.0)).entries();
+ Assert.assertEquals(0.0, weighedElements.get(0).getWeight(), 0.0001);
+ Assert.assertEquals(0.125, weighedElements.get(1).getWeight(), 0.0001);
+ Assert.assertEquals(0.25, weighedElements.get(2).getWeight(), 0.0001);
+ Assert.assertEquals(0.375, weighedElements.get(3).getWeight(), 0.0001);
+ Assert.assertEquals(0.5, weighedElements.get(4).getWeight(), 0.0001);
+ Assert.assertEquals(0.625, weighedElements.get(5).getWeight(), 0.0001);
+ Assert.assertEquals(0.75, weighedElements.get(6).getWeight(), 0.0001);
+ Assert.assertEquals(0.875, weighedElements.get(7).getWeight(), 0.0001);
+ Assert.assertEquals(1.0, weighedElements.get(8).getWeight(), 0.0001);
+ }
+}
diff --git a/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighingTest.java b/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighingTest.java
index c2d0c7a..f8d23ef 100644
--- a/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighingTest.java
+++ b/src/test/java/net/sourceforge/cilib/util/selection/weighing/entity/EntityWeighingTest.java
@@ -27,6 +27,7 @@ import net.sourceforge.cilib.ec.Individual;
import net.sourceforge.cilib.entity.EntityType;
import net.sourceforge.cilib.problem.Fitness;
import net.sourceforge.cilib.problem.MaximisationFitness;
+import net.sourceforge.cilib.problem.MinimisationFitness;
import net.sourceforge.cilib.util.selection.Selection;
import net.sourceforge.cilib.util.selection.Selection.Entry;
import org.junit.Assert;
@@ -38,7 +39,7 @@ import org.junit.Test;
public class EntityWeighingTest {
@Test
- public void entityWeighing() {
+ public void entityWeighingMaximise() {
Individual i1 = createIndividual(new MaximisationFitness(1.0));
Individual i2 = createIndividual(new MaximisationFitness(2.0));
Individual i3 = createIndividual(new MaximisationFitness(3.0));
@@ -53,6 +54,22 @@ public class EntityWeighingTest {
Assert.assertEquals(1.0, entries.get(2).getWeight(), 0.0001);
}
+ @Test
+ public void entityWeighingMinimise() {
+ Individual i1 = createIndividual(new MinimisationFitness(1.0));
+ Individual i2 = createIndividual(new MinimisationFitness(2.0));
+ Individual i3 = createIndividual(new MinimisationFitness(3.0));
+
+ List<Individual> individuals = Arrays.asList(i1, i2, i3);
+ List<Selection.Entry<Individual>> entries = Selection.from(individuals).entries();
+ EntityWeighing<Individual> weighing = new EntityWeighing<Individual>();
+ weighing.weigh(entries);
+
+ Assert.assertEquals(1.0, entries.get(0).getWeight(), 0.0001);
+ Assert.assertEquals(0.5, entries.get(1).getWeight(), 0.0001);
+ Assert.assertEquals(0.0, entries.get(2).getWeight(), 0.0001);
+ }
+
private Individual createIndividual(Fitness fitness) {
Individual i = new Individual();
i.getProperties().put(EntityType.FITNESS, fitness);
diff --git a/xml/dynamic-vepso.xml b/xml/dynamic-vepso.xml
index 7d83de6..0fc7941 100644
--- a/xml/dynamic-vepso.xml
+++ b/xml/dynamic-vepso.xml
@@ -16,9 +16,7 @@
<globalGuideSelectionStrategy class="pso.moo.guideselectionstrategies.VEPSOGuideSelectionStrategy">
<knowledgeTransferStrategy class="algorithm.population.knowledgetransferstrategies.SelectiveKnowledgeTransferStrategy">
<populationSelection class="util.selection.recipes.RingBasedPopulationSelection"/>
- <entitySelection class="util.selection.recipes.TournamentSelection">
- <comparator class="entity.comparator.DescendingFitnessComparator"/>
- </entitySelection>
+ <entitySelection class="util.selection.recipes.TournamentSelection"/>
</knowledgeTransferStrategy>
</globalGuideSelectionStrategy>
<globalGuideUpdateStrategy class="pso.moo.guideupdatestrategies.StandardGuideUpdateStrategy"/>
diff --git a/xml/vepso.xml b/xml/vepso.xml
index a56d454..58f41c9 100644
--- a/xml/vepso.xml
+++ b/xml/vepso.xml
@@ -15,9 +15,7 @@
<globalGuideSelectionStrategy class="pso.moo.guideselectionstrategies.VEPSOGuideSelectionStrategy">
<knowledgeTransferStrategy class="algorithm.population.knowledgetransferstrategies.SelectiveKnowledgeTransferStrategy">
<populationSelection class="util.selection.recipes.RingBasedPopulationSelection"/>
- <entitySelection class="util.selection.recipes.TournamentSelection">
- <comparator class="entity.comparator.DescendingFitnessComparator"/>
- </entitySelection>
+ <entitySelection class="util.selection.recipes.TournamentSelection"/>
</knowledgeTransferStrategy>
</globalGuideSelectionStrategy>
<globalGuideUpdateStrategy class="pso.moo.guideupdatestrategies.StandardGuideUpdateStrategy"/>
--
1.6.0.6
|