Advertisement
Soham_K

MapColoring.java

Jan 15th, 2022
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import org.chocosolver.solver.Model;
  2. import org.chocosolver.solver.Solver;
  3. import org.chocosolver.solver.variables.IntVar;
  4.  
  5. public class MapColoring {
  6.     public static void main(String[] args) {
  7.         Model model = new Model("Map Coloring: Australia");
  8.         IntVar wa = model.intVar("wa", 1, 3);
  9.         IntVar nt = model.intVar("nt", 1, 3);
  10.         IntVar sa = model.intVar("sa", 1, 3);
  11.         IntVar ql = model.intVar("ql", 1, 3);
  12.         IntVar nsw = model.intVar("nsw", 1, 3);
  13.         IntVar vc = model.intVar("vc", 1, 3);
  14.         IntVar ts = model.intVar("ts", 1, 3);
  15.  
  16.         model.arithm(wa, "!=", nt);
  17.         model.arithm(wa, "!=", sa);
  18.         model.arithm(sa, "!=", nt);
  19.         model.arithm(nt, "!=", ql);
  20.         model.arithm(sa, "!=", ql);
  21.         model.arithm(sa, "!=", nsw);
  22.         model.arithm(ql, "!=", nsw);
  23.         model.arithm(sa, "!=", vc);
  24.         model.arithm(nsw, "!=", vc);
  25.  
  26. //        model.allDifferent(wa).post();
  27. //        model.allDifferent(nt).post();
  28. //        model.allDifferent(sa).post();
  29. //        model.allDifferent(ql).post();
  30. //        model.allDifferent(nsw).post();
  31. //        model.allDifferent(vc).post();
  32. //        model.allDifferent(ts).post();
  33.  
  34.         Solver solver = model.getSolver();
  35.         solver.showStatistics();
  36.         solver.showSolutions();
  37.         solver.findSolution();
  38.  
  39.         System.out.println("Western Aus: " + wa);
  40.         System.out.println("Northern territory: " + nt);
  41.         System.out.println("Southern Aus: " + sa);
  42.         System.out.println("Queen's Land: " + ql);
  43.         System.out.println("New South Wales: " + nsw);
  44.         System.out.println("Victoria: " + vc);
  45.         System.out.println("Tasmania: " + ts);
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement