예제 #1
0
파일: Tree.java 프로젝트: USTORG/ECProject
  /**
   * function to build the tree with its Xvalues and creates the nodes from String expression based
   * on Prefix expression format as parameter
   */
  public void buildTree(String str) {
    this.prefix = str;
    Helper help = new Helper();
    ArrayList<String> functionexpression = new ArrayList<>();
    for (int i = 0; i < ts.xValues.length; i++) {
      functionexpression = help.replaceXwithValue(str, ts.xValues[i]);

      this.buildTreeWithValues(functionexpression);
    }
  }
예제 #2
0
파일: Tree.java 프로젝트: USTORG/ECProject
  // change to arraylist
  private double[] calculateRealOutPutValues(String suggestedFunctionExpression) throws Exception {
    this.realOutPutValues = null;
    Tree[] tree = new Tree[ts.xValues.length];
    Helper help = new Helper();
    realOutPutValues = new double[ts.xValues.length];

    for (int i = 0; i < ts.xValues.length; i++) {

      ArrayList<String> functionexpression =
          help.replaceXwithValue(suggestedFunctionExpression, this.ts.xValues[i]);

      tree[i] = new Tree(true);
      tree[i].setPrefix(suggestedFunctionExpression);
      tree[i].buildTreeWithValues(functionexpression);
      realOutPutValues[i] = tree[i].evaluate();
      this.validTree = tree[i].validTree;
      if (this.validTree == false) break;
    }

    return this.realOutPutValues;
  }