How to forumulate an indicator constraint without addGenConstrIndicator
Hi Community
I'm trying to formulate a conditional Constraint without the addGenConstrIndicator Method. The reason is, that my Prof said, that I should formulate it with Big M logical conditions, so I can transfer the code to other solver that I have to evaluate.
Szenario:
The problem I solve is the Examination Timetabling Problem. The constraint I'm implementing is to minimize the number of rooms that are used.
Can you help to find the error in the addGenConstrIndicator formulation? And how can I formulate the same without addGenConstrIndicator? Is there an example?
Kind regards
Carlo
GRBVar[] roomUsed = new GRBVar[getIlpModel().getRooms().size()];
for (Room r : getIlpModel().getRooms()) {
roomUsed[indexOf(r)] = getGrbModel().addVar(1, 1, 1.0, GRB.BINARY, r.toString());
}
for (Room r : getIlpModel().getRooms()) {
GRBLinExpr lhs = new GRBLinExpr();
for (Timeslot t : getIlpModel().getTimeslots()) {
for (Presentation p : getIlpModel().getPresentations()) {
if (getX()[indexOf(p)][indexOf(t)][indexOf(r)] == null) continue;
lhs.addTerm(1.0, getX()[indexOf(p)][indexOf(t)][indexOf(r)]);
}
}
// if lhs >= 1 then roomUsed
// if lhs <= 0 then !roomUsed
// At most N of A, B, C,... a + b + c+. . . ≤ N
// At least N of A, B, C,... a + b + c+. . . ≥ N
getGrbModel().addGenConstrIndicator(roomUsed[indexOf(r)], 1, lhs, GRB.GREATER_EQUAL,1.0, r.toString() );
getGrbModel().addGenConstrIndicator(roomUsed[indexOf(r)], 0, lhs, GRB.LESS_EQUAL,0.0, r.toString() );
getObjectives().addTerm(USED_ROOM_COST, roomUsed[indexOf(r)]);
}
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
Post is closed for comments.
Comments
1 comment