Example #1
0
 /** {@inheritDoc} */
 public Node mutate(Random rng, Probability mutationProbability, TreeFactory treeFactory) {
   if (mutationProbability.nextEvent(rng)) {
     return treeFactory.generateRandomCandidate(rng);
   } else {
     Node newLeft = left.mutate(rng, mutationProbability, treeFactory);
     Node newRight = right.mutate(rng, mutationProbability, treeFactory);
     if (newLeft != left && newRight != right) {
       return newInstance(newLeft, newRight);
     } else {
       // Tree has not changed.
       return this;
     }
   }
 }
  @Override
  public List<List<DomBuyRule>> apply(List<List<DomBuyRule>> selectedCandidates, Random rng) {
    List<List<DomBuyRule>> mutants = new ArrayList<List<DomBuyRule>>();
    for (List<DomBuyRule> candidate : selectedCandidates) {
      BuyStrategy mutant = new BuyStrategy(candidate);
      mutants.add(mutant);
    }

    mutants
        .parallelStream()
        .forEach(
            x -> {
              if (probability.nextEvent(rng)) {
                mutate(x, rng);
              }
            });
    return mutants;
  }