コード例 #1
0
ファイル: DeratingNichePSO.java プロジェクト: seekmas/cilib
  @Override
  public void performIteration(NichingAlgorithm alg) {
    Preconditions.checkState(
        alg.getOptimisationProblem() instanceof DeratingOptimisationProblem,
        "DeratingNichePSO can only be used with DeratingOptimisationProblem.");
    DeratingOptimisationProblem problem =
        (DeratingOptimisationProblem) alg.getOptimisationProblem();

    List<PopulationBasedAlgorithm> subswarms =
        List.<PopulationBasedAlgorithm>iterableList(alg.getPopulations());
    subswarms =
        onMainSwarm(Algorithms.<PopulationBasedAlgorithm>initialise())
            .andThen(phase1(alg))
            .andThen(onSubswarms(clearDeratingSolutions(problem)))
            .andThen(phase2(alg))
            .andThen(joinAndMerge(alg, subswarms))
            .f(
                NichingSwarms.of(
                    alg.getMainSwarm(), Collections.<PopulationBasedAlgorithm>emptyList()))
            ._2();

    problem.clearSolutions();
    problem.addSolutions(
        subswarms
            .map(Solutions.getPosition().o(Algorithms.<PopulationBasedAlgorithm>getBestSolution()))
            .toCollection());
    alg.setPopulations(Lists.newLinkedList(subswarms.toCollection()));
    alg.getMainSwarm().setOptimisationProblem(problem);
    // dont need to set the main swarm because it gets reinitialised
  }
コード例 #2
0
  @Test
  public void offspringCreation() {
    Individual i1 = new Individual();
    Individual i2 = new Individual();

    i1.put(Property.CANDIDATE_SOLUTION, Vector.of(0.0, 1.0, 2.0, 3.0, 4.0));
    i2.put(Property.CANDIDATE_SOLUTION, Vector.of(5.0, 6.0, 7.0, 8.0, 9.0));

    i1.setFitnessCalculator(new MockFitnessCalculator());
    i2.setFitnessCalculator(new MockFitnessCalculator());

    List<Individual> parents = Lists.newArrayList(i1, i2);

    CrossoverOperator crossoverStrategy = new CrossoverOperator();
    crossoverStrategy.setCrossoverStrategy(new OnePointCrossoverStrategy());
    crossoverStrategy.setCrossoverProbability(ConstantControlParameter.of(1.0));
    List<Individual> children = crossoverStrategy.crossover(fj.data.List.iterableList(parents));

    Vector child1 = (Vector) children.get(0).getPosition();
    Vector child2 = (Vector) children.get(1).getPosition();
    Vector parent1 = (Vector) i1.getPosition();
    Vector parent2 = (Vector) i2.getPosition();

    Assert.assertEquals(2, children.size());
    for (int i = 0; i < i1.getDimension(); i++) {
      Assert.assertNotSame(child1.get(i), parent1.get(i));
      Assert.assertNotSame(child1.get(i), parent2.get(i));
      Assert.assertNotSame(child2.get(i), parent1.get(i));
      Assert.assertNotSame(child2.get(i), parent2.get(i));
    }
  }
コード例 #3
0
  @Override
  public Object fromBinaryJava(byte[] bytes, Class<?> manifest) {
    OrderFormat orderFormat =
        SerializationExtension.get(system).deserialize(bytes, OrderFormat.class).get();

    return new Order(orderFormat.id, List.iterableList(orderFormat.items), orderFormat.cancelled);
  }
コード例 #4
0
ファイル: ABC.java プロジェクト: Salihu/cilib
  /** {@inheritDoc} */
  @Override
  public void algorithmInitialisation() {
    topology =
        fj.data.List.iterableList(initialisationStrategy.<HoneyBee>initialise(optimisationProblem));

    int numWorkerBees = (int) (workerBeePercentage.getParameter() * topology.length());
    P2<fj.data.List<HoneyBee>, fj.data.List<HoneyBee>> split = topology.splitAt(numWorkerBees);
    this.workerBees = split._1();
    this.onlookerBees =
        split
            ._2()
            .map(
                new F<HoneyBee, HoneyBee>() {
                  public HoneyBee f(HoneyBee b) {
                    return new OnlookerBee((WorkerBee) b);
                  }
                });

    explorerBee.setExplorerBeeUpdateLimit(this.explorerBeeUpdateLimit);
  }
コード例 #5
0
  private List<Integer> getNeighbourhood(final E e) {
    int currentIteration = getIteration();
    if (currentIteration > lastIteration || nHoods == null || perCall) {
      lastIteration = currentIteration;
      nHoods =
          getNeighbourhoods(distanceMeasure, radius, neighbourhoodSize)
              .f(
                  P.p(
                      List.<Entity>iterableList((java.util.List<Entity>) entities).zipIndex(),
                      List.<List<Integer>>nil()));
    }

    final int index = entities.indexOf(e);
    return nHoods
        .find(
            new F<List<Integer>, Boolean>() {
              @Override
              public Boolean f(List<Integer> a) {
                return a.exists(Equal.intEqual.eq(index));
              }
            })
        .orSome(List.single(index));
  }