Example #1
0
  /** {@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());
  }
  /**
   * 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;
    }
  }