Hi, I have a problem to solve an optimisation problem using dynamic constraints. This is the code:
public static void main (String args[]) { CPModel m = new CPModel(); IntegerVariable [] roles = new IntegerVariable[3]; CPSolver s = new CPSolver(); for (int k = 0; k < 3; k++) roles[k] = Choco.makeIntVar("role" + k, 1, 3); m.addVariable(roles); IntegerVariable obj1 = Choco.makeIntVar("sum"); m.addConstraint(Choco.eq(obj1, Choco.sum(roles))); s.read(m);
** s.minimize(s.getVar(obj1), true)**; s.generateSearchStrategy();
int numSolution=0; if(s.solve()){ System.out.println("The solutions Are 1:"); do{ for(int i=0;i<3;i++) { String r=s.getVar(roles[i])+""; System.out.println(r); } numSolution++; }while (s.nextSolution()); }
** s.post(new NotEqualXC(s.getVar(roles[0]), 1));**
int numSolution1=0; if(s.solve()){ System.out.println("The solutions Are2:"); do{ for(int i=0;i<3;i++) { String r=s.getVar(roles[i])+""; System.out.println(r); } numSolution1++; }while (s.nextSolution()); }
}
the result is: The solutions Are1: role0:1 role1:1 role2:1 ** CHOCO : Constraint Programming Solver ** CHOCO v2.1.5 (August, 2012), Copyleft (c) 1999-2012 - Initial Propagation: Contradiction due to role0:1 != 1 - Search completed: No solutions Minimize: sum:3 Solutions: 0 Time (ms): 10 Nodes: 0 Backtracks: 0 Restarts: 0
I dont understand why there are no solution when i add a dynamic constraint to my problem! Thanks
Hello,
You do not restart the search or create a new solver. Anyway, I would suggest to upgrade to choco3.
Cheers.
Log in to post a comment.
Hi,
I have a problem to solve an optimisation problem using dynamic constraints.
This is the code:
** s.minimize(s.getVar(obj1), true)**;
s.generateSearchStrategy();
** s.post(new NotEqualXC(s.getVar(roles[0]), 1));**
}
the result is:
The solutions Are1:
role0:1
role1:1
role2:1
** CHOCO : Constraint Programming Solver
** CHOCO v2.1.5 (August, 2012), Copyleft (c) 1999-2012
- Initial Propagation: Contradiction due to role0:1 != 1
- Search completed: No solutions
Minimize: sum:3
Solutions: 0
Time (ms): 10
Nodes: 0
Backtracks: 0
Restarts: 0
I dont understand why there are no solution when i add a dynamic constraint to my problem!
Thanks
Hello,
You do not restart the search or create a new solver.
Anyway, I would suggest to upgrade to choco3.
Cheers.