Objective function result
AnsweredHi!
I am currently working on optimizing the average coverage of different locations.
The sets are:
Ict = [ "1","5","4"] #, "77003", "77063"] # Candidate locations
It = [ "9","6","8" ] #"77005","77004","77010"] # Existing locations
Ic = [ "2","3","7"] #"77020", "77502" , "77503"] #In-clinic locations
Ictt = ["1","5","4", "9","6","8"] # candidate and existing
I = ["1","5","4", "9","6","8","2","3","7"] #all locations
J = ["4","11","7"] #demand locations
K = ["African", "Hispanic", "Asian", "White"] #population
Constant parameters:
l = 10 # number of patients for each available location
b = 6 # new locations that are going to be chosen
n = 20 # Number of patients
model = Model("Base Model")
Variables:
x = model.addVars(I, vtype=GRB.BINARY, name = "x") # locations
#E = model.addVars(I, I, vtype=GRB.BINARY, name = "E") #auxiliary variable
Contraints:
a = model.addConstr((sum(x[i] for i in Ict) <= b), name="a")
for i in Ictt:
model.addConstr(quicksum(n * (1 - q[i,j,k])
for j in J for k in K) >= l * x[i])
Ict_1 = ["2"]
for i in Ict_1:
model.addConstr(x["1"]+ x[i] <= 1)
for i in It:
model.addConstr(x[i] == 1 , name = "d")
for i in Ic:
model.addConstr(x[i] == 1 , name = "e")
As of know for simplicity, I am setting the obj function to zero:
obj = 0
model.setObjective( obj, GRB.MAXIMIZE)
model.optimize()
If I only evaluate variable x, then the answer is:
x[1] 0 x[5] 1 x[4] 1 x[9] 1 x[6] 1 x[8] 1 x[2] 1 x[3] 1 x[7] 1 Obj: -0
which makes sense x[1] is being limited by constraint 3 so it should be giving 0.
Nevertheless, as soon as I add the auxiliary variable E, the answer changes to:
x[1] 0 x[5] 0 x[4] 0 x[9] 1 x[6] 1 x[8] 1 x[2] 1 x[3] 1 x[7] 1 E[1,1] 1 E[1,5] 1 E[1,4] 1 E[1,9] 1 E[1,6] 1 E[1,8] 1 E[1,2] 1 E[1,3] 1 E[1,7] 1 E[5,1] 1 ...
E[7,5] 1 E[7,4] 1 E[7,9] 1 E[7,6] 1 E[7,8] 1 E[7,2] 1 E[7,3] 1 E[7,7] 1 Obj: -0
My question is why as soon as I included E, the candidate locations x[5] and x[4] changed to zero even when the constraints remained the same? What is this variable doing that is limiting the candidate locations?
-
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?. -
Hi Sab,
The additional variables don't limit the candidate locations. Because your objective is \( 0 \), Gurobi just looks for a feasible solution. There is no incentive in the objective function to utilize additional candidate locations.
If you solve the exact same model using the exact same parameters, Gurobi should return the same result. Although the \( \texttt{E} \) variables don't show up in any constraints, adding them results in a different model. Thus, Gurobi will not necessarily return the exact same solution as it did when you solved the problem without these variables. You can read more about this in the article Is Gurobi Optimizer deterministic?.
Thanks,
Eli
0
Post is closed for comments.
Comments
2 comments