/home/ooechs/ECJ_Tutorial/src/ac/essex/ecj/functions/Or.java

package ac.essex.ecj.functions; 
 
import ec.gp.GPNode; 
import ec.gp.GPData; 
import ec.gp.ADFStack; 
import ec.gp.GPIndividual; 
import ec.EvolutionState; 
import ec.Problem; 
import ac.essex.ecj.data.DoubleData; 
 
/** 
 * <p/> 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 
 * of the License, or (at your option) any later version, 
 * provided that any use properly credits the author. 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details at http://www.gnu.org 
 * </p> 
 * 
 * @author Olly Oechsle, University of Essex, Date: 18-Aug-2006 
 * @version 1.0 
 */ 
public class Or extends GPNode { 
 
    public void eval(final EvolutionState state, final int thread, final GPData input, final ADFStack stack, final GPIndividual individual, final Problem problem) { 
 
        DoubleData result = ((DoubleData) (input)); 
 
        // evaluate the first child, and save the result 
        children[0].eval(state, thread, input, stack, individual, problem); 
        boolean value1 = (int) result.value == 1; 
 
        // do the same with the second child. 
        children[1].eval(state, thread, input, stack, individual, problem); 
        boolean value2 = (int) result.value == 1; 
 
        // set the value of the result 
        result.value = (value1 || value2)? 1 : 0; 
    } 
 
    public String toString() { 
        return "or"; 
    } 
 
}