コード例 #1
0
  public boolean isBetterThan(Solution s1, Solution s2) { // s1 e' migliore di s2????

    int i = 1;
    boolean found = false, result = false;
    for (i = 0; !found && i < s1.getValue().length(); i++) {
      if ((s1.getValue()).charAt(i) != (s2.getValue()).charAt(i)) found = true;
    }
    i--;
    // System.out.println("cambia in pos: "+i);
    Vertex v = cpnet.getAdjList().get(i);
    if (v.getParents().isEmpty()) {
      result =
          (v.getPreferences().get(0).getIsAffirmedValue())
              ? s1.getValue().charAt(i) == '1'
              : s1.getValue().charAt(i) == '0';
    } else {
      System.out.println(
          "----------------" + s1.getValue() + "e meglio di " + s2.getValue() + "????");
      // controlla preferenza padre
      String parentsPref = "";

      // System.out.println("i parents di " + v.getID() + "sono: ");
      // for(Integer ii : v.getParents()) System.out.println(ii.toString());

      //			for(int k = 1; k < s1.getValue().length();  k++){
      //				System.out.println("guardo se " + cpnet.getAdjList().get(k).getID().toString() + " e
      // parent");
      //				if(v.getParents().contains(cpnet.getAdjList().get(k).getID())){
      //					parentsPref += s1.getValue().charAt(k);
      //					System.out.println("new parent pref " + parentsPref);
      //				}
      //		    }

      for (Integer k : v.getParents()) {
        // System.out.println("parent "+k);
        parentsPref += s1.getValue().charAt(k);
      }
      System.out.println("per " + v.getID() + " ottengo parentPref=" + parentsPref);

      for (Preference p : v.getPreferences()) {
        // System.out.println("preference considerata: " + p.toString());
        if (p.getBinaryValue() == ListUtils.fromBinToInt(parentsPref)) {
          // System.out.println(p.getBinaryValue() + " e' uguale a " +
          // ListUtils.fromBinToInt(parentsPref));
          System.out.println(p.toString());
          result =
              (p.getIsAffirmedValue())
                  ? s1.getValue().charAt(i) == '1'
                  : s1.getValue().charAt(i) == '0';
          // System.out.println("trovata e i="+i);
          // System.out.println(s1.getValue().charAt(i) == '1');
          // System.out.println(s1.getValue().charAt(i) == '0');
          System.out.println(result);
        }
      }
    }
    // System.out.println(result);
    return result;
  }