On Jun 1, 2007, at 9:13 AM, Mehdi Khoury wrote:
> Just trying to contribute by adding one small tutorial to write
> in a file in a simple and quick fashion (no need to use statistic or
> complicated stuff) with ECJ.
> For those interested, see at :
Hi Medhi, nice review: yes, ECJ could use better documentation
still. Actually, I was working on a journal article about it but put
it aside for a while. It's got lots of great diagrams we might use
in a manual some day. Here's some early random text and the pics --
people might be interested in this (don't repost it though):
> On individual is composed of ADFs the following way:
> | | |
> ADF1 ADF2 ADF3
> ADF2 can reuse as a terminal ADF1, and ADF3 can reuse ADF1 and ADF2.
> I evaluate the fitness f1 of an individual the normal way, and
> return my
> global fitness at the top of the tree.
> I also want to record what would be the fitness f2 of the
> individual if ADF1
> was equal to a different value.
> Similarly, I would also like to record what would be the fitness f3
> of the
> individual if ADF1 and ADF2 were equal to different values.
> To be able to do that, my GPNode functions and terminals are
> returning an
> array of values (as extension of GPData ) instead of just one
> value. Each
> cell in the array correspond to one different scenario for a
> fitness value.
> My problem is the following: every normal operator and terminal
> return the
> right thing. Except the ADFs !! I want every ADFs terminal to
> return an
> array of values:
> - one value being the normal calculated value resulted from the
> generated tree
> - other values being new input values that I choose to substitute.
> I guess something must be done in the eval() method at the level of
> one of
> the ADFs classes : either ADF, or ADFArgument or ADFContext.
> I am a bit confused about how to proceed, though...
Assuming that your standard operators are already set up to receive
and return arrays (check out Multiplexer for a clever use of that
technique), then I think this is probably fairly straightforward:
1. In ADF.java (or better, a drop-in subclass you create), you'll
need to modify eval so that it returns in GPData an array. You might
do it like this:
public void eval(final EvolutionState state,
final int thread,
final GPData input,
final ADFStack stack,
final GPIndividual individual,
final Problem problem)
ADFContext c = stack.get();
/// ----- I CHANGED HERE ----
// let's assume that all of your operators use arrays -- that way we
// reuse GPData
MyGPData in = (MyGPData)input;
for(int i=0;i<in.data.length;i++) in.data[i] = 0; // or whatever
// now we imagine that the result came back in in.data
in.data = 2; // our hard-coded item #1
in.data = 3; // our hard-coded item #2
/// ------ END CHANGES ------
if (stack.pop(1) != 1)
state.output.fatal("Stack prematurely empty for " +
Assuming your standard operators are expecting three return values
handed them and perform the same operation on all three in parallel
and hand off the results, then something along these lines should
work, I imagine.