Package aima.core.search.csp

Examples of aima.core.search.csp.SolutionStrategy


     * necessary.
     */
    protected void prepareActions() {
      ImprovedBacktrackingStrategy iStrategy = null;
      if (actions.isEmpty()) {
        SolutionStrategy strategy = null;
        switch (frame.getSelection().getValue(
            MapColoringFrame.STRATEGY_SEL)) {
        case 0:
          strategy = new BacktrackingStrategy();
          break;
        case 1: // MRV + DEG
          strategy = new ImprovedBacktrackingStrategy
          (true, true, false, false);
          break;
        case 2: // FC
          iStrategy = new ImprovedBacktrackingStrategy();
          iStrategy.setInference(ImprovedBacktrackingStrategy
                  .Inference.FORWARD_CHECKING);
          break;
        case 3: // MRV + FC
          iStrategy = new ImprovedBacktrackingStrategy
          (true, false, false, false);
          iStrategy.setInference(ImprovedBacktrackingStrategy
                  .Inference.FORWARD_CHECKING);
          break;
        case 4: // FC + LCV
          iStrategy = new ImprovedBacktrackingStrategy
          (false, false, false, true);
          iStrategy.setInference(ImprovedBacktrackingStrategy
                  .Inference.FORWARD_CHECKING);
          break;
        case 5: // AC3
          strategy = new ImprovedBacktrackingStrategy
          (false, false, true, false);
          break;
        case 6: // MRV + DEG + AC3 + LCV
          strategy = new ImprovedBacktrackingStrategy
          (true, true, true, true);
          break;
        case 7:
          strategy = new MinConflictsStrategy(50);
          break;
        }
        if (iStrategy != null)
          strategy = iStrategy;
       
        try {
          strategy.addCSPStateListener(new CSPStateListener() {
            @Override
            public void stateChanged(Assignment assignment, CSP csp) {
              actions.add(new CSPEnvironment.StateChangeAction(
                  assignment, csp));
            }
            @Override
            public void stateChanged(CSP csp) {
              actions.add(new CSPEnvironment.StateChangeAction(
                  csp));
            }
          });
          strategy.solve(env.getCSP().copyDomains());
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
View Full Code Here


public class MapColoringCSPDemo {
  public static void main(String[] args) {
    CSP csp = new MapCSP();
    StepCounter stepCounter = new StepCounter();
    SolutionStrategy solver;
   
    solver = new MinConflictsStrategy(1000);
    solver.addCSPStateListener(stepCounter);
    stepCounter.reset();
    System.out.println("Map Coloring (Minimum Conflicts)");
    System.out.println(solver.solve(csp.copyDomains()));
    System.out.println(stepCounter.getResults() + "\n");
   
    solver = new ImprovedBacktrackingStrategy(true, true, true, true);
    solver.addCSPStateListener(stepCounter);
    stepCounter.reset();
    System.out.println("Map Coloring (Backtracking + MRV + DEG + AC3 + LCV)");
    System.out.println(solver.solve(csp.copyDomains()));
    System.out.println(stepCounter.getResults() + "\n");
   
    solver = new BacktrackingStrategy();
    solver.addCSPStateListener(stepCounter);
    stepCounter.reset();
    System.out.println("Map Coloring (Backtracking)");
    System.out.println(solver.solve(csp.copyDomains()));
    System.out.println(stepCounter.getResults() + "\n");
  }
View Full Code Here

TOP

Related Classes of aima.core.search.csp.SolutionStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.