|
From: <leo...@gm...> - 2009-07-16 12:52:14
|
From: Leo Langenhoven <lla...@cs...>
Made some members of RandCreationStrategy protected, since Rand-to-Best inherets from it
Added a setScaleParameter method to RandCreationStrategy so that the parameter can be set in the xml file
---
.../operators/creation/RandCreationStrategy.java | 10 ++-
.../creation/RandToBestCreationStrategy.java | 99 ++++++++++++++++++++
2 files changed, 106 insertions(+), 3 deletions(-)
create mode 100644 src/main/java/net/sourceforge/cilib/entity/operators/creation/RandToBestCreationStrategy.java
diff --git a/src/main/java/net/sourceforge/cilib/entity/operators/creation/RandCreationStrategy.java b/src/main/java/net/sourceforge/cilib/entity/operators/creation/RandCreationStrategy.java
index 722a7de..99e176a 100644
--- a/src/main/java/net/sourceforge/cilib/entity/operators/creation/RandCreationStrategy.java
+++ b/src/main/java/net/sourceforge/cilib/entity/operators/creation/RandCreationStrategy.java
@@ -38,7 +38,7 @@ import net.sourceforge.cilib.type.types.container.Vector;
public class RandCreationStrategy implements CreationStrategy {
private static final long serialVersionUID = 930740770470361009L;
- private ControlParameter scaleParameter;
+ protected ControlParameter scaleParameter;
private ControlParameter numberOfDifferenceVectors;
/**
@@ -92,7 +92,7 @@ public class RandCreationStrategy implements CreationStrategy {
* reduce the diversity of the population as not all entities will be considered.
* @return A {@linkplain Vector} representing the resultant of all calculated difference vectors.
*/
- private Vector determineDistanceVector(List<Entity> participants) {
+ protected Vector determineDistanceVector(List<Entity> participants) {
Vector distanceVector = new Vector(participants.get(0).getCandidateSolution().size(), new Real(0.0));
Iterator<Entity> iterator = participants.iterator();
@@ -114,7 +114,7 @@ public class RandCreationStrategy implements CreationStrategy {
* @return {@linkplain List} containing the entities to be used in the calculation of
* the difference vectors.
*/
- private List<Entity> selectEntities(Entity current, Topology<? extends Entity> topology) {
+ protected List<Entity> selectEntities(Entity current, Topology<? extends Entity> topology) {
SelectionStrategy randomSelectionStrategy = new RandomSelectionStrategy();
List<Entity> participants = new ArrayList<Entity>();
@@ -140,5 +140,9 @@ public class RandCreationStrategy implements CreationStrategy {
throw new UnsupportedOperationException("Not supported yet. This may need some more refactoring. May require looping operator?");
}
+ public void setScaleParameter(ControlParameter scaleParameter) {
+ this.scaleParameter = scaleParameter;
+ }
+
}
diff --git a/src/main/java/net/sourceforge/cilib/entity/operators/creation/RandToBestCreationStrategy.java b/src/main/java/net/sourceforge/cilib/entity/operators/creation/RandToBestCreationStrategy.java
new file mode 100644
index 0000000..9eee5f9
--- /dev/null
+++ b/src/main/java/net/sourceforge/cilib/entity/operators/creation/RandToBestCreationStrategy.java
@@ -0,0 +1,99 @@
+/**
+ * Copyright (C) 2003 - 2009
+ * 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.operators.creation;
+
+import java.util.List;
+
+import net.sourceforge.cilib.controlparameter.ConstantControlParameter;
+import net.sourceforge.cilib.controlparameter.ControlParameter;
+import net.sourceforge.cilib.entity.Entity;
+import net.sourceforge.cilib.entity.Topology;
+import net.sourceforge.cilib.entity.topologies.TopologyHolder;
+import net.sourceforge.cilib.type.types.container.Vector;
+
+/**
+ * @author leo
+ * This is an implimentation of the Rand-to-best DE target creation strategy. This implimentation is simply an extension of the {@linkplain RandCreationStrategy} that also includes the best {@linkplain Entity}'s solution vector. The influence of the best vector and the
+ * random vector is determined by the greedynessParameter, which is sampled as E [0,1]. A value of 0 will ignore the contribution of the best {@linkplain Entity}, and a
+ * value of 1 will ignore the controbution of the random {@linkplain Entity}.
+ */
+public class RandToBestCreationStrategy extends RandCreationStrategy {
+ private static final long serialVersionUID = 413628791093573875L;
+ private ControlParameter greedynessParameter;
+ /**
+ * Create a new instance of {@code RandToBestCreationStrategy}.
+ */
+ public RandToBestCreationStrategy() {
+ super();
+ greedynessParameter = new ConstantControlParameter(0.5);
+ }
+ /**
+ * Copy constructor. Create a copy of the provided instance.
+ * @param copy The instance to copy.
+ */
+ public RandToBestCreationStrategy(RandToBestCreationStrategy other) {
+ super(other);
+ greedynessParameter = other.greedynessParameter.getClone();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Entity create(Entity targetEntity, Entity current,
+ Topology<? extends Entity> topology) {
+ List<Entity> participants = selectEntities(current, topology);
+ Vector differenceVector = determineDistanceVector(participants);
+
+ Vector targetVector = ((Vector) targetEntity.getCandidateSolution()).multiply(1 - greedynessParameter.getParameter());
+ Vector bestVector = ((Vector) topology.getBestEntity().getCandidateSolution()).multiply(greedynessParameter.getParameter());
+
+ Vector trialVector = bestVector.plus(targetVector.plus(differenceVector.multiply(scaleParameter.getParameter())));
+
+ Entity trialEntity = current.getClone();
+ trialEntity.setCandidateSolution(trialVector);
+
+ return trialEntity;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RandToBestCreationStrategy getClone() {
+ return new RandToBestCreationStrategy(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void performOperation(TopologyHolder holder) {
+ throw new UnsupportedOperationException("Not supported yet. This may need some more refactoring. May require looping operator?");
+ }
+
+ public void setGreedynessParameter(ControlParameter greedynessParameter) {
+ this.greedynessParameter = greedynessParameter;
+ }
+
+}
--
1.5.4.3
|