> Hello all.
> I am trying to run example with WatchMaker framework, using array of
> primitive integers as population. What class should I use as mutation
> operator?
>
> ...
> // Create a pipeline that applies cross-over then mutation.
> List<EvolutionaryOperator<int[]>> operators =
> newLinkedList<EvolutionaryOperator<
> int[]>>();
> operators.add(/* Here should come *IntArrayMutation()* or something like
> that */);
You will probably have to implement your own mutation operator depending
on exactly how you intend to mutate the integers (there isn't currently a
generic off-the-shelf implementation for you to use). You just need to
implement the single method of the EvolutionaryOperator interface.
Dan.
--
Daniel Dyer
You will probably have to implement your own mutation operator depending
on exactly how you intend to mutate the integers (there isn't currently a
generic off-the-shelf implementation for you to use). You just need to
implement the single method of the EvolutionaryOperator interface.Dan.
--
Daniel Dyer
> Thank you very much for answering, Dan.
> I am doing like this:
> ...
> wmOperators = new LinkedList<>();
> wmOperators.add(new IntArrayCrossover());
> wmOperators.add(new Replacement<int[]>(wmFactory, new
> Probability(0.2d)));
> wmPipeline = new EvolutionPipeline<>(wmOperators);
> ...
> is that OK?
It depends on exactly what you are trying to achieve but I would assume
that you'd normally want a proper mutation operator in there. The
Replacement operator is not the same thing because it does not preserve
any part of the original candidate, it replaces it with a completely new
one. If you want to perform mutation on an array of ints then you'll need
to write your own mutation operator that implements the kind of mutation
that you need. It should be pretty straightforward, just create a class
that implements EvolutionaryOperator:
class IntArrayMutation implements EvolutionaryOperator<int[]>
{
public List<int[]> apply(List<int[]> selectedCandidates, Random rng)
{
List<int[]> results = new
ArrayList<int[]>(selectedCandidates.size());
for (int[] candidate : selectedCandidates)
{
int[] copy = candidate.clone();
// TO DO: Modify the cloned int array here, using the RNG for
any
// required random values.
results.add(copy);
}
return results;
}
}
Dan.
--
Daniel Dyer