예제 #1
0
파일: Tan.java 프로젝트: Tandrial/AI-SE-Bsc
  /**
   * Try to reduce this node by adhering the given allowed types
   *
   * @param allowed the allowd types
   * @return the reduced node, or this node if no reduction is possible
   */
  @Override
  @SuppressWarnings("unchecked")
  public RealFunction reduce(final NodeTypeSet<RealFunction> allowed) {
    RealFunction oa, a;
    NodeType<Tan, RealFunction> t;
    ConstantType q;

    t = ((NodeType) (this.getType()));
    oa = this.get(0);

    a = oa.reduce(t.getChildTypes(0));
    if ((a.hasConstantValue()) && (!(a.hasEffect()))) {
      q = ConstantType.getConstantType(a, null, allowed);
      if (q != null) {
        if ((allowed == null) || (allowed.containsType(q))) {
          return q.instantiate(compute(a.getConstantValue()));
        }
      }
    }

    if (a != oa) {
      return new Tan(new Node[] {a}, t);
    }

    return this; // super.reduce(allowed);
  }
예제 #2
0
파일: Add.java 프로젝트: Tandrial/AI-SE-Bsc
  /**
   * Try to reduce this node by adhering the given allowed types
   *
   * @param allowed the allowd types
   * @return the reduced node, or this node if no reduction is possible
   */
  @Override
  @SuppressWarnings("unchecked")
  public RealFunction reduce(final NodeTypeSet<RealFunction> allowed) {
    RealFunction oa, ob, a, b;
    NodeType<Add, RealFunction> t;
    ConstantType q;

    t = ((NodeType) (this.getType()));
    oa = this.get(0);
    ob = this.get(1);

    a = oa.reduce(t.getChildTypes(0));
    b = ob.reduce(t.getChildTypes(1));

    if (a.hasConstantValue() && (!(a.hasEffect()))) {

      if (b.hasConstantValue() && (!(b.hasEffect()))) {
        q = ConstantType.getConstantType(a, b, allowed);
        if (q != null) {
          if ((allowed == null) || (allowed.containsType(q))) {
            return q.instantiate( //
                a.getConstantValue() + b.getConstantValue());
          }
        }
      }

      if (a.getConstantValue() == 0d) {
        if ((allowed == null) || (allowed.containsType(b.getType()))) {
          return b;
        }
      }
    }

    if ((b.hasConstantValue() && (!(b.hasEffect()))) && (b.getConstantValue() == 0d)) {
      if ((allowed == null) || (allowed.containsType(a.getType()))) {
        return a;
      }
    }

    if ((a != oa) || (b != ob)) {
      return new Add(new Node[] {a, b}, t);
    }

    return this; // super.reduce(allowed);
  }