コード例 #1
0
ファイル: Colorizer.java プロジェクト: bahadrix/MapCoFX2
  public void runWith(SUVType suvType, ODVType odvType, boolean forwarChecking) {
    // Problemi oluştur
    CSP csp = new CSP(graph, 5, suvType, odvType, forwarChecking);
    CSP.AssignmentsState result = csp.backTrack();

    // Atamaya göre düğümleri boya
    paintAssignment(result.getAssignments());

    // Sonucu bildir
    System.out.println();
    System.out.println("=====");
    System.out.println();
    if (csp.checkComplete(result.getAssignments())) {
      System.out.println("Problem çözüldü!");
    } else {
      System.out.println(result.getAssignments().size() + ". düğümden sonrası gelmedi ");
    }

    // İstatistikleri yaz
    System.out.println(csp.stats);
  }
コード例 #2
0
 protected void fireStateChanged(Assignment assignment, CSP csp) {
   for (CSPStateListener listener : listeners)
     listener.stateChanged(assignment.copy(), csp.copyDomains());
 }
コード例 #3
0
 protected void fireStateChanged(CSP csp) {
   for (CSPStateListener listener : listeners) listener.stateChanged(csp.copyDomains());
 }
コード例 #4
-1
 public boolean isSatisfied() {
   Solution current = csp.getCurrentSolution();
   Assignment lastAssignment = csp.getCurrentSolution().getLastAssignment();
   for (Iterator ite = current.getAssignments().iterator(); ite.hasNext(); ) {
     Assignment previousAssignment = (Assignment) ite.next();
     if (!lastAssignment.getVariable().equals(previousAssignment.getVariable())) {
       if (lastAssignment.getValue().equals(previousAssignment.getValue())) {
         return false;
       }
     }
   }
   return true;
 }
コード例 #5
-16
  /**
   * The actual minConflicts algorithm
   *
   * @param csp An CSP
   * @param maxSteps The maximum amount of steps to take before bailing
   * @return The number of steps actually taken, or -1 if we bailed.
   */
  private short minConflicts(CSP csp, short maxSteps) {

    short shuffleList[] = new short[csp.board];
    for (short i = 0; i < csp.board; ++i) {
      shuffleList[i] = i;
    }

    for (short i = 0; i < maxSteps; ++i) {
      if (csp.solution()) {
        return i;
      }

      shuffle(shuffleList);

      for (short n = 0; n < csp.board; ++n) {
        if (csp.isConflicted(shuffleList[n])) {
          short moveTo = csp.minConflicts(shuffleList[n]);

          csp.matrix[shuffleList[n]] = moveTo;

          break;
        }
      }
    }
    return -1;
  }