I am trying to use type 1 SOS constraints via the Python API, but it seems like Gurobi ignores my constraints.
If I use quicksum constraints, the solver works as expected:
# Constraint: Each customer is served exactly once
# customers is a list of customers
# facilities is a list of facilities (that may or may not be opened)
# y_wc is a list of binary Gurobi variables representing whether facility w serves customer c,
# for example, y_wc[0] represents whether facility 0 serves customer 0, etc.
for c in range(len(customers)):
m.addConstr(quicksum([y_wc[w * len(customers) + c] for w in range(len(facilities))]) == 1)
However, if I try to replace the code above by SOS constraints as follows, the solver seems to ignore these - it immediately gives an "optimal" solution where no single facility is opened and no customer is served.
# SOS constraint
for c in range(len(customers)):
m.addSOS(GRB.SOS_TYPE1, [y_wc[w * len(customers) + c] for w in range(len(facilities))])
If I write the model to a mps file, the SOS constraints do seem to be in place (3 facilities, 4 customers):
# serves(w,c) is the name of the y_wc variables
SOS
S1 s0
serves(0,0) 1
serves(1,0) 2
serves(2,0) 3
S1 s1
serves(0,1) 1
serves(1,1) 2
serves(2,1) 3
S1 s2
serves(0,2) 1
serves(1,2) 2
serves(2,2) 3
S1 s3
serves(0,3) 1
serves(1,3) 2
serves(2,3) 3
I'm sure that I'm missing something here - any help appreciated!
I am using:
gurobi6.0.3_mac64
grurobipy.sys.api_version returns 1013
OS X version 10.10.3 (14D131)