Constraints not being imposed

39 views
Skip to first unread message

Abhishek Kumar

unread,
Sep 9, 2021, 10:49:15 AM9/9/21
to or-tools-discuss
Hello everyone!,

I have three lists: BVILobby, CCGLobby and VRLobby.

The solution set will comprise of elements from these three lists. I want to ensure that no more than half (1/2) of all elements in solution set comprise of elements from BVILobby set and No more than one-third (1/3) of all elements in solution set comprise of elements from CCGLobby set, in the Final solution. The equations are as follows:

solver.Add(solver.Sum(2 * (X_j[BVILobby.index(l)]) for l in BVILobby) <=(solver.Sum((X_j[j]) for j in DUTY_COUNTER))) and\
solver.Add(solver.Sum(3 * (X_j[CCGLobby.index(k)]) for k in CCGLobby) <= (solver.Sum((X_j[j]) for j in DUTY_COUNTER)))

Here, X_j[j] = 1, if  duty j in final solution, 0 otherwise and DUTY_COUNTER  contains numbers corresponding to whole feasible solution set, from which the optimum is being derived. In some cases it does give the solutions in ratios specified but in some cases the constraints are not being followed at all. It gives solution clearly violating the ratios, and not giving warning of infeasibility.

I am using pywraplp as solver. I tried with pywrapcp also, but same results

Any help in this regard will be highly appreciated.

Thanks,
Abhishek

Laurent Perron

unread,
Sep 9, 2021, 10:59:44 AM9/9/21
to or-tools-discuss
using the python and will prevent python from evaluating the second equation as the first one returns a constraint object that always evaluates to True.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/a46023ce-9fd4-4daa-afe1-b405dcb16eadn%40googlegroups.com.

Abhishek Kumar

unread,
Sep 9, 2021, 12:45:59 PM9/9/21
to or-tools-discuss
Thanks for your reply. But I have tried changing the order of constraints, like putting the second part of and at first position, but the answer is same. Moreover, the first part i.e.  solver.Add(solver.Sum(2 * (X_j[BVILobby.index(l)]) for l in BVILobby) <=(solver.Sum((X_j[j]) for j in DUTY_COUNTER))) is mostly getting violated.

Anyway to avoid it?

Thanks,
Abhishek

Laurent Perron

unread,
Sep 9, 2021, 1:05:22 PM9/9/21
to or-tools-discuss
add 2 constraints separately ?


Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Laurent Perron

unread,
Sep 9, 2021, 1:05:59 PM9/9/21
to or-tools-discuss
And I would suggest using CP-SAT for that.

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Abhishek Kumar

unread,
Sep 9, 2021, 1:19:22 PM9/9/21
to or-tools...@googlegroups.com
Already tried, with same results.

Thanks,
Abhishek

Abhishek Kumar

unread,
Sep 9, 2021, 1:20:23 PM9/9/21
to or-tools...@googlegroups.com
CP-SAT part, I haven't.

Abhishek Kumar

unread,
Sep 9, 2021, 6:25:31 PM9/9/21
to or-tools...@googlegroups.com
The problem persists even after switching to CP - SAT. Tried and verified.

Thanks,
Abhishek

Laurent Perron

unread,
Sep 10, 2021, 1:40:24 AM9/10/21
to or-tools-discuss
Reply all
Reply to author
Forward
0 new messages