Exemplo n.º 1
0
 public static ConditionResultArray combine(ArrayList<ArrayList<ConditionResult>> arrs) {
   ConditionResultArray arr = new ConditionResultArray();
   for (int i = 0; i < arrs.size(); i++) {
     ConditionResult r = new ConditionResult();
     for (int j = 0; j < arrs.get(i).size(); j++) {
       r.join(arrs.get(i).get(j));
     }
     arr.add(r);
   }
   return arr;
 }
Exemplo n.º 2
0
  public ConditionResultArray generateAllPath() {
    ConditionResultArray paths = new ConditionResultArray();
    // 将条件信息初始化
    ArrayList<Integer> condition = new ArrayList<Integer>();
    for (int i = 0; i < this.size(); i++) {
      int count = this.get(i).getCount();
      for (int j = 0; j < count; j++) {
        condition.add(0);
      }
    }
    // 0,1的全排列
    int count = (int) (Math.pow(2, condition.size())) - 1;

    int length = condition.size();
    for (int i = 0; i <= count; i++) {
      System.out.println("-------------------------");
      ConditionResult path = new ConditionResult();
      String strPath = Integer.toString(i, 2);
      int strPathlen = strPath.length();
      if (strPathlen < length) {
        StringBuffer s = new StringBuffer();
        for (int temp = strPathlen; temp < length; temp++) {
          s.append("0");
        }
        strPath = s + strPath;
      }
      //			System.out.println("strPath:"+strPath);
      // int zero = condition.size() - strPath.length();
      for (int j = 0; j < length; j++) {
        if (j < strPath.length()) {
          path.add(strPath.charAt(j) - 48);
        } else {
          path.add(0);
        }
        //				System.out.println("path (i="+i+"j="+j+"):"+path);
      }
      paths.add(path);
      //			System.out.println("path (i="+i+"):"+path);
      // System.out.println(Integer.toString(i, 2));
    }
    System.out.println(paths);
    return paths;
  }