/** {@inheritDoc} */ @Override public void initialise(Problem problem) { StructuredType harmony = problem.getDomain().getBuiltRepresenation().getClone(); harmony.randomize(new MersenneTwister()); setCandidateSolution(harmony); this.getProperties().put(EntityType.FITNESS, InferiorFitness.instance()); }
/** * This is an Synchronous strategy: * * <ol> * <li>For all particles: * <ol> * <li>Update the particle velocity * <li>Update the particle position * </ol> * <li>For all particles: * <ol> * <li>Calculate the particle fitness * <li>For all particles in the current particle's neighbourhood: * <ol> * <li>Update the neighbourhood best * </ol> * </ol> * </ol> * * @see * net.sourceforge.cilib.PSO.IterationStrategy#performIteration(net.sourceforge.cilib.PSO.PSO) * @param pso The {@link PSO} to have an iteration applied. */ @Override public void performIteration(PSO pso) { Topology<Particle> topology = pso.getTopology(); for (Particle current : topology) { current.updateVelocity(); current.updatePosition(); // TODO: replace with visitor (will simplify particle interface) boundaryConstraint.enforce(current); } Problem problem = AbstractAlgorithm.getAlgorithmList().get(0).getOptimisationProblem(); for (Particle current : topology) { current.calculateFitness(); for (Particle other : topology.neighbourhood(current)) { Particle p1 = current.getNeighbourhoodBest().getClone(); Particle p2 = other.getNeighbourhoodBest().getClone(); OptimisationSolution s1 = new OptimisationSolution( p1.getCandidateSolution().getClone(), problem.getFitness(p1.getCandidateSolution().getClone())); OptimisationSolution s2 = new OptimisationSolution( p2.getCandidateSolution().getClone(), problem.getFitness(p2.getCandidateSolution().getClone())); MOFitness fitness1 = (MOFitness) s1.getFitness(); MOFitness fitness2 = (MOFitness) s2.getFitness(); // System.out.println("fitness1 = "); // for (int i=0; i < fitness1.getDimension(); i++) // System.out.println(fitness1.getFitness(i).getValue()); // // System.out.println("fitness2 = "); // for (int i=0; i < fitness2.getDimension(); i++) // System.out.println(fitness2.getFitness(i).getValue()); if (fitness1.compareTo(fitness2) > 0) { other.setNeighbourhoodBest(current); } } } }
/** * Splits up the given {@link OptimisationProblem} into sub-problems, where each sub problem * contains a sequencial (non-uniform sized) portion of the problem vector, and assigns them to * all the participating {@link Algorithm}s. This implementation assigns a portion of length * equals to dimensionality/number of populations + 1 to dimensionality % number of populations of * the participating algorithms. * * @param populations The list of participating {@linkplain PopulationBasedAlgorithm}s. * @param problem The problem that needs to be re-distributed. * @param context The context vector maintained by the {@linkplain * CooperativeCoevolutionAlgorithm}. */ public void performDistribution( List<PopulationBasedAlgorithm> populations, Problem problem, Vector context) { checkArgument( populations.size() >= 2, "There should at least be two Cooperating populations in a Cooperative Algorithm"); int dimension = problem.getDomain().getDimension() / populations.size(); int oddDimensions = problem.getDomain().getDimension() % populations.size(); int i = 0; int offset = 0; for (Algorithm population : populations) { int actualDimension = dimension; if (i < oddDimensions) actualDimension++; DimensionAllocation problemAllocation = new SequencialDimensionAllocation(offset, actualDimension); population.setOptimisationProblem( new CooperativeCoevolutionProblemAdapter(problem, problemAllocation, context)); offset += actualDimension; ++i; } }