From: Gary P. <gpa...@gm...> - 2009-08-24 08:51:10
|
The need to have an interface for Algorithm is very high. It promotes better unit testing as it can be mocked out successfully. Signed-off-by: Gary Pampara <gpa...@gm...> --- .../{Algorithm.java => AbstractAlgorithm.java} | 13 +- .../net/sourceforge/cilib/algorithm/Algorithm.java | 350 +------------------- .../algorithm/MultistartOptimisationAlgorithm.java | 10 +- .../cilib/algorithm/SingularAlgorithm.java | 2 +- .../population/PopulationBasedAlgorithm.java | 4 +- .../rnaprediction/RNAAccuracyMeasurement.java | 3 +- .../sequencealignment/AlignmentVisualizer.java | 2 +- .../DesiredMaximizationFitness.java | 5 +- .../net/sourceforge/cilib/boa/bee/OnlookerBee.java | 4 +- .../net/sourceforge/cilib/boa/bee/WorkerBee.java | 4 +- .../cilib/clustering/kmeans/KMeans.java | 3 +- .../ExponentiallyDecreasingControlParameter.java | 3 +- .../ExponentiallyIncreasingControlParameter.java | 3 +- .../LinearDecreasingControlParameter.java | 3 +- .../LinearIncreasingControlParameter.java | 3 +- .../splitstrategies/ImperfectSplitStrategy.java | 7 +- .../splitstrategies/IndexedSplitStrategy.java | 5 +- .../splitstrategies/PerfectSplitStrategy.java | 3 +- .../continuous/dynamic/moo/fda1/FDA1_g.java | 4 +- .../continuous/dynamic/moo/fda2/FDA2_h.java | 4 +- .../discrete/LongestCommonSubsequence.java | 8 +- .../games/random/FixedListSeedingStrategy.java | 4 +- .../games/random/RandomListSeedingStrategy.java | 4 +- .../cilib/measurement/generic/Iterations.java | 3 +- .../measurement/generic/PercentageComplete.java | 4 +- .../measurement/multiple/MultipleFitness.java | 3 +- .../measurement/multiple/MultipleSolutions.java | 3 +- .../measurement/single/ConvergedDimensions.java | 1 - .../measurement/single/FitnessEvaluations.java | 1 + .../AverageDiversityAroundAllEntities.java | 5 +- .../GBestCenterInitialisationStrategy.java | 4 +- .../SpatialCenterInitialisationStrategy.java | 4 +- .../normalisation/TopologyBasedNormalisation.java | 5 +- .../ArchivingIterationStrategy.java | 3 +- .../foundation/EvaluationMediator.java | 4 +- .../foundation/measurements/NNOutput.java | 3 +- .../postSimulation/PostMeasurementSuite.java | 4 +- .../FFNNEvaluationMediator.java | 3 +- .../SAILAEvaluationMediator.java | 3 +- .../IterationBasedChangeStrategy.java | 4 +- ...CoevolutionGameLearningOptimizationProblem.java | 5 +- .../pso/dynamic/ChargedVelocityUpdateStrategy.java | 4 +- .../ArchiveReevaluationResponseStrategy.java | 4 +- ...lutionParticleReevaluationResponseStrategy.java | 4 +- .../VEPSOGuideSelectionStrategy.java | 4 +- .../DominantGuideUpdateStrategy.java | 3 +- .../cilib/pso/particle/MultiObjectiveParticle.java | 4 +- .../DEPositionUpdateStrategy.java | 4 +- .../BareBonesDEVelocityUpdate.java | 4 +- .../CoherenceVelocityUpdate.java | 4 +- .../FDRVelocityUpdateStrategy.java | 6 +- .../FIPSVelocityUpdate.java | 4 +- .../GCVelocityUpdateStrategy.java | 6 +- .../sourceforge/cilib/simulator/Simulation.java | 5 +- .../net/sourceforge/cilib/simulator/Simulator.java | 5 +- .../cilib/stoppingcondition/MinimumDiversity.java | 3 +- .../sourceforge/cilib/util/ClusteringUtils.java | 3 +- .../calculator/EntityBasedFitnessCalculator.java | 3 +- .../calculator/PropertyBasedFitnessCalculator.java | 3 +- .../StructuredTypeFitnessCalculator.java | 3 +- .../recipes/RingBasedPopulationSelection.java | 4 +- .../cilib/algorithm/GenericAlgorithmTest.java | 10 +- 62 files changed, 146 insertions(+), 457 deletions(-) copy src/main/java/net/sourceforge/cilib/algorithm/{Algorithm.java => AbstractAlgorithm.java} (97%) diff --git a/src/main/java/net/sourceforge/cilib/algorithm/Algorithm.java b/src/main/java/net/sourceforge/cilib/algorithm/AbstractAlgorithm.java similarity index 97% copy from src/main/java/net/sourceforge/cilib/algorithm/Algorithm.java copy to src/main/java/net/sourceforge/cilib/algorithm/AbstractAlgorithm.java index dd307f4..80d0784 100644 --- a/src/main/java/net/sourceforge/cilib/algorithm/Algorithm.java +++ b/src/main/java/net/sourceforge/cilib/algorithm/AbstractAlgorithm.java @@ -27,7 +27,6 @@ import java.util.List; import net.sourceforge.cilib.problem.OptimisationProblem; import net.sourceforge.cilib.problem.OptimisationSolution; import net.sourceforge.cilib.stoppingcondition.StoppingCondition; -import net.sourceforge.cilib.util.Cloneable; /** * <p> @@ -40,7 +39,7 @@ import net.sourceforge.cilib.util.Cloneable; * </p> * @author Edwin Peer */ -public abstract class Algorithm implements Cloneable, Runnable { +public abstract class AbstractAlgorithm implements Algorithm, Runnable { private static final long serialVersionUID = 7197544770653732632L; private List<StoppingCondition> stoppingConditions; private List<AlgorithmListener> algorithmListeners; @@ -68,7 +67,7 @@ public abstract class Algorithm implements Cloneable, Runnable { * for the instance and initialises the needed containers needed for the different * {@linkplain AlgorithmEvent}s that are generated. */ - protected Algorithm() { + protected AbstractAlgorithm() { stoppingConditions = new ArrayList<StoppingCondition>(); algorithmListeners = new ArrayList<AlgorithmListener>(); @@ -80,7 +79,7 @@ public abstract class Algorithm implements Cloneable, Runnable { * Copy constructor. Create a deep copy of the provided instance and return it. * @param copy The instance to copy. */ - protected Algorithm(Algorithm copy) { + protected AbstractAlgorithm(AbstractAlgorithm copy) { stoppingConditions = new ArrayList<StoppingCondition>(); for (StoppingCondition stoppingCondition : copy.stoppingConditions) { StoppingCondition clone = stoppingCondition.getClone(); @@ -104,7 +103,7 @@ public abstract class Algorithm implements Cloneable, Runnable { * {@inheritDoc} */ @Override - public abstract Algorithm getClone(); + public abstract AbstractAlgorithm getClone(); /** @@ -280,8 +279,8 @@ public abstract class Algorithm implements Cloneable, Runnable { * Accessor for the top-level currently executing algorithm running in the current thread. * @return the instance of the algorithm that is running in the current thread. */ - public static Algorithm get() { - return currentAlgorithmStack.get().peek(); + public static AbstractAlgorithm get() { + return (AbstractAlgorithm) currentAlgorithmStack.get().peek(); } /** diff --git a/src/main/java/net/sourceforge/cilib/algorithm/Algorithm.java b/src/main/java/net/sourceforge/cilib/algorithm/Algorithm.java index dd307f4..d49e5d2 100644 --- a/src/main/java/net/sourceforge/cilib/algorithm/Algorithm.java +++ b/src/main/java/net/sourceforge/cilib/algorithm/Algorithm.java @@ -21,358 +21,40 @@ */ package net.sourceforge.cilib.algorithm; -import java.util.ArrayList; -import java.util.List; - import net.sourceforge.cilib.problem.OptimisationProblem; import net.sourceforge.cilib.problem.OptimisationSolution; -import net.sourceforge.cilib.stoppingcondition.StoppingCondition; import net.sourceforge.cilib.util.Cloneable; /** - * <p> - * All algorithms in CIlib should be subclasses of <code>Algorithm</code>. This class handles - * stopping criteria, events, threading and measurements. Subclasses of <code>Algorithm</code> - * must provide an implementation for <code>protected abstract void performIteration()</code>. If - * a subclass overrides {@link #initialise()} then it must call <code>super.initialise()</code>. - * Failure to do so will cause an {@linkplain InitialisationException} to be thrown when {@link #run()} - * is called. - * </p> - * @author Edwin Peer + * */ -public abstract class Algorithm implements Cloneable, Runnable { - private static final long serialVersionUID = 7197544770653732632L; - private List<StoppingCondition> stoppingConditions; - private List<AlgorithmListener> algorithmListeners; - private int iterations; - private volatile boolean running; - private boolean initialised; - - protected OptimisationProblem optimisationProblem; - - /** - * This {@linkplain ThreadLocal} variable maintains the stack of the currently - * executing algorithm. It is defined as a static member and as a result is not - * required to be marked as transient as static members are not allowed to be - * serializable according to the Java Specification. - */ - private static ThreadLocal<AlgorithmStack> currentAlgorithmStack = new ThreadLocal<AlgorithmStack>() { - @Override - protected AlgorithmStack initialValue() { - return new AlgorithmStack(); - } - }; - - /** - * Default constructor for {@linkplain Algorithm} classes. Sets up the correct state - * for the instance and initialises the needed containers needed for the different - * {@linkplain AlgorithmEvent}s that are generated. - */ - protected Algorithm() { - stoppingConditions = new ArrayList<StoppingCondition>(); - algorithmListeners = new ArrayList<AlgorithmListener>(); - - running = false; - initialised = false; - } - - /** - * Copy constructor. Create a deep copy of the provided instance and return it. - * @param copy The instance to copy. - */ - protected Algorithm(Algorithm copy) { - stoppingConditions = new ArrayList<StoppingCondition>(); - for (StoppingCondition stoppingCondition : copy.stoppingConditions) { - StoppingCondition clone = stoppingCondition.getClone(); - clone.setAlgorithm(this); - stoppingConditions.add(clone); - } - - algorithmListeners = new ArrayList<AlgorithmListener>(); - for (AlgorithmListener listen : copy.algorithmListeners) { - algorithmListeners.add(listen.getClone()); - } - - running = false; - initialised = false; - - if (copy.optimisationProblem != null) - optimisationProblem = copy.optimisationProblem.getClone(); - } - - /** - * {@inheritDoc} - */ - @Override - public abstract Algorithm getClone(); - - - /** - * Reset the {@linkplain Algorithm} internals if needed. - */ - public void reset() { - throw new UnsupportedOperationException("'reset()' method not implemented for '" + this.getClass().getName() + "'"); - } - - /** - * Initialises the algorithm. Must be called before {@link #run()} is called. - */ - public final void initialise() { - iterations = 0; - running = true; - initialised = true; - - if (stoppingConditions.isEmpty()) - throw new InitialisationException("No stopping conditions specified"); - - for (StoppingCondition stoppingCondition : stoppingConditions) - stoppingCondition.setAlgorithm(this); - - currentAlgorithmStack.get().push(this); - performInitialisation(); - currentAlgorithmStack.get().pop(); - } - - /** - * Perform the actions of the current {@linkplain Algorithm} for a single iteration. This - * method calls {@linkplain Algorithm#algorithmIteration()} after it performs some - * internal tasks by maintaining the stack of the currently executing algorithm instances. - */ - public final void performIteration() { - currentAlgorithmStack.get().push(this); - algorithmIteration(); - iterations++; - currentAlgorithmStack.get().pop(); - } - - /** - * The actual operations that the current {@linkplain Algorithm} performs within a single - * iteration. - */ - protected abstract void algorithmIteration(); - - /** - * Perform the needed initialisation required before the execution of the algorithm - * starts. - */ - public void performInitialisation() { - // subclasses can override the behaviour for this method - } - - /** - * Perform the needed unintialisation steps after the algorithm completes it's - * execution. - */ - public void performUninitialisation() { - // subclasses can override the behaviour for this method - } - - /** - * Executes the algorithm. - * @exception InitialisationException algorithm was not properly initialised. - */ - @Override - public void run() { - if (!initialised) { - throw new InitialisationException("Algorithm not initialised"); - } - - fireAlgorithmStarted(); - - currentAlgorithmStack.get().push(this); - - while (running && (!isFinished())) { - performIteration(); - fireIterationCompleted(); - } +public interface Algorithm extends Cloneable { - if (running) { - fireAlgorithmFinished(); - } - else { - fireAlgorithmTerminated(); - } + public OptimisationSolution getBestSolution(); - performUninitialisation(); + public void performIteration(); - currentAlgorithmStack.remove(); - } - - /** - * Adds a stopping condition. - * @param stoppingCondition A {@link net.sourceforge.cilib.stoppingcondition.StoppingCondition} - * to be added. - */ - public final void addStoppingCondition(StoppingCondition stoppingCondition) { - stoppingConditions.add(stoppingCondition); - } - - /** - * Removes a stopping condition. - * @param stoppingCondition The {@link net.sourceforge.cilib.stoppingcondition.StoppingCondition} - * to be removed. - */ - public final void removeStoppingCondition(StoppingCondition stoppingCondition) { - stoppingConditions.remove(stoppingCondition); - } - - /** - * Adds an algorithm event listener. Event listeners are notified at various stages during the - * execution of an algorithm. - * @param listener An {@link AlgorithmListener} to be added. - */ - public final void addAlgorithmListener(AlgorithmListener listener) { - algorithmListeners.add(listener); - } - - /** - * Removes an algorithm event listener. - * @param listener The {@link AlgorithmListener} to be removed. - */ - public final void removeAlgorithmListener(AlgorithmListener listener) { - algorithmListeners.remove(listener); - } - - /** - * Returns the number of iterations that have been performed by the algorihtm. - * @return The number of iterations. - */ - public final int getIterations() { - return iterations; - } - - /** - * Returns the percentage the algorithm is from completed (as a fraction). The percentage - * complete is calculated based on the stopping condition that is closest to finished. - * @return The percentage complete as a fraction. + /** + * Not Needed>??>???????????? */ - public final double getPercentageComplete() { - double percentageComplete = 0; - for (StoppingCondition condition : stoppingConditions) { - if (condition.getPercentageCompleted() > percentageComplete) { - percentageComplete = condition.getPercentageCompleted(); - } - } - return percentageComplete; - } + public void performInitialisation(); - /** - * Returns true if the algorithm has finished executing. - * @return true if the algorithm is finished + /** + * Not Needed>??>???????????? */ - public final boolean isFinished() { - for (StoppingCondition condition : stoppingConditions) { - if (condition.isCompleted()) { - return true; - } - } - return false; - } + public void performUninitialisation(); - /** - * Terminates the algorithm. - */ - public final void terminate() { - running = false; - } + public Iterable<OptimisationSolution> getSolutions(); - /** - * Accessor for the top-level currently executing algorithm running in the current thread. - * @return the instance of the algorithm that is running in the current thread. - */ - public static Algorithm get() { - return currentAlgorithmStack.get().peek(); - } + public OptimisationProblem getOptimisationProblem(); /** - * Static accessor to allow the current level of algorithm composition to be returned. - * @see AlgorithmStack#asList() - * @return An unmodifiable list of algorithms. + * ???? Not needed? */ - public static List<Algorithm> getAlgorithmList() { - return currentAlgorithmStack.get().asList(); - } + public void reset(); /** - * Get the current list of {@linkplain StoppingCondition} instances that are - * associated with the current {@linkplain Algorithm}. - * @return The list of {@linkplain StoppingCondition} instances associated with - * the current {@linkplain Algorithm}. + * Not Needed>??>???????????? */ - public List<StoppingCondition> getStoppingConditions() { - return this.stoppingConditions; - } - - /** - * Fire the {@linkplain AlgorithmEvent} to indicate that the {@linkplain Algorithm} - * has started execution. - */ - private void fireAlgorithmStarted() { - for (AlgorithmListener listener : algorithmListeners) { - listener.algorithmStarted(new AlgorithmEvent(this)); - } - } - - /** - * Fire the {@linkplain AlgorithmEvent} to indicate that the {@linkplain Algorithm} - * has finished execution. - */ - private void fireAlgorithmFinished() { - for (AlgorithmListener listener : algorithmListeners) { - listener.algorithmFinished(new AlgorithmEvent(this)); - } - } - - /** - * Fire the {@linkplain AlgorithmEvent} to indicate that the {@linkplain Algorithm} - * has been terminated. - */ - private void fireAlgorithmTerminated() { - for (AlgorithmListener listener : algorithmListeners) { - listener.algorithmTerminated(new AlgorithmEvent(this)); - } - } - - /** - * Fire the {@linkplain AlgorithmEvent} to indicate that the {@linkplain Algorithm} - * has completed an iteration. - */ - private void fireIterationCompleted() { - for (AlgorithmListener listener : algorithmListeners) { - listener.iterationCompleted(new AlgorithmEvent(this)); - } - } - - /** - * Set the optimisation problem to be solved. By default, the problem is <code>null</code>. - * That is, it is necessary to set the optimisation problem before calling {@link #initialise()}. - * @param problem An implementation of the - * {@link net.sourceforge.cilib.problem.OptimisationProblemAdapter} interface. - */ - public void setOptimisationProblem(OptimisationProblem problem) { - this.optimisationProblem = problem; - } - - /** - * Get the specified {@linkplain OptimisationProblem}. - * @return The specified {@linkplain OptimisationProblem}. - */ - public OptimisationProblem getOptimisationProblem() { - return this.optimisationProblem; - } - - /** - * Get the best current solution. This best solution is determined from the personal bests of the - * particles. - * @return The <code>OptimisationSolution</code> representing the best solution. - */ - public abstract OptimisationSolution getBestSolution(); - - /** - * Get the collection of best solutions. This result does not actually make sense in the normal - * PSO algorithm, but rather in a MultiObjective optimization. - * @return The <code>Collection<OptimisationSolution></code> containing the solutions. - */ - public abstract List<OptimisationSolution> getSolutions(); - + public int getIterations(); } diff --git a/src/main/java/net/sourceforge/cilib/algorithm/MultistartOptimisationAlgorithm.java b/src/main/java/net/sourceforge/cilib/algorithm/MultistartOptimisationAlgorithm.java index 8ef8f51..e875eb6 100644 --- a/src/main/java/net/sourceforge/cilib/algorithm/MultistartOptimisationAlgorithm.java +++ b/src/main/java/net/sourceforge/cilib/algorithm/MultistartOptimisationAlgorithm.java @@ -51,7 +51,7 @@ import net.sourceforge.cilib.type.types.Type; * * @author Edwin Peer */ -public class MultistartOptimisationAlgorithm extends Algorithm implements ParticipatingAlgorithm { +public class MultistartOptimisationAlgorithm extends AbstractAlgorithm implements ParticipatingAlgorithm { private static final long serialVersionUID = 1493525363256406120L; /** Creates a new instance of MultistartOptimisationAlgorithm. */ @@ -83,8 +83,8 @@ public class MultistartOptimisationAlgorithm extends Algorithm implements Partic * @param algorithm Any {@link OptimisationAlgorithm} that extends {@link Algorithm}. */ public void setTargetAlgorithm(Algorithm algorithm) { - optimisationAlgorithm = algorithm; - this.algorithm = (Algorithm) algorithm; + optimisationAlgorithm = (AbstractAlgorithm) algorithm; + this.algorithm = (AbstractAlgorithm) algorithm; this.algorithm.addStoppingCondition(singleIteration); } @@ -215,8 +215,8 @@ public class MultistartOptimisationAlgorithm extends Algorithm implements Partic return solutions; } - private Algorithm algorithm; - private Algorithm optimisationAlgorithm; + private AbstractAlgorithm algorithm; + private AbstractAlgorithm optimisationAlgorithm; private int restarts; private SingleIteration singleIteration; private MultistartProblemAdapter problem; diff --git a/src/main/java/net/sourceforge/cilib/algorithm/SingularAlgorithm.java b/src/main/java/net/sourceforge/cilib/algorithm/SingularAlgorithm.java index 195179e..166a1c9 100644 --- a/src/main/java/net/sourceforge/cilib/algorithm/SingularAlgorithm.java +++ b/src/main/java/net/sourceforge/cilib/algorithm/SingularAlgorithm.java @@ -28,7 +28,7 @@ package net.sourceforge.cilib.algorithm; * Examples of such algorithms will include <tt>KMeans</tt>, <tt>Gradient Decent</tt> etc. * */ -public abstract class SingularAlgorithm extends Algorithm { +public abstract class SingularAlgorithm extends AbstractAlgorithm { private static final long serialVersionUID = 8524134633474124524L; /** diff --git a/src/main/java/net/sourceforge/cilib/algorithm/population/PopulationBasedAlgorithm.java b/src/main/java/net/sourceforge/cilib/algorithm/population/PopulationBasedAlgorithm.java index bb81271..e8f54c8 100644 --- a/src/main/java/net/sourceforge/cilib/algorithm/population/PopulationBasedAlgorithm.java +++ b/src/main/java/net/sourceforge/cilib/algorithm/population/PopulationBasedAlgorithm.java @@ -22,7 +22,7 @@ package net.sourceforge.cilib.algorithm.population; import java.util.List; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.initialisation.PopulationInitialisationStrategy; import net.sourceforge.cilib.entity.Entity; import net.sourceforge.cilib.entity.Topology; @@ -33,7 +33,7 @@ import net.sourceforge.cilib.problem.OptimisationSolution; * Base class for all algorithms that manage a collection of * {@linkplain Entity entities} in some manner. */ -public abstract class PopulationBasedAlgorithm extends Algorithm { +public abstract class PopulationBasedAlgorithm extends AbstractAlgorithm { protected PopulationBasedAlgorithm() { } diff --git a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAAccuracyMeasurement.java b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAAccuracyMeasurement.java index 8fe8fcf..05a701c 100644 --- a/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAAccuracyMeasurement.java +++ b/src/main/java/net/sourceforge/cilib/bioinf/rnaprediction/RNAAccuracyMeasurement.java @@ -21,7 +21,6 @@ */ package net.sourceforge.cilib.bioinf.rnaprediction; -import java.util.Collection; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.measurement.Measurement; @@ -47,7 +46,7 @@ public class RNAAccuracyMeasurement implements Measurement { } public Type getValue(Algorithm algorithm) { - Collection<OptimisationSolution> solutions = algorithm.getSolutions(); + Iterable<OptimisationSolution> solutions = algorithm.getSolutions(); StringBuilder sb = new StringBuilder(); //Iterator i = solutions.iterator(); for (OptimisationSolution solution : solutions) { diff --git a/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/AlignmentVisualizer.java b/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/AlignmentVisualizer.java index 364b91a..a449bd7 100644 --- a/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/AlignmentVisualizer.java +++ b/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/AlignmentVisualizer.java @@ -47,7 +47,7 @@ public class AlignmentVisualizer implements Measurement { String lineOfStars=""; fullyMatchedColumnCounter = 0; - ArrayList<String> as = new ArrayList<String>(((AlignmentCreator) ((MSAProblem) algorithm.getOptimisationProblem()).getAlignmentCreator()).getAlignment()); + ArrayList<String> as = new ArrayList<String>((((MSAProblem) algorithm.getOptimisationProblem()).getAlignmentCreator()).getAlignment()); //checks for fully matched columns if (fullColumns) { diff --git a/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/DesiredMaximizationFitness.java b/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/DesiredMaximizationFitness.java index 11aa0c1..2e91123 100644 --- a/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/DesiredMaximizationFitness.java +++ b/src/main/java/net/sourceforge/cilib/bioinf/sequencealignment/DesiredMaximizationFitness.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.bioinf.sequencealignment; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.stoppingcondition.StoppingCondition; @@ -33,7 +34,7 @@ import net.sourceforge.cilib.stoppingcondition.StoppingCondition; */ public class DesiredMaximizationFitness implements StoppingCondition { private static final long serialVersionUID = 6494553632698710933L; - private Algorithm algorithm; + private AbstractAlgorithm algorithm; private double desiredFitness; private int quitAnywayAfterIterations; @@ -69,7 +70,7 @@ public class DesiredMaximizationFitness implements StoppingCondition { } public void setAlgorithm(Algorithm algorithm) { - this.algorithm = algorithm; + this.algorithm = (AbstractAlgorithm) algorithm; } public int getQuitAnywayAfterIterations() { diff --git a/src/main/java/net/sourceforge/cilib/boa/bee/OnlookerBee.java b/src/main/java/net/sourceforge/cilib/boa/bee/OnlookerBee.java index 15e3d02..56f614d 100644 --- a/src/main/java/net/sourceforge/cilib/boa/bee/OnlookerBee.java +++ b/src/main/java/net/sourceforge/cilib/boa/bee/OnlookerBee.java @@ -21,7 +21,7 @@ */ package net.sourceforge.cilib.boa.bee; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.boa.ABC; @@ -68,7 +68,7 @@ public class OnlookerBee extends AbstractBee implements HoneyBee { */ @Override public void updatePosition() { - ABC algorithm = (ABC) Algorithm.get(); + ABC algorithm = (ABC) AbstractAlgorithm.get(); HoneyBee target = targetSelectionStrategy.select(algorithm.getWorkerBees()); while (target == this) { diff --git a/src/main/java/net/sourceforge/cilib/boa/bee/WorkerBee.java b/src/main/java/net/sourceforge/cilib/boa/bee/WorkerBee.java index 33339d8..479201f 100644 --- a/src/main/java/net/sourceforge/cilib/boa/bee/WorkerBee.java +++ b/src/main/java/net/sourceforge/cilib/boa/bee/WorkerBee.java @@ -21,7 +21,7 @@ */ package net.sourceforge.cilib.boa.bee; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.boa.ABC; import net.sourceforge.cilib.controlparameter.ConstantControlParameter; import net.sourceforge.cilib.controlparameter.ControlParameter; @@ -67,7 +67,7 @@ public class WorkerBee extends AbstractBee implements HoneyBee { */ @Override public void updatePosition() { - ABC algorithm = (ABC) Algorithm.get(); + ABC algorithm = (ABC) AbstractAlgorithm.get(); HoneyBee target = targetSelectionStrategy.select(algorithm.getWorkerBees()); while (target == this) { 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 8f85a73..7be5f1d 100644 --- a/src/main/java/net/sourceforge/cilib/clustering/kmeans/KMeans.java +++ b/src/main/java/net/sourceforge/cilib/clustering/kmeans/KMeans.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Hashtable; import java.util.List; -import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.algorithm.SingularAlgorithm; import net.sourceforge.cilib.math.Stats; import net.sourceforge.cilib.problem.OptimisationSolution; @@ -85,7 +84,7 @@ public class KMeans extends SingularAlgorithm { * {@inheritDoc} */ @Override - public Algorithm getClone() { + public KMeans getClone() { return new KMeans(this); } diff --git a/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyDecreasingControlParameter.java b/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyDecreasingControlParameter.java index 47db47c..1693b1e 100644 --- a/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyDecreasingControlParameter.java +++ b/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyDecreasingControlParameter.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.controlparameter; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; /** @@ -60,7 +61,7 @@ public class ExponentiallyDecreasingControlParameter extends BoundedControlParam */ @Override public void update() { - double result = Math.exp((-1) * Algorithm.get().getPercentageComplete()); + double result = Math.exp((-1) * AbstractAlgorithm.get().getPercentageComplete()); this.parameter.setReal(result); } diff --git a/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyIncreasingControlParameter.java b/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyIncreasingControlParameter.java index d5a7dd1..43c15b7 100644 --- a/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyIncreasingControlParameter.java +++ b/src/main/java/net/sourceforge/cilib/controlparameter/ExponentiallyIncreasingControlParameter.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.controlparameter; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; /** @@ -60,7 +61,7 @@ public class ExponentiallyIncreasingControlParameter extends BoundedControlParam */ @Override public void update() { - double result = Math.exp(Algorithm.get().getPercentageComplete() - 1); + double result = Math.exp(AbstractAlgorithm.get().getPercentageComplete() - 1); this.parameter.setReal(result); } diff --git a/src/main/java/net/sourceforge/cilib/controlparameter/LinearDecreasingControlParameter.java b/src/main/java/net/sourceforge/cilib/controlparameter/LinearDecreasingControlParameter.java index 84fc6d5..190ca5c 100644 --- a/src/main/java/net/sourceforge/cilib/controlparameter/LinearDecreasingControlParameter.java +++ b/src/main/java/net/sourceforge/cilib/controlparameter/LinearDecreasingControlParameter.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.controlparameter; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; /** @@ -60,7 +61,7 @@ public class LinearDecreasingControlParameter extends BoundedControlParameter { * {@inheritDoc} */ public void update() { - double result = getUpperBound() - (getUpperBound() - getLowerBound()) * Algorithm.get().getPercentageComplete(); + double result = getUpperBound() - (getUpperBound() - getLowerBound()) * AbstractAlgorithm.get().getPercentageComplete(); parameter.setReal(result); } diff --git a/src/main/java/net/sourceforge/cilib/controlparameter/LinearIncreasingControlParameter.java b/src/main/java/net/sourceforge/cilib/controlparameter/LinearIncreasingControlParameter.java index cf18d0b..3f3fb5e 100644 --- a/src/main/java/net/sourceforge/cilib/controlparameter/LinearIncreasingControlParameter.java +++ b/src/main/java/net/sourceforge/cilib/controlparameter/LinearIncreasingControlParameter.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.controlparameter; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; /** @@ -62,7 +63,7 @@ public class LinearIncreasingControlParameter extends BoundedControlParameter { * The update is done in an increasing manner. */ public void update() { - double result = getLowerBound() + (getUpperBound() - getLowerBound()) * Algorithm.get().getPercentageComplete(); + double result = getLowerBound() + (getUpperBound() - getLowerBound()) * AbstractAlgorithm.get().getPercentageComplete(); parameter.setReal(result); } diff --git a/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/ImperfectSplitStrategy.java b/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/ImperfectSplitStrategy.java index 48a2b17..c27b197 100644 --- a/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/ImperfectSplitStrategy.java +++ b/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/ImperfectSplitStrategy.java @@ -23,7 +23,6 @@ package net.sourceforge.cilib.cooperative.splitstrategies; import java.util.List; -import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.algorithm.InitialisationException; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import net.sourceforge.cilib.cooperative.CooperativeEntity; @@ -54,7 +53,7 @@ public class ImperfectSplitStrategy extends IndexedSplitStrategy { int offset = 0; if (remainder == 0) { - for (Algorithm population : populations) { + for (PopulationBasedAlgorithm population : populations) { population.setOptimisationProblem(new CooperativeOptimisationProblemAdapter(problem, context, splitSize, offset)); offset += splitSize; } @@ -75,7 +74,7 @@ public class ImperfectSplitStrategy extends IndexedSplitStrategy { } for (int i = 0; i < populations.size(); ++i) { - Algorithm population = (Algorithm) populations.get(i); + PopulationBasedAlgorithm population = populations.get(i); offset = indices.get(i); int dimension; if ((i + 1) < indices.size()) @@ -83,7 +82,7 @@ public class ImperfectSplitStrategy extends IndexedSplitStrategy { else dimension = problem.getDomain().getDimension() - indices.get(i); // TODO check whether this cast is safe - ((Algorithm) population).setOptimisationProblem(new CooperativeOptimisationProblemAdapter(problem, context, dimension, offset)); + population.setOptimisationProblem(new CooperativeOptimisationProblemAdapter(problem, context, dimension, offset)); } } } diff --git a/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/IndexedSplitStrategy.java b/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/IndexedSplitStrategy.java index 228d402..a5ab93c 100644 --- a/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/IndexedSplitStrategy.java +++ b/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/IndexedSplitStrategy.java @@ -24,7 +24,6 @@ package net.sourceforge.cilib.cooperative.splitstrategies; import java.util.ArrayList; import java.util.List; -import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.algorithm.InitialisationException; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import net.sourceforge.cilib.cooperative.CooperativeEntity; @@ -67,7 +66,7 @@ public class IndexedSplitStrategy implements SplitStrategy { throw new InitialisationException("Problem dimensionality should be equal to or greater than the number of cooperating populations."); for (int i = 0; i < populations.size(); ++i) { - Algorithm population = (Algorithm) populations.get(i); + PopulationBasedAlgorithm population = populations.get(i); int offset = indices.get(i); int dimension; if ((i + 1) < indices.size()) @@ -75,7 +74,7 @@ public class IndexedSplitStrategy implements SplitStrategy { else dimension = problem.getDomain().getDimension() - indices.get(i); // TODO check whether this cast is safe - ((Algorithm) population).setOptimisationProblem(new CooperativeOptimisationProblemAdapter(problem, context, dimension, offset)); + population.setOptimisationProblem(new CooperativeOptimisationProblemAdapter(problem, context, dimension, offset)); } } } diff --git a/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/PerfectSplitStrategy.java b/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/PerfectSplitStrategy.java index 3e053a5..28c17c9 100644 --- a/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/PerfectSplitStrategy.java +++ b/src/main/java/net/sourceforge/cilib/cooperative/splitstrategies/PerfectSplitStrategy.java @@ -23,7 +23,6 @@ package net.sourceforge.cilib.cooperative.splitstrategies; import java.util.List; -import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.algorithm.InitialisationException; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import net.sourceforge.cilib.cooperative.CooperativeEntity; @@ -43,7 +42,7 @@ public class PerfectSplitStrategy implements SplitStrategy { throw new InitialisationException("A Problem with dimension " + problem.getDomain().getDimension() + " cannot be split into parts of equal size when using " + populations.size() + " populations"); int dimension = problem.getDomain().getDimension() / populations.size(); int offset = 0; - for (Algorithm population : populations) { + for (PopulationBasedAlgorithm population : populations) { // TODO check whether this cast is safe population.setOptimisationProblem(new CooperativeOptimisationProblemAdapter(problem, context, dimension, offset)); offset += dimension; diff --git a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_g.java b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_g.java index b753f71..5e0ed80 100755 --- a/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_g.java +++ b/src/main/java/net/sourceforge/cilib/functions/continuous/dynamic/moo/fda1/FDA1_g.java @@ -21,7 +21,7 @@ */ package net.sourceforge.cilib.functions.continuous.dynamic.moo.fda1; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.functions.ContinuousFunction; import net.sourceforge.cilib.type.types.container.Vector; @@ -130,7 +130,7 @@ public class FDA1_g extends ContinuousFunction { */ @Override public Double evaluate(Vector input) { - this.tau = Algorithm.get().getIterations(); + this.tau = AbstractAlgorithm.get().getIterations(); double t = (1.0/(double)n_t)*Math.floor((double)this.tau/(double)this.tau_t); double G = Math.sin(0.5*Math.PI*t); 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 d949cb3..ba6f4e7 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 @@ -21,7 +21,7 @@ */ package net.sourceforge.cilib.functions.continuous.dynamic.moo.fda2; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.functions.ContinuousFunction; import net.sourceforge.cilib.type.types.container.Vector; import net.sourceforge.cilib.problem.FunctionMinimisationProblem; @@ -209,7 +209,7 @@ public class FDA2_h extends ContinuousFunction { */ @Override public Double evaluate(Vector input) { - this.tau = Algorithm.get().getIterations(); + this.tau = AbstractAlgorithm.get().getIterations(); double t = (1.0/(double)n_t)*Math.floor((double)this.tau/(double)this.tau_t); double H = 0.75 + 0.7*(Math.sin(0.5*Math.PI*t)); 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 7e9b33a..3707e7e 100644 --- a/src/main/java/net/sourceforge/cilib/functions/discrete/LongestCommonSubsequence.java +++ b/src/main/java/net/sourceforge/cilib/functions/discrete/LongestCommonSubsequence.java @@ -22,7 +22,7 @@ package net.sourceforge.cilib.functions.discrete; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import net.sourceforge.cilib.functions.DiscreteFunction; import net.sourceforge.cilib.problem.OptimisationProblem; @@ -76,7 +76,7 @@ public class LongestCommonSubsequence extends DiscreteFunction { * @return The shortest length */ private String getShortestString() { - PopulationBasedAlgorithm popAlgorithm = (PopulationBasedAlgorithm) Algorithm.get(); + PopulationBasedAlgorithm popAlgorithm = (PopulationBasedAlgorithm) AbstractAlgorithm.get(); OptimisationProblem problem = popAlgorithm.getOptimisationProblem(); TextDataSetBuilder dataSetBuilder = (TextDataSetBuilder) problem.getDataSetBuilder(); @@ -84,7 +84,7 @@ public class LongestCommonSubsequence extends DiscreteFunction { } private int getDataSetSize() { - PopulationBasedAlgorithm popAlgorithm = (PopulationBasedAlgorithm) Algorithm.get(); + PopulationBasedAlgorithm popAlgorithm = (PopulationBasedAlgorithm) AbstractAlgorithm.get(); OptimisationProblem problem = popAlgorithm.getOptimisationProblem(); TextDataSetBuilder dataSetBuilder = (TextDataSetBuilder) problem.getDataSetBuilder(); @@ -110,7 +110,7 @@ public class LongestCommonSubsequence extends DiscreteFunction { private int matches(Vector x) { - PopulationBasedAlgorithm popAlgorithm = (PopulationBasedAlgorithm) Algorithm.get(); + PopulationBasedAlgorithm popAlgorithm = (PopulationBasedAlgorithm) AbstractAlgorithm.get(); OptimisationProblem problem = popAlgorithm.getOptimisationProblem(); TextDataSetBuilder dataSetBuilder = (TextDataSetBuilder) problem.getDataSetBuilder(); diff --git a/src/main/java/net/sourceforge/cilib/games/random/FixedListSeedingStrategy.java b/src/main/java/net/sourceforge/cilib/games/random/FixedListSeedingStrategy.java index fba7f5e..f85d7b3 100644 --- a/src/main/java/net/sourceforge/cilib/games/random/FixedListSeedingStrategy.java +++ b/src/main/java/net/sourceforge/cilib/games/random/FixedListSeedingStrategy.java @@ -21,7 +21,7 @@ */ package net.sourceforge.cilib.games.random; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; /** * This class is similar to the {@linkplain ListSeedingStrategy} but differs in the following way. @@ -79,7 +79,7 @@ public class FixedListSeedingStrategy extends RandomListSeedingStrategy { if(index >= maxIndex) index = minIndex; //index changes with algorithm iterations - int currentIteration = Algorithm.get().getIterations(); + int currentIteration = AbstractAlgorithm.get().getIterations(); if (currentIteration != changeIteration && currentIteration % iterationModulus == 0) { changeIteration = currentIteration; minIndex += useCount; diff --git a/src/main/java/net/sourceforge/cilib/games/random/RandomListSeedingStrategy.java b/src/main/java/net/sourceforge/cilib/games/random/RandomListSeedingStrategy.java index a55c9bc..ff767bf 100644 --- a/src/main/java/net/sourceforge/cilib/games/random/RandomListSeedingStrategy.java +++ b/src/main/java/net/sourceforge/cilib/games/random/RandomListSeedingStrategy.java @@ -23,7 +23,7 @@ package net.sourceforge.cilib.games.random; import java.util.ArrayList; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.math.random.generator.Seeder; /** @@ -66,7 +66,7 @@ public class RandomListSeedingStrategy extends ListSeedingStrategy { * Check if the seed list needs to be randomised. If so, generate a new list of seeds */ protected void updateSeed(){ - int currentIteration = Algorithm.get().getIterations(); + int currentIteration = AbstractAlgorithm.get().getIterations(); if(currentIteration != changeIteration && currentIteration % iterationModulus == 0){ changeIteration = currentIteration; randomizeSeeds(seeds.size()); diff --git a/src/main/java/net/sourceforge/cilib/measurement/generic/Iterations.java b/src/main/java/net/sourceforge/cilib/measurement/generic/Iterations.java index cb3d91c..e9eac18 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/generic/Iterations.java +++ b/src/main/java/net/sourceforge/cilib/measurement/generic/Iterations.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.measurement.generic; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.measurement.Measurement; import net.sourceforge.cilib.type.types.Int; @@ -63,7 +64,7 @@ public class Iterations implements Measurement { */ public Type getValue(Algorithm algorithm) { Int i = new Int(); - i.setInt(algorithm.getIterations()); + i.setInt(((AbstractAlgorithm)algorithm).getIterations()); return i; } diff --git a/src/main/java/net/sourceforge/cilib/measurement/generic/PercentageComplete.java b/src/main/java/net/sourceforge/cilib/measurement/generic/PercentageComplete.java index 6871341..2d40451 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/generic/PercentageComplete.java +++ b/src/main/java/net/sourceforge/cilib/measurement/generic/PercentageComplete.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.measurement.generic; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.measurement.Measurement; import net.sourceforge.cilib.type.types.Real; @@ -49,7 +50,8 @@ public class PercentageComplete implements Measurement { } public Type getValue(Algorithm algorithm) { - return new Real(algorithm.getPercentageComplete()); + AbstractAlgorithm alg = (AbstractAlgorithm) algorithm; + return new Real(alg.getPercentageComplete()); } } diff --git a/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleFitness.java b/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleFitness.java index ee03830..82dc010 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleFitness.java +++ b/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleFitness.java @@ -21,7 +21,6 @@ */ package net.sourceforge.cilib.measurement.multiple; -import java.util.Collection; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.measurement.Measurement; @@ -89,7 +88,7 @@ public class MultipleFitness implements Measurement { return fitnessValues.toArray();*/ Vector fitnessValues = new Vector(); - Collection<OptimisationSolution> solutions = algorithm.getSolutions(); + Iterable<OptimisationSolution> solutions = algorithm.getSolutions(); for (OptimisationSolution solution : solutions) { Double fitness = solution.getFitness().getValue(); diff --git a/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutions.java b/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutions.java index 7eb41f7..f4de0ed 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutions.java +++ b/src/main/java/net/sourceforge/cilib/measurement/multiple/MultipleSolutions.java @@ -21,7 +21,6 @@ */ package net.sourceforge.cilib.measurement.multiple; -import java.util.List; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.measurement.Measurement; @@ -56,7 +55,7 @@ public class MultipleSolutions implements Measurement { public Type getValue(Algorithm algorithm) { Vector v = new Vector(); - List<OptimisationSolution> solutions = algorithm.getSolutions(); + Iterable<OptimisationSolution> solutions = algorithm.getSolutions(); for (OptimisationSolution solution : solutions) { v.append((Vector) solution.getPosition()); diff --git a/src/main/java/net/sourceforge/cilib/measurement/single/ConvergedDimensions.java b/src/main/java/net/sourceforge/cilib/measurement/single/ConvergedDimensions.java index 1d56a41..80065fb 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/single/ConvergedDimensions.java +++ b/src/main/java/net/sourceforge/cilib/measurement/single/ConvergedDimensions.java @@ -100,7 +100,6 @@ public class ConvergedDimensions implements Measurement { * @throws ParseException if the provided {@code String} cannot be parsed. */ public void setTargetSolution(String stringRepresentation) throws ParseException { - System.out.println("Setting the target solition to: " + stringRepresentation); this.targetSolution = (Vector) DomainParser.parse(stringRepresentation); } diff --git a/src/main/java/net/sourceforge/cilib/measurement/single/FitnessEvaluations.java b/src/main/java/net/sourceforge/cilib/measurement/single/FitnessEvaluations.java index 336d09c..a2b0a2d 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/single/FitnessEvaluations.java +++ b/src/main/java/net/sourceforge/cilib/measurement/single/FitnessEvaluations.java @@ -21,6 +21,7 @@ */ package net.sourceforge.cilib.measurement.single; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.measurement.Measurement; import net.sourceforge.cilib.type.types.Int; diff --git a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/AverageDiversityAroundAllEntities.java b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/AverageDiversityAroundAllEntities.java index 169c567..7c52288 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/AverageDiversityAroundAllEntities.java +++ b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/AverageDiversityAroundAllEntities.java @@ -23,7 +23,7 @@ package net.sourceforge.cilib.measurement.single.diversity; import java.util.Iterator; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import net.sourceforge.cilib.entity.Entity; import net.sourceforge.cilib.type.types.Real; @@ -45,8 +45,7 @@ public class AverageDiversityAroundAllEntities extends Diversity { * {@inheritDoc} */ public Type getValue() { - - PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) Algorithm.get(); + PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) AbstractAlgorithm.get(); int numberOfEntities = algorithm.getTopology().size(); Iterator<? extends Entity> populationCenterIterator = algorithm.getTopology().iterator(); diff --git a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/GBestCenterInitialisationStrategy.java b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/GBestCenterInitialisationStrategy.java index 6e7cbf0..a4cb746 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/GBestCenterInitialisationStrategy.java +++ b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/GBestCenterInitialisationStrategy.java @@ -21,7 +21,7 @@ */ package net.sourceforge.cilib.measurement.single.diversity.centerinitialisationstrategies; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import net.sourceforge.cilib.type.types.container.Vector; @@ -32,7 +32,7 @@ public class GBestCenterInitialisationStrategy extends CenterInitialisationStrat @Override public Vector getCenter() { - PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) Algorithm.get(); + PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) AbstractAlgorithm.get(); return (Vector) algorithm.getTopology().getBestEntity().getCandidateSolution(); } diff --git a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/SpatialCenterInitialisationStrategy.java b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/SpatialCenterInitialisationStrategy.java index 8e92169..10074e8 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/SpatialCenterInitialisationStrategy.java +++ b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/centerinitialisationstrategies/SpatialCenterInitialisationStrategy.java @@ -23,7 +23,7 @@ package net.sourceforge.cilib.measurement.single.diversity.centerinitialisations import java.util.Iterator; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; import net.sourceforge.cilib.entity.Entity; import net.sourceforge.cilib.type.types.container.Vector; @@ -35,7 +35,7 @@ public class SpatialCenterInitialisationStrategy extends CenterInitialisationStr @Override public Vector getCenter() { - PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) Algorithm.get(); + PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) AbstractAlgorithm.get(); int numberOfEntities = algorithm.getTopology().size();//getPopulationSize(); Iterator<? extends Entity> averageIterator = algorithm.getTopology().iterator(); diff --git a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/normalisation/TopologyBasedNormalisation.java b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/normalisation/TopologyBasedNormalisation.java index 04981d0..5ebb10c 100644 --- a/src/main/java/net/sourceforge/cilib/measurement/single/diversity/normalisation/TopologyBasedNormalisation.java +++ b/src/main/java/net/sourceforge/cilib/measurement/single/diversity/normalisation/TopologyBasedNormalisation.java @@ -21,8 +21,9 @@ */ package net.sourceforge.cilib.measurement.single.diversity.normalisation; -import net.sourceforge.cilib.algorithm.Algorithm; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; +import net.sourceforge.cilib.entity.Topology; import net.sourceforge.cilib.entity.visitor.DiameterVisitor; import net.sourceforge.cilib.entity.visitor.TopologyVisitor; @@ -46,7 +47,7 @@ public class TopologyBasedNormalisation extends NormalisationParameter { */ @Override public double getValue() { - PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) Algorithm.get(); + PopulationBasedAlgorithm algorithm = (PopulationBasedAlgorithm) AbstractAlgorithm.get(); visitor.setDistanceMeasure(distanceMeasure); algorithm.accept(visitor); this.normalisationParameter = (Double) visitor.getResult(); diff --git a/src/main/java/net/sourceforge/cilib/moo/iterationstrategies/ArchivingIterationStrategy.java b/src/main/java/net/sourceforge/cilib/moo/iterationstrategies/ArchivingIterationStrategy.java index 124747d..768b16c 100644 --- a/src/main/java/net/sourceforge/cilib/moo/iterationstrategies/ArchivingIterationStrategy.java +++ b/src/main/java/net/sourceforge/cilib/moo/iterationstrategies/ArchivingIterationStrategy.java @@ -24,6 +24,7 @@ package net.sourceforge.cilib.moo.iterationstrategies; import java.util.ArrayList; import java.util.List; +import net.sourceforge.cilib.algorithm.AbstractAlgorithm; import net.sourceforge.cilib.algorithm.Algorithm; import net.sourceforge.cilib.algorithm.population.IterationStrategy; import net.sourceforge.cilib.algorithm.population.PopulationBasedAlgorithm; @@ -72,7 +73,7 @@ public class ArchivingIterationStrategy<E extends PopulationBasedAlgorithm> impl } protected void updateArchive(Topology<? extends Entity> population) { - Algorithm topLevelAlgorithm = Algorithm.getAlgorithmList().get(0); + Algorithm topLevelAlgorithm = AbstractAlgorithm.getAlgorithmList().get(0); List<OptimisationSolution> optimisationSolutions = new ArrayList<OptimisationSolution>(); for (Entity entity : population) { Type solution = entity.getCandidateSolution().getClone(); 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 6173f89..0ed61b1 100644 --- a/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/EvaluationMediator.java +++ b/src/main/java/net/sourceforge/cilib/neuralnetwork/foundation/EvaluationMediator.java @@ -24,13 +24,11 @@ package net.sourceforge.cilib.neuralnetwork.foundation; import java.util.List; -import net.sourceforge.cilib.algorithm.Algorithm; 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; @@ -258,7 +256,7 @@ public class EvaluationMediator extends SingularAlgorithm { } @Override - public Al... [truncated message content] |