Print

Print


Thanks for your advice. I'll have a try.

Best regards,
Wei


2010/11/25 Sean Luke <[log in to unmask]>
On Nov 24, 2010, at 9:20 PM, Wei He wrote:

In the STGP example of the manual, the val variable can store both boolean and real-valued data. However, in my case, the input from the child (char data) and the the result (Bike data) of a GPNode can not use the same val variable. Should I allocate different fields for them as below?

public class MyData extends GPData {
        public char char_val;
        public Bike Bike_val;
        public GPData copyTo(GPData other) {
                  ((MyData)other).char_val = char_val;
                  ((MyData)other).Bike_val = Bike_val;
                  return other;
        }
}

Sure, that's how I'd do it.  However I would clone Bike_val rather than sharing the pointer.  Also you'll need to implement the MyData.clone() method and in it clone the Bike.  I should show that as an example in the manual.

Now it may be the case that you have certain GPNodes which can accept EITHER a char or a Bike.  In that case I would have an additional boolean which indicates which variable holds the real data.

Sean