From 1e48c6cc820e6420ff4843528e831d02590edd23 Mon Sep 17 00:00:00 2001
From: Gili Tzabari
Date: Fri, 30 Sep 2011 16:08:10 -0400
Subject: [PATCH 1/4] Removed unnecessary {@inheritDoc} tags.
EvolutionObserver.populationUpdate() redefined as: "public void
populationUpdate(PopulationData data)". Added
PopulationData.getPopulation().
---
examples/nb-configuration.xml | 23 +--
.../examples/AbstractExampleApplet.java | 13 +-
.../watchmaker/examples/EvolutionLogger.java | 9 +-
.../examples/biomorphs/BiomorphApplet.java | 70 +++----
.../biomorphs/DawkinsBiomorphMutation.java | 18 +-
.../biomorphs/RandomBiomorphMutation.java | 11 +-
.../examples/bits/BitStringEvaluator.java | 5 +-
.../examples/geneticprogramming/Addition.java | 9 +-
.../geneticprogramming/BinaryNode.java | 47 ++---
.../examples/geneticprogramming/Constant.java | 7 +-
.../geneticprogramming/IfThenElse.java | 64 ++-----
.../geneticprogramming/IsGreater.java | 17 +-
.../examples/geneticprogramming/LeafNode.java | 19 +-
.../geneticprogramming/Multiplication.java | 13 +-
.../geneticprogramming/Parameter.java | 8 +-
.../geneticprogramming/Subtraction.java | 8 +-
.../geneticprogramming/TreeFactory.java | 33 ++--
.../examples/strings/StringEvaluator.java | 8 +-
.../examples/strings/StringsExample.java | 38 ++--
.../examples/sudoku/SudokuApplet.java | 176 +++++++++---------
.../examples/sudoku/SudokuEvaluator.java | 16 +-
.../examples/sudoku/SudokuFactory.java | 21 +--
.../BruteForceTravellingSalesman.java | 17 +-
.../EuropeanDistanceLookup.java | 21 +--
.../EvolutionaryTravellingSalesman.java | 71 +++----
.../travellingsalesman/RouteEvaluator.java | 12 +-
framework/nb-configuration.xml | 23 +--
.../uncommons/util/id/CompositeIDSource.java | 16 +-
.../util/id/IntSequenceIDSource.java | 14 +-
.../util/id/LongSequenceIDSource.java | 14 +-
.../util/id/StringPrefixIDSource.java | 9 +-
.../framework/AbstractEvolutionEngine.java | 131 ++++++-------
.../framework/CachingFitnessEvaluator.java | 50 +++--
.../framework/EvolutionObserver.java | 55 +++---
.../framework/EvolutionStrategyEngine.java | 27 +--
.../watchmaker/framework/EvolutionUtils.java | 27 ++-
.../GenerationalEvolutionEngine.java | 39 ++--
.../framework/NullFitnessEvaluator.java | 7 +-
.../watchmaker/framework/PopulationData.java | 39 ++--
.../framework/SteadyStateEvolutionEngine.java | 34 ++--
.../factories/AbstractCandidateFactory.java | 19 +-
.../interactive/InteractiveSelection.java | 18 +-
.../interactive/RendererAdapter.java | 16 +-
.../framework/islands/IslandEvolution.java | 153 +++++++--------
.../operators/BitStringCrossover.java | 10 +-
.../operators/ByteArrayCrossover.java | 10 +-
.../operators/CharArrayCrossover.java | 10 +-
.../operators/DoubleArrayCrossover.java | 11 +-
.../operators/IntArrayCrossover.java | 10 +-
.../framework/operators/ListCrossover.java | 4 +-
.../operators/ListOrderCrossover.java | 25 +--
.../operators/ObjectArrayCrossover.java | 24 +--
.../framework/operators/StringCrossover.java | 13 +-
.../framework/selection/RankSelection.java | 28 ++-
.../selection/RouletteWheelSelection.java | 41 ++--
.../framework/selection/SigmaScaling.java | 31 ++-
.../StochasticUniversalSampling.java | 24 ++-
.../selection/TournamentSelection.java | 23 +--
.../selection/TruncationSelection.java | 19 +-
.../framework/termination/ElapsedTime.java | 2 +
.../termination/GenerationCount.java | 6 +-
.../framework/termination/Stagnation.java | 14 +-
.../framework/termination/TargetFitness.java | 10 +-
.../framework/termination/UserAbort.java | 16 +-
.../GenerationalEvolutionEngineTest.java | 24 ++-
.../islands/IslandEvolutionTest.java | 72 +++----
.../termination/ElapsedTimeTest.java | 21 ++-
.../termination/GenerationCountTest.java | 16 +-
.../framework/termination/StagnationTest.java | 108 +++++++----
.../termination/TargetFitnessTest.java | 33 +++-
.../framework/termination/UserAbortTest.java | 16 +-
nb-configuration.xml | 17 +-
pom.xml | 4 +-
swing/nb-configuration.xml | 23 +--
.../watchmaker/swing/AbortControl.java | 9 +-
.../swing/NumericParameterControl.java | 14 +-
.../swing/ProbabilityParameterControl.java | 12 +-
.../swing/SelectionStrategyControl.java | 38 ++--
.../watchmaker/swing/SwingConsole.java | 11 +-
.../swing/SwingEvolutionObserver.java | 31 +--
.../swing/SwingIslandEvolutionObserver.java | 35 ++--
.../evolutionmonitor/EvolutionMonitor.java | 48 ++---
.../FittestCandidateView.java | 14 +-
.../swing/evolutionmonitor/IslandsView.java | 66 +++----
.../PopulationFitnessView.java | 72 ++++---
.../swing/evolutionmonitor/StatusBar.java | 14 +-
.../FittestCandidateViewTest.java | 27 ++-
.../swing/evolutionmonitor/StatusBarTest.java | 73 +++++---
88 files changed, 1231 insertions(+), 1343 deletions(-)
diff --git a/examples/nb-configuration.xml b/examples/nb-configuration.xml
index ae35717d..2db68b70 100644
--- a/examples/nb-configuration.xml
+++ b/examples/nb-configuration.xml
@@ -14,10 +14,10 @@ That way multiple projects can share the same settings (useful for formatting ru
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
project
- 2
- 2
- 2
- false
+ 4
+ 4
+ 4
+ true100words0
@@ -29,33 +29,28 @@ Any value defined here will override the pom.xml file value but is only applicab
WRAP_IF_LONGWRAP_IF_LONGWRAP_IF_LONG
- 2
- WRAP_IF_LONGtrue
+ WRAP_IF_LONGWRAP_IF_LONG
- truetrue
+ trueNEW_LINE
- WRAP_IF_LONGWRAP_IF_LONG
+ WRAP_IF_LONGWRAP_IF_LONGWRAP_IF_LONGWRAP_IF_LONGWRAP_IF_LONGWRAP_IF_LONGWRAP_IF_LONG
- 2
- true
- 100WRAP_IF_LONGtrueLEAVE_ALONE
- 2
- 2
- false
+ 4NEW_LINENEW_LINELEAVE_ALONEWRAP_IF_LONG
+ 2
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/AbstractExampleApplet.java b/examples/src/java/main/org/uncommons/watchmaker/examples/AbstractExampleApplet.java
index 8bf600ae..33c761b6 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/AbstractExampleApplet.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/AbstractExampleApplet.java
@@ -17,21 +17,15 @@
import java.awt.Container;
import java.lang.reflect.InvocationTargetException;
-import javax.swing.JApplet;
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-import javax.swing.UIManager;
+import javax.swing.*;
/**
* Base class for examples that run as applets.
+ *
* @author Daniel Dyer
*/
public abstract class AbstractExampleApplet extends JApplet
{
- /**
- * {@inheritDoc}
- */
@Override
public void init()
{
@@ -74,7 +68,8 @@ public void run()
catch (InvocationTargetException ex)
{
ex.getCause().printStackTrace();
- JOptionPane.showMessageDialog(container, ex.getCause(), "Error Occurred", JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(container, ex.getCause(), "Error Occurred",
+ JOptionPane.ERROR_MESSAGE);
}
}
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/EvolutionLogger.java b/examples/src/java/main/org/uncommons/watchmaker/examples/EvolutionLogger.java
index 5c47146b..10000583 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/EvolutionLogger.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/EvolutionLogger.java
@@ -19,16 +19,17 @@
import org.uncommons.watchmaker.framework.islands.IslandEvolutionObserver;
/**
- * Trivial evolution observer for displaying information at the end
- * of each generation.
+ * Trivial evolution observer for displaying information at the end of each generation.
+ *
* @param The type of entity being evolved.
* @author Daniel Dyer
*/
public class EvolutionLogger implements IslandEvolutionObserver
{
- public void populationUpdate(PopulationData extends T> data)
+ public void populationUpdate(PopulationData data)
{
- System.out.println("Generation " + data.getGenerationNumber() + ": " + data.getBestCandidateFitness());
+ System.out.println("Generation " + data.getGenerationNumber() + ": " + data.
+ getBestCandidateFitness());
}
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/BiomorphApplet.java b/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/BiomorphApplet.java
index 2be66309..1673d2c2 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/BiomorphApplet.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/BiomorphApplet.java
@@ -24,28 +24,13 @@
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.concurrent.TimeUnit;
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JSpinner;
-import javax.swing.SpinnerNumberModel;
-import javax.swing.SpringLayout;
-import javax.swing.SwingUtilities;
+import javax.swing.*;
import org.uncommons.maths.random.MersenneTwisterRNG;
import org.uncommons.maths.random.Probability;
import org.uncommons.swing.SpringUtilities;
import org.uncommons.swing.SwingBackgroundTask;
import org.uncommons.watchmaker.examples.AbstractExampleApplet;
-import org.uncommons.watchmaker.framework.EvolutionEngine;
-import org.uncommons.watchmaker.framework.EvolutionObserver;
-import org.uncommons.watchmaker.framework.EvolutionaryOperator;
-import org.uncommons.watchmaker.framework.GenerationalEvolutionEngine;
-import org.uncommons.watchmaker.framework.PopulationData;
+import org.uncommons.watchmaker.framework.*;
import org.uncommons.watchmaker.framework.interactive.InteractiveSelection;
import org.uncommons.watchmaker.framework.interactive.Renderer;
import org.uncommons.watchmaker.framework.termination.GenerationCount;
@@ -54,6 +39,7 @@
/**
* Watchmaker Framework implementation of Dawkin's biomorph program.
+ *
* @author Daniel Dyer
*/
public class BiomorphApplet extends AbstractExampleApplet
@@ -98,31 +84,35 @@ protected void prepareGUI(Container container)
* the GUI when it is done.
*/
private SwingBackgroundTask createTask(final int populationSize,
- final int generationCount,
- final boolean random)
+ final int generationCount,
+ final boolean random)
{
return new SwingBackgroundTask()
{
@Override
protected Biomorph performTask()
{
- EvolutionaryOperator mutation = random ? new RandomBiomorphMutation(new Probability(0.12d))
- : new DawkinsBiomorphMutation();
- InteractiveSelection selection = new InteractiveSelection(console,
- renderer,
- populationSize,
- 1);
- EvolutionEngine engine = new GenerationalEvolutionEngine(new BiomorphFactory(),
- mutation,
- selection,
- new MersenneTwisterRNG());
+ EvolutionaryOperator mutation = random
+ ? new RandomBiomorphMutation(new Probability(0.12d))
+ : new DawkinsBiomorphMutation();
+ InteractiveSelection selection = new InteractiveSelection(
+ console,
+ renderer,
+ populationSize,
+ 1);
+ EvolutionEngine engine =
+ new GenerationalEvolutionEngine(new BiomorphFactory(),
+ mutation,
+ selection,
+ new MersenneTwisterRNG());
engine.addEvolutionObserver(new SwingEvolutionObserver(
- new GenerationTracker(), 300, TimeUnit.MILLISECONDS));
+ new GenerationTracker(), 300, TimeUnit.MILLISECONDS));
return engine.evolve(populationSize,
- 0,
- new GenerationCount(generationCount));
+ 0,
+ new GenerationCount(generationCount));
}
+
@Override
protected void postProcessing(Biomorph result)
{
@@ -144,27 +134,25 @@ public static void main(String[] args)
new BiomorphApplet().displayInFrame("Watchmaker Framework - Biomporphs Example");
}
-
/**
* Simple observer to update the dialog title every time the evolution advances
* to a new generation.
*/
private final class GenerationTracker implements EvolutionObserver
{
- public void populationUpdate(final PopulationData extends Biomorph> populationData)
+ public void populationUpdate(final PopulationData populationData)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
selectionDialog.setTitle("Biomorph Selection - Generation "
- + (populationData.getGenerationNumber() + 1));
+ + (populationData.getGenerationNumber() + 1));
}
});
}
}
-
/**
* Panel for controlling the evolutionary algorithm parameters.
*/
@@ -174,6 +162,7 @@ private final class ControlPanel extends JPanel
private JSpinner generationsSpinner;
private JComboBox mutationCombo;
+
ControlPanel()
{
super(new BorderLayout());
@@ -198,7 +187,10 @@ private JComponent createInputPanel()
inputPanel.add(generationsLabel);
inputPanel.add(generationsSpinner);
JLabel mutationLabel = new JLabel("Mutation Type: ");
- mutationCombo = new JComboBox(new String[]{"Dawkins (Non-random)", "Random"});
+ mutationCombo = new JComboBox(new String[]
+ {
+ "Dawkins (Non-random)", "Random"
+ });
mutationCombo.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent itemEvent)
@@ -232,8 +224,8 @@ private JComponent createButtonPanel()
public void actionPerformed(ActionEvent actionEvent)
{
createTask((Integer) populationSpinner.getValue(),
- (Integer) generationsSpinner.getValue(),
- mutationCombo.getSelectedIndex() == 1).execute();
+ (Integer) generationsSpinner.getValue(),
+ mutationCombo.getSelectedIndex() == 1).execute();
selectionDialog.setVisible(true);
}
});
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/DawkinsBiomorphMutation.java b/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/DawkinsBiomorphMutation.java
index f718a76d..28102d9e 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/DawkinsBiomorphMutation.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/DawkinsBiomorphMutation.java
@@ -21,15 +21,17 @@
import org.uncommons.watchmaker.framework.EvolutionaryOperator;
/**
- * Non-random mutation of a population of biomorphs. This ensures that each selected candidate
- * is mutated differently. This is the mutation used by Dawkins in his original experiment.
+ * Non-random mutation of a population of biomorphs. This ensures that each selected candidate is
+ * mutated differently. This is the mutation used by Dawkins in his original experiment.
+ *
* @author Daniel Dyer
*/
public class DawkinsBiomorphMutation implements EvolutionaryOperator
{
/**
- * Mutate a population of biomorphs non-randomly, ensuring that each selected
- * candidate is mutated differently.
+ * Mutate a population of biomorphs non-randomly, ensuring that each selected candidate is
+ * mutated differently.
+ *
* @param selectedCandidates {@inheritDoc}
* @param rng A source of randomness (not used since this mutation is non-random).
* @return {@inheritDoc}
@@ -39,7 +41,7 @@ public List apply(List selectedCandidates, Random rng)
List mutatedPopulation = new ArrayList(selectedCandidates.size());
int mutatedGene = 0;
int mutation = 1;
- for (Biomorph b : selectedCandidates)
+ for (Biomorph b: selectedCandidates)
{
int[] genes = b.getGenotype();
@@ -49,8 +51,10 @@ public List apply(List selectedCandidates, Random rng)
mutatedGene = (mutatedGene + 1) % Biomorph.GENE_COUNT;
}
genes[mutatedGene] += mutation;
- int min = mutatedGene == Biomorph.LENGTH_GENE_INDEX ? Biomorph.LENGTH_GENE_MIN : Biomorph.GENE_MIN;
- int max = mutatedGene == Biomorph.LENGTH_GENE_INDEX ? Biomorph.LENGTH_GENE_MAX : Biomorph.GENE_MAX;
+ int min = mutatedGene == Biomorph.LENGTH_GENE_INDEX ? Biomorph.LENGTH_GENE_MIN
+ : Biomorph.GENE_MIN;
+ int max = mutatedGene == Biomorph.LENGTH_GENE_INDEX ? Biomorph.LENGTH_GENE_MAX
+ : Biomorph.GENE_MAX;
if (genes[mutatedGene] > max)
{
genes[mutatedGene] = min;
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java b/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java
index a98cb55f..a057ca1f 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/biomorphs/RandomBiomorphMutation.java
@@ -22,14 +22,16 @@
import org.uncommons.watchmaker.framework.EvolutionaryOperator;
/**
- * Mutation operator for biomorphs. Mutates each individual gene
- * according to some mutation probability.
+ * Mutation operator for biomorphs. Mutates each individual gene according to some mutation
+ * probability.
+ *
* @author Daniel Dyer
*/
public class RandomBiomorphMutation implements EvolutionaryOperator
{
private final Probability mutationProbability;
+
/**
* @param mutationProbability The probability that a given gene
* is changed.
@@ -49,7 +51,7 @@ public RandomBiomorphMutation(Probability mutationProbability)
public List apply(List selectedCandidates, Random rng)
{
List mutatedPopulation = new ArrayList(selectedCandidates.size());
- for (Biomorph biomorph : selectedCandidates)
+ for (Biomorph biomorph: selectedCandidates)
{
mutatedPopulation.add(mutateBiomorph(biomorph, rng));
}
@@ -66,7 +68,8 @@ public List apply(List selectedCandidates, Random rng)
private Biomorph mutateBiomorph(Biomorph biomorph, Random rng)
{
int[] genes = biomorph.getGenotype();
- assert genes.length == Biomorph.GENE_COUNT : "Biomorphs must have " + Biomorph.GENE_COUNT + " genes.";
+ assert genes.length == Biomorph.GENE_COUNT: "Biomorphs must have " + Biomorph.GENE_COUNT
+ + " genes.";
for (int i = 0; i < Biomorph.GENE_COUNT - 1; i++)
{
if (mutationProbability.nextEvent(rng))
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/bits/BitStringEvaluator.java b/examples/src/java/main/org/uncommons/watchmaker/examples/bits/BitStringEvaluator.java
index 3a6421c4..916b65d8 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/bits/BitStringEvaluator.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/bits/BitStringEvaluator.java
@@ -20,8 +20,8 @@
import org.uncommons.watchmaker.framework.FitnessEvaluator;
/**
- * A fitness evaluator that simply counts the number of ones in a bit
- * string.
+ * A fitness evaluator that simply counts the number of ones in a bit string.
+ *
* @see BitString
* @author Daniel Dyer
*/
@@ -29,6 +29,7 @@ public class BitStringEvaluator implements FitnessEvaluator
{
/**
* Calculates a fitness score for the candidate bit string.
+ *
* @param candidate The evolved bit string to evaluate.
* @param population {@inheritDoc}
* @return How many bits in the string are set to 1.
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Addition.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Addition.java
index 641510cb..08895179 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Addition.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Addition.java
@@ -17,13 +17,15 @@
/**
* Simple addition operator {@link Node}.
+ *
* @author Daniel Dyer
*/
public class Addition extends BinaryNode
{
/**
- * Creates a node that evaluates to the sum of the values of its two
- * child nodes ({@literal left} and {@literal right}).
+ * Creates a node that evaluates to the sum of the values of its two child nodes ({@literal left}
+ * and {@literal right}).
+ *
* @param left The first operand.
* @param right The second operand.
*/
@@ -45,9 +47,6 @@ public double evaluate(double[] programParameters)
}
- /**
- * {@inheritDoc}
- */
public Node simplify()
{
Node simplifiedLeft = left.simplify();
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/BinaryNode.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/BinaryNode.java
index 2273f742..efb23142 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/BinaryNode.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/BinaryNode.java
@@ -22,17 +22,20 @@
/**
* Convenient base class for {@link Node}s that have two sub-trees.
+ *
* @author Daniel Dyer
*/
abstract class BinaryNode implements Node
{
protected static final double[] NO_ARGS = new double[0];
-
- /** The first argument to the binary function. */
+ /**
+ * The first argument to the binary function.
+ */
protected final Node left;
- /** The second argument to the binary function. */
+ /**
+ * The second argument to the binary function.
+ */
protected final Node right;
-
private final char symbol;
@@ -49,9 +52,6 @@ protected BinaryNode(Node left, Node right, char symbol)
}
- /**
- * {@inheritDoc}
- */
public String getLabel()
{
return String.valueOf(symbol);
@@ -88,18 +88,12 @@ public int getWidth()
}
- /**
- * {@inheritDoc}
- */
public int countNodes()
{
return 1 + left.countNodes() + right.countNodes();
}
- /**
- * {@inheritDoc}
- */
public Node getNode(int index)
{
if (index == 0)
@@ -118,23 +112,20 @@ public Node getNode(int index)
}
- /**
- * {@inheritDoc}
- */
public Node getChild(int index)
{
switch (index)
{
- case 0: return left;
- case 1: return right;
- default: throw new IndexOutOfBoundsException("Invalid child index: " + index);
+ case 0:
+ return left;
+ case 1:
+ return right;
+ default:
+ throw new IndexOutOfBoundsException("Invalid child index: " + index);
}
}
- /**
- * {@inheritDoc}
- */
public Node replaceNode(int index, Node newNode)
{
if (index == 0)
@@ -154,10 +145,6 @@ public Node replaceNode(int index, Node newNode)
}
-
- /**
- * {@inheritDoc}
- */
public String print()
{
StringBuilder buffer = new StringBuilder("(");
@@ -171,9 +158,6 @@ public String print()
}
- /**
- * {@inheritDoc}
- */
public Node mutate(Random rng, Probability mutationProbability, TreeFactory treeFactory)
{
if (mutationProbability.nextEvent(rng))
@@ -199,9 +183,8 @@ public Node mutate(Random rng, Probability mutationProbability, TreeFactory tree
private Node newInstance(Node newLeft, Node newRight)
{
- Constructor extends BinaryNode> constructor = ReflectionUtils.findKnownConstructor(this.getClass(),
- Node.class,
- Node.class);
+ Constructor extends BinaryNode> constructor = ReflectionUtils.findKnownConstructor(this.
+ getClass(), Node.class, Node.class);
return ReflectionUtils.invokeUnchecked(constructor, newLeft, newRight);
}
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Constant.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Constant.java
index 2a075381..5866bce2 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Constant.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Constant.java
@@ -18,13 +18,13 @@
import java.text.DecimalFormat;
/**
- * A program node that evaluates to a constant value.
+ * A program node that evaluates to a constant value.
+ *
* @author Daniel Dyer
*/
public class Constant extends LeafNode
{
private static final DecimalFormat NUMBER_FORMAT = new DecimalFormat("######0.##");
-
private final double constant;
private final String label;
@@ -50,9 +50,6 @@ public double evaluate(double[] programParameters)
}
- /**
- * {@inheritDoc}
- */
public String getLabel()
{
return label;
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IfThenElse.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IfThenElse.java
index 54abc4c2..0023d3f0 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IfThenElse.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IfThenElse.java
@@ -20,6 +20,7 @@
/**
* Simple conditional program {@link Node}.
+ *
* @author Daniel Dyer
*/
public class IfThenElse implements Node
@@ -28,6 +29,7 @@ public class IfThenElse implements Node
private final Node then;
private final Node otherwise;
+
/**
* @param condition If this node evaluates to a value greater than zero then
* the value of the {@literal then} node is returned. Otherwise the value of
@@ -45,9 +47,6 @@ public IfThenElse(Node condition, Node then, Node otherwise)
}
- /**
- * {@inheritDoc}
- */
public String getLabel()
{
return "if";
@@ -64,36 +63,24 @@ public int getArity()
}
- /**
- * {@inheritDoc}
- */
public int getDepth()
{
return 1 + Math.max(condition.getDepth(), Math.max(then.getDepth(), otherwise.getDepth()));
}
- /**
- * {@inheritDoc}
- */
public int getWidth()
{
return condition.getWidth() + then.getWidth() + otherwise.getWidth();
}
- /**
- * {@inheritDoc}
- */
public int countNodes()
{
return 1 + condition.countNodes() + then.countNodes() + otherwise.countNodes();
}
- /**
- * {@inheritDoc}
- */
public Node getNode(int index)
{
if (index == 0)
@@ -120,25 +107,22 @@ public Node getNode(int index)
}
- /**
- * {@inheritDoc}
- */
public Node getChild(int index)
{
switch (index)
{
- case 0: return condition;
- case 1: return then;
- case 2 : return otherwise;
- default: throw new IndexOutOfBoundsException("Invalid child index: " + index);
+ case 0:
+ return condition;
+ case 1:
+ return then;
+ case 2:
+ return otherwise;
+ default:
+ throw new IndexOutOfBoundsException("Invalid child index: " + index);
}
}
-
- /**
- * {@inheritDoc}
- */
public Node replaceNode(int index, Node newNode)
{
if (index == 0)
@@ -156,19 +140,20 @@ public Node replaceNode(int index, Node newNode)
int thenNodes = then.countNodes();
if (index <= conditionNodes + thenNodes)
{
- return new IfThenElse(condition, then.replaceNode(index - conditionNodes - 1, newNode), otherwise);
+ return new IfThenElse(condition, then.replaceNode(index - conditionNodes - 1,
+ newNode), otherwise);
}
else
{
return new IfThenElse(condition,
then,
- otherwise.replaceNode(index - conditionNodes - thenNodes - 1, newNode));
+ otherwise.replaceNode(index - conditionNodes - thenNodes - 1,
+ newNode));
}
}
}
-
/**
* {@inheritDoc}
* Operates on three other nodes. The first is an expression to evaluate.
@@ -180,23 +165,17 @@ public Node replaceNode(int index, Node newNode)
public double evaluate(double[] programParameters)
{
return condition.evaluate(programParameters) > 0 // If...
- ? then.evaluate(programParameters) // Then...
- : otherwise.evaluate(programParameters); // Else...
+ ? then.evaluate(programParameters) // Then...
+ : otherwise.evaluate(programParameters); // Else...
}
-
- /**
- * {@inheritDoc}
- */
+
public String print()
{
return "(" + condition.print() + " ? " + then.print() + " : " + otherwise.print() + ")";
}
- /**
- * {@inheritDoc}
- */
public Node mutate(Random rng, Probability mutationProbability, TreeFactory treeFactory)
{
if (mutationProbability.nextEvent(rng))
@@ -222,9 +201,6 @@ public Node mutate(Random rng, Probability mutationProbability, TreeFactory tree
}
- /**
- * {@inheritDoc}
- */
@Override
public String toString()
{
@@ -232,9 +208,6 @@ public String toString()
}
- /**
- * {@inheritDoc}
- */
public Node simplify()
{
Node simplifiedCondition = condition.simplify();
@@ -255,7 +228,8 @@ public Node simplify()
return simplifiedThen;
}
// Only create a new node if something has actually changed, otherwise return the existing node.
- if (simplifiedCondition != condition || simplifiedThen != then || simplifiedOtherwise != otherwise)
+ if (simplifiedCondition != condition || simplifiedThen != then || simplifiedOtherwise
+ != otherwise)
{
return new IfThenElse(simplifiedCondition, simplifiedThen, simplifiedOtherwise);
}
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IsGreater.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IsGreater.java
index bd23472a..ded3644a 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IsGreater.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/IsGreater.java
@@ -16,16 +16,17 @@
package org.uncommons.watchmaker.examples.geneticprogramming;
/**
- * A program {@link Node} that evaluates to a one if the value of its first
- * argument is greater than the value of its second, or evaluates to zero otherwise.
+ * A program {@link Node} that evaluates to a one if the value of its first argument is greater than
+ * the value of its second, or evaluates to zero otherwise.
+ *
* @author Daniel Dyer
*/
public class IsGreater extends BinaryNode
{
/**
- * Creates a node that evaluates to one if the value of the first child node
- * is greater than the value of the second child node. Otherwise it evaluates
- * to zero.
+ * Creates a node that evaluates to one if the value of the first child node is greater than the
+ * value of the second child node. Otherwise it evaluates to zero.
+ *
* @param left The first operand.
* @param right The second operand.
*/
@@ -48,9 +49,6 @@ public double evaluate(double[] programParameters)
}
- /**
- * {@inheritDoc}
- */
public Node simplify()
{
Node simplifiedLeft = left.simplify();
@@ -64,7 +62,8 @@ public Node simplify()
// ever change.
else if (simplifiedLeft instanceof Constant && simplifiedRight instanceof Constant)
{
- return new Constant(simplifiedLeft.evaluate(NO_ARGS) > simplifiedRight.evaluate(NO_ARGS) ? 1 : 0);
+ return new Constant(simplifiedLeft.evaluate(NO_ARGS) > simplifiedRight.evaluate(NO_ARGS)
+ ? 1 : 0);
}
else if (simplifiedLeft != left || simplifiedRight != right)
{
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/LeafNode.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/LeafNode.java
index cf8718a7..9527c9db 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/LeafNode.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/LeafNode.java
@@ -20,12 +20,14 @@
/**
* Convenient base class for {@link Node}s that have no sub-trees.
+ *
* @author Daniel Dyer
*/
abstract class LeafNode implements Node
{
/**
* The arity of a non-function node is always zero.
+ *
* @return 0
*/
public int getArity()
@@ -33,7 +35,7 @@ public int getArity()
return 0;
}
-
+
/**
* Leaf nodes always have a depth of 1 since they have no child nodes.
* @return 1
@@ -53,10 +55,7 @@ public int getWidth()
return 1;
}
-
- /**
- * {@inheritDoc}
- */
+
public int countNodes()
{
return 1;
@@ -73,9 +72,6 @@ public Node getNode(int index)
}
- /**
- * {@inheritDoc}
- */
public Node getChild(int index)
{
throw new IndexOutOfBoundsException("Leaf nodes have no children.");
@@ -88,13 +84,10 @@ public Node replaceNode(int index, Node newNode)
{
throw new IndexOutOfBoundsException("Invalid node index: " + index);
}
- return newNode;
+ return newNode;
}
-
- /**
- * {@inheritDoc}
- */
+
public Node mutate(Random rng, Probability mutationProbability, TreeFactory treeFactory)
{
if (mutationProbability.nextEvent(rng))
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Multiplication.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Multiplication.java
index bd5dd600..42bd8204 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Multiplication.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Multiplication.java
@@ -17,13 +17,15 @@
/**
* Simple multiplication operator {@link Node}.
+ *
* @author Daniel Dyer
*/
public class Multiplication extends BinaryNode
{
/**
- * Creates a node that evaluates to the product of the values of its two
- * child nodes ({@literal left} and {@literal right}).
+ * Creates a node that evaluates to the product of the values of its two child nodes ({@literal left}
+ * and {@literal right}).
+ *
* @param left The first operand.
* @param right The second operand.
*/
@@ -45,9 +47,6 @@ public double evaluate(double[] programParameters)
}
- /**
- * {@inheritDoc}
- */
public Node simplify()
{
Node simplifiedLeft = left.simplify();
@@ -84,7 +83,7 @@ else if (constant == 0)
}
}
return simplifiedLeft != left || simplifiedRight != right
- ? new Multiplication(simplifiedLeft, simplifiedRight)
- : this;
+ ? new Multiplication(simplifiedLeft, simplifiedRight)
+ : this;
}
}
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Parameter.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Parameter.java
index 575bd1d0..9d88a565 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Parameter.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Parameter.java
@@ -16,14 +16,15 @@
package org.uncommons.watchmaker.examples.geneticprogramming;
/**
- * A program {@link Node} that simply returns the value of one of the
- * program's parameters.
+ * A program {@link Node} that simply returns the value of one of the program's parameters.
+ *
* @author Daniel Dyer
*/
public class Parameter extends LeafNode
{
private final int parameterIndex;
+
/**
* @param parameterIndex Which of the program's (zero-indexed) parameter
* values should be returned upon evaluation of this node.
@@ -49,9 +50,6 @@ public double evaluate(double[] programParameters)
}
- /**
- * {@inheritDoc}
- */
public String getLabel()
{
return "P" + parameterIndex;
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Subtraction.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Subtraction.java
index 97083af9..3a5b2d16 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Subtraction.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/Subtraction.java
@@ -17,13 +17,14 @@
/**
* Simple subtraction operator {@link Node}.
+ *
* @author Daniel Dyer
*/
public class Subtraction extends BinaryNode
{
/**
- * Creates a node that evaluates the the value of {@literal left}
- * minus the value of {@literal right}.
+ * Creates a node that evaluates the the value of {@literal left} minus the value of {@literal right}.
+ *
* @param left The first operand.
* @param right The second operand.
*/
@@ -45,9 +46,6 @@ public double evaluate(double[] programParameters)
}
- /**
- * {@inheritDoc}
- */
public Node simplify()
{
Node simplifiedLeft = left.simplify();
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeFactory.java b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeFactory.java
index abb935de..3a5b470c 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeFactory.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/geneticprogramming/TreeFactory.java
@@ -20,23 +20,21 @@
import org.uncommons.watchmaker.framework.factories.AbstractCandidateFactory;
/**
- * {@link org.uncommons.watchmaker.framework.CandidateFactory} for generating
- * trees of {@link Node}s for the genetic programming example application.
+ * {@link org.uncommons.watchmaker.framework.CandidateFactory} for generating trees of {@link Node}s
+ * for the genetic programming example application.
+ *
* @author Daniel Dyer
*/
public class TreeFactory extends AbstractCandidateFactory
{
// The number of program parameters that each program tree will be provided.
private final int parameterCount;
-
// The maximum depth of a program tree. No function nodes will be created below
// this depth (branches will be terminated with parameters or constants).
private final int maximumDepth;
-
// Probability that a created node is a function node rather
// than a value node.
private final Probability functionProbability;
-
// Probability that a value (non-function) node is a parameter
// node rather than a constant node.
private final Probability parameterProbability;
@@ -53,9 +51,9 @@ public class TreeFactory extends AbstractCandidateFactory
* non-function node will be a parameter node rather than a constant node.
*/
public TreeFactory(int parameterCount,
- int maxDepth,
- Probability functionProbability,
- Probability parameterProbability)
+ int maxDepth,
+ Probability functionProbability,
+ Probability parameterProbability)
{
if (parameterCount < 0)
{
@@ -73,9 +71,6 @@ public TreeFactory(int parameterCount,
}
- /**
- * {@inheritDoc}
- */
public Node generateRandomCandidate(Random rng)
{
return makeNode(rng, maximumDepth);
@@ -96,11 +91,17 @@ private Node makeNode(Random rng, int maxDepth)
int depth = maxDepth - 1;
switch (rng.nextInt(5))
{
- case 0: return new Addition(makeNode(rng, depth), makeNode(rng, depth));
- case 1: return new Subtraction(makeNode(rng, depth), makeNode(rng, depth));
- case 2: return new Multiplication(makeNode(rng, depth), makeNode(rng, depth));
- case 3: return new IfThenElse(makeNode(rng, depth), makeNode(rng, depth), makeNode(rng, depth));
- default: return new IsGreater(makeNode(rng, depth), makeNode(rng, depth));
+ case 0:
+ return new Addition(makeNode(rng, depth), makeNode(rng, depth));
+ case 1:
+ return new Subtraction(makeNode(rng, depth), makeNode(rng, depth));
+ case 2:
+ return new Multiplication(makeNode(rng, depth), makeNode(rng, depth));
+ case 3:
+ return new IfThenElse(makeNode(rng, depth), makeNode(rng, depth),
+ makeNode(rng, depth));
+ default:
+ return new IsGreater(makeNode(rng, depth), makeNode(rng, depth));
}
}
else if (parameterProbability.nextEvent(rng))
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringEvaluator.java b/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringEvaluator.java
index ac56c9f2..4e7ed2d0 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringEvaluator.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringEvaluator.java
@@ -19,8 +19,9 @@
import org.uncommons.watchmaker.framework.FitnessEvaluator;
/**
- * Evaluates strings and assigns a fitness score based on how many characters
- * differ from the equivalent positions in a given target string.
+ * Evaluates strings and assigns a fitness score based on how many characters differ from the
+ * equivalent positions in a given target string.
+ *
* @author Daniel Dyer
*/
public class StringEvaluator implements FitnessEvaluator
@@ -63,9 +64,6 @@ public double getFitness(String candidate,
}
- /**
- * {@inheritDoc}
- */
public boolean isNatural()
{
return false;
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java b/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java
index d8425fa6..deff155c 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/strings/StringsExample.java
@@ -19,11 +19,7 @@
import java.util.List;
import org.uncommons.maths.random.MersenneTwisterRNG;
import org.uncommons.maths.random.Probability;
-import org.uncommons.watchmaker.framework.EvolutionEngine;
-import org.uncommons.watchmaker.framework.EvolutionObserver;
-import org.uncommons.watchmaker.framework.EvolutionaryOperator;
-import org.uncommons.watchmaker.framework.GenerationalEvolutionEngine;
-import org.uncommons.watchmaker.framework.PopulationData;
+import org.uncommons.watchmaker.framework.*;
import org.uncommons.watchmaker.framework.factories.StringFactory;
import org.uncommons.watchmaker.framework.operators.EvolutionPipeline;
import org.uncommons.watchmaker.framework.operators.StringCrossover;
@@ -32,13 +28,16 @@
import org.uncommons.watchmaker.framework.termination.TargetFitness;
/**
- * Simple evolutionary algorithm that evolves a population of randomly-generated
- * strings until at least one matches a specified target string.
+ * Simple evolutionary algorithm that evolves a population of randomly-generated strings until at
+ * least one matches a specified target string.
+ *
* @author Daniel Dyer
*/
public final class StringsExample
{
private static final char[] ALPHABET = new char[27];
+
+
static
{
for (char c = 'A'; c <= 'Z'; c++)
@@ -66,19 +65,21 @@ public static void main(String[] args)
public static String evolveString(String target)
{
StringFactory factory = new StringFactory(ALPHABET, target.length());
- List> operators = new ArrayList>(2);
+ List> operators =
+ new ArrayList>(2);
operators.add(new StringMutation(ALPHABET, new Probability(0.02d)));
operators.add(new StringCrossover());
EvolutionaryOperator pipeline = new EvolutionPipeline(operators);
- EvolutionEngine engine = new GenerationalEvolutionEngine(factory,
- pipeline,
- new StringEvaluator(target),
- new RouletteWheelSelection(),
- new MersenneTwisterRNG());
+ EvolutionEngine engine =
+ new GenerationalEvolutionEngine(factory,
+ pipeline,
+ new StringEvaluator(target),
+ new RouletteWheelSelection(),
+ new MersenneTwisterRNG());
engine.addEvolutionObserver(new EvolutionLogger());
return engine.evolve(100, // 100 individuals in the population.
- 5, // 5% elitism.
- new TargetFitness(0, false));
+ 5, // 5% elitism.
+ new TargetFitness(0, false));
}
@@ -102,18 +103,17 @@ private static String convertArgs(String[] args)
return result.toString().toUpperCase();
}
-
/**
* Trivial evolution observer for displaying information at the end
* of each generation.
*/
private static class EvolutionLogger implements EvolutionObserver
{
- public void populationUpdate(PopulationData extends String> data)
+ public void populationUpdate(PopulationData data)
{
System.out.printf("Generation %d: %s\n",
- data.getGenerationNumber(),
- data.getBestCandidate());
+ data.getGenerationNumber(),
+ data.getBestCandidate());
}
}
}
diff --git a/examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuApplet.java b/examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuApplet.java
index e1d482af..b45f99da 100644
--- a/examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuApplet.java
+++ b/examples/src/java/main/org/uncommons/watchmaker/examples/sudoku/SudokuApplet.java
@@ -26,16 +26,7 @@
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JSpinner;
-import javax.swing.SpinnerNumberModel;
-import javax.swing.SpringLayout;
-import javax.swing.SwingUtilities;
+import javax.swing.*;
import org.uncommons.maths.random.DiscreteUniformGenerator;
import org.uncommons.maths.random.MersenneTwisterRNG;
import org.uncommons.maths.random.PoissonGenerator;
@@ -43,12 +34,7 @@
import org.uncommons.swing.SpringUtilities;
import org.uncommons.swing.SwingBackgroundTask;
import org.uncommons.watchmaker.examples.AbstractExampleApplet;
-import org.uncommons.watchmaker.framework.EvolutionEngine;
-import org.uncommons.watchmaker.framework.EvolutionObserver;
-import org.uncommons.watchmaker.framework.EvolutionaryOperator;
-import org.uncommons.watchmaker.framework.GenerationalEvolutionEngine;
-import org.uncommons.watchmaker.framework.PopulationData;
-import org.uncommons.watchmaker.framework.SelectionStrategy;
+import org.uncommons.watchmaker.framework.*;
import org.uncommons.watchmaker.framework.operators.EvolutionPipeline;
import org.uncommons.watchmaker.framework.selection.TournamentSelection;
import org.uncommons.watchmaker.framework.termination.TargetFitness;
@@ -59,57 +45,67 @@
/**
* An evolutionary Sudoku solver.
+ *
* @author Daniel Dyer
*/
public class SudokuApplet extends AbstractExampleApplet
{
- private static final String[] BLANK_PUZZLE = {".........",
- ".........",
- ".........",
- ".........",
- ".........",
- ".........",
- ".........",
- ".........",
- "........."};
-
- private static final String[] EASY_PUZZLE = {"4.5...9.7",
- ".2..9..6.",
- "39.6.7.28",
- "9..3.2..6",
- "7..9.6..3",
- "5..4.8..1",
- "28.1.5.49",
- ".7..3..8.",
- "6.4...3.2"};
-
- private static final String[] MEDIUM_PUZZLE = {"....3....",
- ".....6293",
- ".2.9.48..",
- ".754...38",
- "..46.71..",
- "91...547.",
- "..38.9.1.",
- "1567.....",
- "....1...."};
-
- private static final String[] HARD_PUZZLE = {"...891...",
- "....5.8..",
- ".....6.2.",
- "5....4..8",
- "49....67.",
- "8.13....5",
- ".6..8..9.",
- "..5.4.2.7",
- "...1.3.8."};
-
- private static final String[][] PUZZLES = {EASY_PUZZLE,
- MEDIUM_PUZZLE,
- HARD_PUZZLE,
- BLANK_PUZZLE};
-
+ private static final String[] BLANK_PUZZLE =
+ {
+ ".........",
+ ".........",
+ ".........",
+ ".........",
+ ".........",
+ ".........",
+ ".........",
+ ".........",
+ "........."
+ };
+ private static final String[] EASY_PUZZLE =
+ {
+ "4.5...9.7",
+ ".2..9..6.",
+ "39.6.7.28",
+ "9..3.2..6",
+ "7..9.6..3",
+ "5..4.8..1",
+ "28.1.5.49",
+ ".7..3..8.",
+ "6.4...3.2"
+ };
+ private static final String[] MEDIUM_PUZZLE =
+ {
+ "....3....",
+ ".....6293",
+ ".2.9.48..",
+ ".754...38",
+ "..46.71..",
+ "91...547.",
+ "..38.9.1.",
+ "1567.....",
+ "....1...."
+ };
+ private static final String[] HARD_PUZZLE =
+ {
+ "...891...",
+ "....5.8..",
+ ".....6.2.",
+ "5....4..8",
+ "49....67.",
+ "8.13....5",
+ ".6..8..9.",
+ "..5.4.2.7",
+ "...1.3.8."
+ };
+ private static final String[][] PUZZLES =
+ {
+ EASY_PUZZLE,
+ MEDIUM_PUZZLE,
+ HARD_PUZZLE,
+ BLANK_PUZZLE
+ };
private SelectionStrategy
+ *
* @param The type of entity that is to be evolved.
* @see GenerationalEvolutionEngine
* @see SteadyStateEvolutionEngine
@@ -83,21 +82,23 @@ public EvolutionStrategyEngine(CandidateFactory candidateFactory,
* @param rng A source of randomness.
* @return The updated population after the evolution strategy has advanced.
*/
- @Override
- protected List> nextEvolutionStep(List> evaluatedPopulation,
- int eliteCount,
- Random rng)
+ protected List> nextEvolutionStep(
+ List> evaluatedPopulation,
+ int eliteCount,
+ Random rng)
{
// Elite count is ignored. If it's non-zero it doesn't really matter, but if assertions are
// enabled we will flag it as wrong.
- assert eliteCount == 0 : "Explicit elitism is not supported for an ES, eliteCount should be 0.";
-
+ assert eliteCount == 0:
+ "Explicit elitism is not supported for an ES, eliteCount should be 0.";
+
// Select candidates that will be operated on to create the offspring.
int offspringCount = offspringMultiplier * evaluatedPopulation.size();
List parents = new ArrayList(offspringCount);
for (int i = 0; i < offspringCount; i++)
{
- parents.add(evaluatedPopulation.get(rng.nextInt(evaluatedPopulation.size())).getCandidate());
+ parents.add(evaluatedPopulation.get(rng.nextInt(evaluatedPopulation.size())).
+ getCandidate());
}
// Then evolve the parents.
diff --git a/framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java b/framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java
index 2838e318..8ecd517e 100644
--- a/framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java
+++ b/framework/src/java/main/org/uncommons/watchmaker/framework/EvolutionUtils.java
@@ -21,8 +21,9 @@
import org.uncommons.maths.statistics.DataSet;
/**
- * Utility methods used by different evolution implementations. This class exists to
- * avoid duplication of this logic among multiple evolution implementations.
+ * Utility methods used by different evolution implementations. This class exists to avoid
+ * duplication of this logic among multiple evolution implementations.
+ *
* @author Daniel Dyer
*/
public final class EvolutionUtils
@@ -55,7 +56,7 @@ public static List shouldContinue(PopulationData da
}
// Otherwise check the termination conditions for the evolution.
List satisfiedConditions = new LinkedList();
- for (TerminationCondition condition : conditions)
+ for (TerminationCondition condition: conditions)
{
if (condition.shouldTerminate(data))
{
@@ -90,7 +91,6 @@ public static void sortEvaluatedPopulation(List> evalu
}
-
/**
* Gets data about the current population, including the fittest candidate
* and statistics about the population as a whole.
@@ -100,24 +100,23 @@ public static void sortEvaluatedPopulation(List> evalu
* @param naturalFitness True if higher fitness scores mean fitter individuals, false otherwise.
* @param eliteCount The number of candidates preserved via elitism.
* @param iterationNumber The zero-based index of the current generation/epoch.
- * @param startTime The time at which the evolution began, expressed as a number of milliseconds since
- * 00:00 on 1st January 1970.
+ * @param startTime The time at which the evolution began, expressed as a number of milliseconds since 00:00 on 1st January 1970.
* @param The type of entity that is being evolved.
* @return Statistics about the current generation of evolved individuals.
*/
- public static PopulationData getPopulationData(List> evaluatedPopulation,
- boolean naturalFitness,
- int eliteCount,
- int iterationNumber,
- long startTime)
+ public static PopulationData getPopulationData(
+ List> evaluatedPopulation,
+ boolean naturalFitness,
+ int eliteCount,
+ int iterationNumber,
+ long startTime)
{
DataSet stats = new DataSet(evaluatedPopulation.size());
- for (EvaluatedCandidate candidate : evaluatedPopulation)
+ for (EvaluatedCandidate candidate: evaluatedPopulation)
{
stats.addValue(candidate.getFitness());
}
- return new PopulationData(evaluatedPopulation.get(0).getCandidate(),
- evaluatedPopulation.get(0).getFitness(),
+ return new PopulationData(evaluatedPopulation,
stats.getArithmeticMean(),
stats.getStandardDeviation(),
naturalFitness,
diff --git a/framework/src/java/main/org/uncommons/watchmaker/framework/GenerationalEvolutionEngine.java b/framework/src/java/main/org/uncommons/watchmaker/framework/GenerationalEvolutionEngine.java
index 3e43915f..63a41f65 100644
--- a/framework/src/java/main/org/uncommons/watchmaker/framework/GenerationalEvolutionEngine.java
+++ b/framework/src/java/main/org/uncommons/watchmaker/framework/GenerationalEvolutionEngine.java
@@ -22,21 +22,18 @@
import org.uncommons.watchmaker.framework.interactive.InteractiveSelection;
/**
- *
This class implements a general-purpose generational evolutionary algorithm.
- * It supports optional concurrent fitness evaluations to take full advantage of
- * multi-processor, multi-core and hyper-threaded machines.
- *
- *
If multi-threading is enabled, evolution (mutation, cross-over, etc.) occurs
- * on the request thread but fitness evaluations are delegated to a pool of worker
- * threads. All of the host's available processing units are used (i.e. on a quad-core
- * machine there will be four fitness evaluation worker threads).
- *
- *
If multi-threading is disabled, all work is performed synchronously on the
- * request thread. This strategy is suitable for restricted/managed environments where
- * it is not permitted for applications to manage their own threads. If there are no
- * restrictions on concurrency, applications should enable multi-threading for improved
- * performance.
- *
+ *
This class implements a general-purpose generational evolutionary algorithm. It supports
+ * optional concurrent fitness evaluations to take full advantage of multi-processor, multi-core and
+ * hyper-threaded machines.
+ *
If multi-threading is enabled, evolution (mutation, cross-over, etc.) occurs on the
+ * request thread but fitness evaluations are delegated to a pool of worker threads. All of the
+ * host's available processing units are used (i.e. on a quad-core machine there will be four fitness
+ * evaluation worker threads).
+ *
If multi-threading is disabled, all work is performed synchronously on the request
+ * thread. This strategy is suitable for restricted/managed environments where it is not permitted
+ * for applications to manage their own threads. If there are no restrictions on concurrency,
+ * applications should enable multi-threading for improved performance.
+ *
* @param The type of entity that is to be evolved.
* @see SteadyStateEvolutionEngine
* @see EvolutionStrategyEngine
@@ -48,6 +45,7 @@ public class GenerationalEvolutionEngine extends AbstractEvolutionEngine
private final FitnessEvaluator super T> fitnessEvaluator;
private final SelectionStrategy super T> selectionStrategy;
+
/**
* Creates a new evolution engine by specifying the various components required by
* a generational evolutionary algorithm.
@@ -100,13 +98,10 @@ public GenerationalEvolutionEngine(CandidateFactory candidateFactory,
}
- /**
- * {@inheritDoc}
- */
- @Override
- protected List> nextEvolutionStep(List> evaluatedPopulation,
- int eliteCount,
- Random rng)
+ protected List> nextEvolutionStep(
+ List> evaluatedPopulation,
+ int eliteCount,
+ Random rng)
{
List population = new ArrayList(evaluatedPopulation.size());
diff --git a/framework/src/java/main/org/uncommons/watchmaker/framework/NullFitnessEvaluator.java b/framework/src/java/main/org/uncommons/watchmaker/framework/NullFitnessEvaluator.java
index 0fe0d3ae..23046cc9 100644
--- a/framework/src/java/main/org/uncommons/watchmaker/framework/NullFitnessEvaluator.java
+++ b/framework/src/java/main/org/uncommons/watchmaker/framework/NullFitnessEvaluator.java
@@ -18,14 +18,16 @@
import java.util.List;
/**
- * Fitness evaluation is not required for interactive selection, so this stub
- * implementation is used to satisfy the framework requirements.
+ * Fitness evaluation is not required for interactive selection, so this stub implementation is used
+ * to satisfy the framework requirements.
+ *
* @author Daniel Dyer
*/
class NullFitnessEvaluator implements FitnessEvaluator