Print

Print


Wei, there are several basic Java errors in your class below.  Here is  
a revised version which fixes them but I've not tested it.

Sean


public class MyData extends GPData {
		
	public char char_val;
	public Bike Bike_val = new Bike_val();

	public Object clone() {
		MyData copy = (MyData) super.clone();
		copy.Bike_val = (Bike) (Bike_val.clone());
		return copy;
	}

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


On Nov 30, 2010, at 4:16 AM, Wei He wrote:

> Hi Sean,
>
> I tried to implement MyData. But, NullPointerException was thrown  
> when cloning the Bike_val which was used by the setup procedure of  
> MyGPProblem(BikeTestDataGe).
> I mean:
>
> public class MyData extends GPData {
> 		
> 	public char char_val;
> 	public Bike Bike_val;
>
> 	@Override
> 	public Object clone() {
> 		MyData copy = (MyData) super.clone();
>
> 		// do any additional initialization required for deep clone
> 		copy.Bike_val = (Bike) copy.Bike_val.clone(); //  
> NullPointerException is thrown
>
> 		return copy;
> 	}
>
> 	@Override
> 	public GPData copyTo(GPData other) {
> 		((MyData) other).char_val = char_val;
>
> 		return other;
> 	}
> }
>
>
> And the stacktrace is as follows,
> java.lang.NullPointerException
> 	at testdatagen.bike.gp.MyData.clone(MyData.java:24)
> 	at ec.gp.ADFContext.setup(ADFContext.java:135)
> 	at ec.gp.ADFStack.setup(ADFStack.java:113)
> 	at ec.gp.GPProblem.setup(GPProblem.java:81)
> 	at testdatagen.bike.gp.BikeTestDataGen.setup(BikeTestDataGen.java:56)
> 	at ec.Evaluator.setup(Evaluator.java:79)
> 	at ec.simple.SimpleEvaluator.setup(SimpleEvaluator.java:36)
> 	at ec.EvolutionState.setup(EvolutionState.java:313)
> 	at  
> ec.simple.SimpleEvolutionState.startFresh(SimpleEvolutionState.java: 
> 50)
> 	at ec.EvolutionState.run(EvolutionState.java:360)
> 	at ec.Evolve.main(Evolve.java:655)
>
>
> It seemed that I didn't get you. Can you please little elaborate?
>
> Thanks,
> Wei
>
>
>
> 2010/11/29 Wei He <[log in to unmask]>
> 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
>
>