All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chen0040.gp.treegp.program.operators.And Maven / Gradle / Ivy

There is a newer version: 1.0.14
Show newest version
package com.github.chen0040.gp.treegp.program.operators;


import com.github.chen0040.gp.commons.Observation;
import com.github.chen0040.gp.treegp.program.Operator;
import com.github.chen0040.gp.treegp.program.Primitive;


/**
 * Created by xschen on 11/5/2017.
 */
public class And extends Operator {
   private static final double mTolerance = 0.0000001;
   private static final long serialVersionUID = 7814710401617777968L;

   public And(){
      super(2, "AND");
   }

   @Override public void execute(Observation observation)       {
      double x1 = this.getInput(0);
      double x2 = this.getInput(1);
      if (isTrue(x1) && isTrue(x2))
      {
         setValue(1);
      }
      else
      {
         setValue(0);
      }
   }

   private boolean isTrue(double x)
   {
      if (x > -mTolerance && x < mTolerance)
      {
         return false;
      }
      return true;
   }


   @Override public Primitive makeCopy() {
      return new And().copy(this);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy