content: package aima.gui.demo.search;
  
  import aima.core.search.csp.*;
  import aima.core.search.csp.examples.MapCSP;
  import aima.core.search.csp.solver.*;
  
  import java.util.Optional;
  
  /**
   * Demonstrates the performance of different constraint solving strategies.
   * The map coloring problem from the textbook is used as CSP.
   * 
   * @author Ruediger Lunde
   */
  
  public class MapColoringCspDemo {
  	public static void main(String[] args) {
  		CSP<Variable, String> csp = new MapCSP();
  		CspListener.StepCounter<Variable, String> stepCounter = new CspListener.StepCounter<>();
  		CspSolver<Variable, String> solver;
  		Optional<Assignment<Variable, String>> solution;
  		
  		solver = new MinConflictsSolver<>(1000);
  		solver.addCspListener(stepCounter);
  		stepCounter.reset();
  		System.out.println("Map Coloring (Minimum Conflicts)");
  		solution = solver.solve(csp);
  		solution.ifPresent(System.out::println);
  		System.out.println(stepCounter.getResults() + "\n");
  		
  		solver = new FlexibleBacktrackingSolver<Variable, String>().setAll();
  		solver.addCspListener(stepCounter);
  		stepCounter.reset();
  		System.out.println("Map Coloring (Backtracking + MRV & DEG + LCV + AC3)");
  		solution = solver.solve(csp);
  		solution.ifPresent(System.out::println);
  		System.out.println(stepCounter.getResults() + "\n");
  
  		solver = new FlexibleBacktrackingSolver<Variable, String>().set(CspHeuristics.mrvDeg());
  		solver.addCspListener(stepCounter);
  		stepCounter.reset();
  		System.out.println("Map Coloring (Backtracking + MRV & DEG)");
  		solution = solver.solve(csp);
  		solution.ifPresent(System.out::println);
  		System.out.println(stepCounter.getResults() + "\n");
  		
  		solver = new FlexibleBacktrackingSolver<>();
  		solver.addCspListener(stepCounter);
  		stepCounter.reset();
  		System.out.println("Map Coloring (Backtracking)");
  		solution = solver.solve(csp);
  		solution.ifPresent(System.out::println);
  		System.out.println(stepCounter.getResults() + "\n");
  	}
  }
  