private int nbNodeFromRegulatModel(int seed) { m = new CPModel(); s = new CPSolver(); int k = 2; IntegerVariable v0 = makeIntVar("v0", 0, 10); IntegerVariable v1 = makeIntVar("v1", 0, 10); List<int[]> ltuple = new LinkedList<int[]>(); for (int i = 0; i <= 10; i++) { for (int j = 0; j <= 10; j++) { if (Math.abs(i - j) < k) ltuple.add(new int[] {i, j}); } } m.addConstraint(regular(new IntegerVariable[] {v0, v1}, ltuple)); s.read(m); s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32)); s.setValIntSelector(new RandomIntValSelector(seed)); try { s.propagate(); } catch (ContradictionException e) { LOGGER.info(e.getMessage()); // To change body of catch statement use File | Settings | File // Templates. } s.solveAll(); // LOGGER.info("solutions regular : " + s.getNbSolutions()); return s.getNodeCount(); }
@Test public void test1NeqSolve() { for (int seed = 0; seed < 10; seed++) { m = new CPModel(); s = new CPSolver(); int k = 9, k1 = 7, k2 = 6; IntegerVariable v0 = makeIntVar("v0", 0, 10); IntegerVariable v1 = makeIntVar("v1", 0, 10); IntegerVariable v2 = makeIntVar("v2", 0, 10); IntegerVariable v3 = makeIntVar("v3", 0, 10); m.addConstraint(distanceNEQ(v0, v1, k)); m.addConstraint(distanceNEQ(v1, v2, k1)); m.addConstraint(distanceNEQ(v2, v3, k2)); s.read(m); s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32)); s.setValIntSelector(new RandomIntValSelector(seed)); try { s.propagate(); } catch (ContradictionException e) { LOGGER.info(e.getMessage()); } s.solveAll(); int nbNode = s.getNodeCount(); LOGGER.info("solutions : " + s.getNbSolutions() + " nbNode : " + nbNode); assertEquals(s.getNbSolutions(), 12147); } }
@Test public void test3LTSolve() { for (int seed = 0; seed < 10; seed++) { m = new CPModel(); s = new CPSolver(); int k = 2; IntegerVariable v0 = makeIntVar("v0", 0, 10); IntegerVariable v1 = makeIntVar("v1", 0, 10); m.addConstraint(distanceLT(v0, v1, k)); s.read(m); s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32)); s.setValIntSelector(new RandomIntValSelector(seed)); try { s.propagate(); } catch (ContradictionException e) { LOGGER.info(e.getMessage()); // To change body of catch statement use File | Settings | File // Templates. } s.solveAll(); int nbNode = s.getNodeCount(); LOGGER.info("solutions : " + s.getNbSolutions() + " nbNode : " + nbNode); assertEquals(s.getNbSolutions(), 31); assertEquals(nbNodeFromRegulatModel(seed), nbNode); } }
@Test public void test3BoundsSolve() { for (int seed = 0; seed < 10; seed++) { m = new CPModel(); s = new CPSolver(); int k = 9, k1 = 7, k2 = 6; IntegerVariable v0 = makeIntVar("v0", 0, 10); IntegerVariable v1 = makeIntVar("v1", 0, 10); IntegerVariable v2 = makeIntVar("v2", 0, 10); IntegerVariable v3 = makeIntVar("v3", 0, 10); m.addVariables(Options.V_BOUND, v0, v1, v2, v3); m.addConstraint(distanceEQ(v0, v1, k)); m.addConstraint(distanceEQ(v1, v2, k1)); m.addConstraint(distanceEQ(v2, v3, k2)); s.read(m); s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32)); s.setValIntSelector(new RandomIntValSelector(seed)); try { s.propagate(); } catch (ContradictionException e) { LOGGER.info(e.getMessage()); // To change body of catch statement use File | Settings | File // Templates. } s.solveAll(); int nbNode = s.getNodeCount(); LOGGER.info("solutions : " + s.getNbSolutions() + " nbNode : " + nbNode); assertEquals(s.getNbSolutions(), 4); } }
@Test public void testDXYZSolve1() { for (int seed = 0; seed < 10; seed++) { m = new CPModel(); s = new CPSolver(); IntegerVariable v0 = makeIntVar("v0", 0, 5); IntegerVariable v1 = makeIntVar("v1", 0, 5); IntegerVariable v2 = makeIntVar("v2", 0, 5); m.addConstraint(distanceEQ(v0, v1, v2, 0)); s.read(m); s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32)); s.setValIntSelector(new RandomIntValSelector(seed)); s.solveAll(); assertEquals(36, s.getNbSolutions()); } }
@Test public void testDXYZSolve4() { for (int seed = 0; seed < 10; seed++) { m = new CPModel(); s = new CPSolver(); IntegerVariable v0 = makeIntVar("v0", 3, 6); IntegerVariable v1 = makeIntVar("v1", -3, 4); IntegerVariable v2 = makeIntVar("v2", 0, 5); IntegerVariable v3 = makeIntVar("v3", 2, 5); m.addConstraint(distanceGT(v0, v1, v2, 0)); m.addConstraint(distanceGT(v0, v2, v3, 0)); s.read(m); s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32)); s.setValIntSelector(new RandomIntValSelector(seed)); s.solveAll(); LOGGER.info("nbsol " + s.getNbSolutions()); assertEquals(getNbSolByDecomp(2), s.getNbSolutions()); } }
public void setHeuristic(ChocoHeuristic heuristic) { switch (heuristic) { case MIN_DOMAIN: { solver.setVarIntSelector(new MinDomain(solver, solver.getVar(model.getVariables()))); break; } case DOM_OVER_WDEG: { solver.addGoal( new DomOverWDegBranchingNew( solver, solver.getVar(model.getVariables()), new IncreasingDomain(), 1)); break; } case DEFAULT: { // default heuristic break; } } }