ECJ-INTEREST-L Archives

January 2016

ECJ-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
ECJ Evolutionary Computation Toolkit <[log in to unmask]>
Date:
Fri, 22 Jan 2016 01:18:04 -0500
MIME-version:
1.0 (Mac OS X Mail 7.3 \(1878.6\))
Reply-To:
ECJ Evolutionary Computation Toolkit <[log in to unmask]>
Content-type:
text/plain; charset=us-ascii
Subject:
From:
Sean Luke <[log in to unmask]>
In-Reply-To:
Message-ID:
Content-Transfer-Encoding:
8bit
Parts/Attachments:
text/plain (161 lines)
1. Don't override checkConstraints.  Get rid of that.

2. Verify that your parameter file is using a NodeConstraints for your class ("&&" I presume) that has two children.

Sean

On Jan 22, 2016, at 12:57 AM, bijoy patwal <[log in to unmask]> wrote:

> Hi,
> I am new to java and genetic programming and trying to write a GA for xor gate using functions and,or,not.
> I am getting an error :-
> Incorrect number of children for node ! at pop.subpop.0.species.ind, was expecting 1 but got 2.
> 
> i would be thankful for any help.
> 
> the definitions of some functions and regression class are as follows-
> 
> NOT.java-
> public class Not extends GPNode 
> {
> 	public String toString() { return "!"; }
> 
>     public int expectedChildren() { return 1; }
>     
>     public void eval(final EvolutionState state,final int thread, final GPData input,final ADFStack stack,
>             final GPIndividual individual, final Problem problem)
>             {
>     			boolean result;
>     			//Boolean_Data rd = ((Boolean_Data)(input));
>     			
>     			Boolean_Data rd = ((Boolean_Data)(input));
>     			children[0].eval(state,thread,input,stack,individual,problem);
>     			result  = !rd.x;
>     			
>     		    
>             }
> }
> 
> And.Java
> 
> public class And extends GPNode 
> {
> 	public String toString() { return "&&"; }
> 
>     public int expectedChildren() { return 2; }
>     
>     public void checkConstraints(final EvolutionState state,final int tree,
>             final GPIndividual typicalIndividual,
>             final Parameter individualBase)
>     {
>     	super.checkConstraints(state,tree,typicalIndividual,individualBase);
>     	if (children.length!=2)
>     		state.output.error("Incorrect number of children for node " + 
>     				toStringForError() + " at " +
>     				individualBase);
>     }
>     
>     public void eval(final EvolutionState state,final int thread,
>             final GPData input,final ADFStack stack,
>             final GPIndividual individual, final Problem problem)
>             {
>     			boolean result;
>     			
>     			Boolean_Data rd = ((Boolean_Data)(input));
>     			children[0].eval(state,thread,input,stack,individual,problem);
>     			result  = rd.x;
>     			
>     			children[1].eval(state,thread,input,stack,individual,problem);
>     		    rd.x=result && rd.x;
>     			
>     		    
>             }
> }
> 
> REGRESSION.java
> public class MultiValuedRegression extends GPProblem implements SimpleProblemForm
> {
> 	public static final String P_DATA = "data";
> 	
> 	public boolean currentX;
> 	public boolean currentY;
> 	public boolean expected_result;
> 	double sum = 0;
> 	int hits=0;
> 	
> 	 public Object clone()
>      {
> 		 MultiValuedRegression newobj = (MultiValuedRegression) (super.clone());
> 		 newobj.input = (Boolean_Data)(input.clone());
> 		 return newobj;
>      }
> 	
> 	public void setup(final EvolutionState state,
>             final Parameter base)
> 	{
> 			super.setup(state,base);
> 
> 			if (!(input instanceof Boolean_Data))
> 				state.output.fatal("GPData class must subclass from " + Boolean_Data.class,
> 			base.push(P_DATA), null);
> 	}
> 	 public void evaluate(final EvolutionState state,  final Individual ind, final int subpopulation, final int threadnum)
> 	{
> 		 			Boolean_Data  input = (Boolean_Data)(this.input);
> 		 			 sum = 0;
> 		 			 hits=0;
> 		 			
> 					currentX=false;
> 					currentY=false;
> 					expected_result= true;
> 					((GPIndividual)ind).trees[0].child.eval(
> 	                        state,threadnum,input,stack,((GPIndividual)ind),this);
> 					
> 					if(expected_result == input.x)
> 					{
> 						sum++;
> 						hits++;
> 					}
> 					
> 					currentX=true;
> 					currentY=false;
> 					expected_result = false;
> 					((GPIndividual)ind).trees[0].child.eval(
> 	                        state,threadnum,input,stack,((GPIndividual)ind),this);
> 					if(expected_result == input.x)
> 					{
> 						sum++;
> 						hits++;
> 					}
> 					
> 					currentX=false;
> 					currentY=true;
> 					expected_result = false;
> 					((GPIndividual)ind).trees[0].child.eval(
> 	                        state,threadnum,input,stack,((GPIndividual)ind),this);
> 					if(expected_result == input.x)
> 					{
> 						sum++;
> 						hits++;
> 					}		
> 					currentX=false;
> 					currentY=false;
> 					expected_result = true;
> 					((GPIndividual)ind).trees[0].child.eval(
> 	                        state,threadnum,input,stack,((GPIndividual)ind),this);
> 					if(expected_result == input.x)
> 					{
> 						sum++;
> 						hits++;	
> 					}	
>             KozaFitness f = ((KozaFitness)ind.fitness);
>             f.setStandardizedFitness(state, sum/4);
>             f.hits = hits;
>             ind.evaluated = true;
> 	}
> 	
> 	
> 	
> }
> 

ATOM RSS1 RSS2