Modèle solved with a 0 Objective function
OngoingHello,
i have a problem and i would like some help,
The résolution of mu model comes with a 0 objectife function like you can see,
So i dont know how is it possible, and what does it mean
Thanks a lot
-
Hi Rayan,
Thank you for reaching us.
I'm happy to support you again :DCould you give us more information about why you consider the solution wrong?
Do you already know a feasible solution whose objective function value is greater than zero?Also, it is better for us to have a snippet of your code to reproduce the same problem and support you better.
Best regards,
Chung-Kyun Han0 -
Hello, the solution is wrong because thé constraint are not verified,
And of course i can send you My code just give me where
Also, the modele was ruuning correctly but When i added more constraint the modele gave me 0 for the objective function.
I think may be is a memory problème0 -
Hi Rayan,
We would like to suggest two approaches to validate your model.
If you already know a solution having better objective value, fix variables based on the solution and validate the feasibility.
For example, let's assume that a known solution is a=1, b=0 and then add the following constraints.import gurobipy as gp
m = gp.Model()
'''
here, your variables
assuming a, b variables are also in yours
'''
'''
here, your constraints
'''
# constraints for fixing variables based on a known solution
m.addConstr(a == 1)
m.addConstr(b == 0)When you try to solve the model with fixed variables, Gurobi can give you a log message that the model is infeasible. In that case, you can run m.computeIIS() and analyze your model.
The second one is to utilize the objective function value of a know solution.
Let's assume that your problem is a maximization problem, and the objective value of a feasible solution is 1. In the model, you substitute the whole objective function to decision variable z and add a constraint for setting the lower bound of the objective.import gurobipy as gp
m = gp.Model()
'''
your model
'''
z = m.addVar()
m.addConstr(z == f) # assume that f is the objective function
m.addConstr(z >= 1)It might be possible that the model can be infeasible. Like above, you can use m.computeIIS() here again.
Lastly, there is another suggestion for you.
Now, you are testing a big problem. Therefore, it is not that easy to figure out the root cause.
It would be better to try a small-size instance first.If there are unclear things, please feel free to leave a message again!!
Best regards,
Chung-Kyun Han0 -
Hello Chung-Kyun,
Thank you for your response,
I'll try to clarify my problem,
My model is an allocation model for the quantity of products in différent locations ( storage location), so from one period t to another the quantity of a product in a location may decrease or increase depending on the inflow and outflow of products.
One of my variable is X[i,c,j,t] ( Quantity of ptoduct(i,c) in location j at period t).
When I run my model and initialize all locations at period t=0 to 0 with this constraintfor i in range(I):
for c in range(C):
for j in range(J):
for t in range(T):
if t==0:
model.addConstr(X[i,c,j,t]==0)My modèle give me a fesiable and optimal solution.
But when i initialize location with real values like for example:model.addConstr(X[26, 0, 0, 0] == 6)
for i in range(I):
model.addConstr(X[i, 0, 1, 0] == 0)
for i in range(I):
model.addConstr(X[i, 0, 2, 0] == 0)
model.addConstr(X[6, 0, 3, 0] == 3)
I have the previous solution ( 0 for the objective function) and solutions that don't respect the constraints.So i think that the probleme is a memory probleme, it takes lot of memory to initialise all my 211 location with 49 Products.
Thanks a lot
0 -
Hi Rayan,
Thank you for sharing your problem and model file.
If you don't mind, please share the model file through other cloud storage services such as Filemail, Dropbox, Box, Google Drive, OneDrive, etc (please refer to our guidance regarding the Community Forum).
The purpose is to share your model with others.
Here is a public forum. I'm not the only one who will help you.
When you share the model file, don't include your credentials regarding your license like you did through the Google Colaboratory link you shared with me.Anyway, I don't think that the problem is related to memory because you got a final solution (though it is not the one you hoped for), and Gurobi didn't report any issue with memory.
The following is my suggestion mentioned earlier.
result_1 = gp.quicksum(R[i,0,e,j,t] for i in range(I) for j in range(J) for t in range(T) for e in range(E))*20+gp.quicksum(R[i,1,e,j,t] for i in range(I) for j in range(J) for t in range(T) for e in range(E) )*21
result_2 = gp.quicksum(V[i,0,e,k,t] for i in range(I) for k in range(K) for t in range(T) for e in range(E))*30+gp.quicksum(V[i,1,e,k,t] for i in range(I) for k in range(K) for t in range(T) for e in range(E))*31
result_3 = gp.quicksum(Z[i,0,e,k,t] for i in range(I) for k in range(K) for t in range(T) for e in range(E))*300+gp.quicksum(Z[i,1,e,k,t] for i in range(I) for k in range(K) for t in range(T) for e in range(E))*301
result_4 = gp.quicksum(Q[i,c,j,k,t] for i in range(I) for k in range(K) for j in range(J) for t in range (T)for c in range(C))*20
result_5 = gp.quicksum(L[i,c,b,j,t] for i in range(I) for b in range(J) for j in range(J) for t in range (T)for c in range(C))*10
result_6 = gp.quicksum(F[i,c,t] for i in range(I) for t in range(T)for c in range(C))*1000
result_7 = gp.quicksum(A[i,e,t] for i in range(I) for e in range(E) for t in range(T))*1000
objF = model.addVar(name='objF')
model.addConstr(result_1 + result_2 + result_3 + result_4 + result_5 + result_6 + result_7 == objF)
model.addConstr(objF >= 1) # arbitrary number, greater than zero
objective=model.setObjective(objF, gp.GRB.MINIMIZE)Suppose your know solution is correct. In that case, by imposing the objective function value greater than zero, the model becomes infeasible, and then you can run model.computeIIS() and figure out conflicting constraints.
And for the analysis, it would be better to reduce the size of the problem.
Best regards,
Chung-Kyun Han0 -
Good Morning Chung-Kyun,
I think i found where my probleme is :
I defined thode constraint for my variable S[i,c,j,t]
thes sets are:
I=49
J=211
T=3
K=27
E=7
C=3
J1=range(151,211)
J21=range(48,49)
J22=range(55,56)
J23=range(62,63)
J24=range(65,69)
J25=range(73,74)
J26=range(76,103)
J2=chain(J21,J22,J23,J24,J25,J26)
J3=range(103,151)
J41=range(28,29)
J42=range(35,36)
J43=range(42,48)
J44=range(49,55)
J45=range(56,62)
J46=range(63,65)
J47=range(69,73)
J48=range(74,76)
J4=chain(J41,J42,J43,J44,J45,J46,J47,J48)
J61=range(0,2)
J62=range(25,27)
J63=range(38,39)
J6=chain(J61, J62, J63)
J8=range(39,42)
J9=range(2,14)
JA=range(23,25)
JB1=range(14,23)
JB2=range(27,28)
JB3=range(29,35)
JB4=range(36,38)
JB=chain(JB1,JB2,JB3,JB4)after that i defined the constraint like this:for i in range(I):
for c in range(C):
for t in range(T):
for j in J1:
model.addConstr(S[i,c,j,t]<=1)
for i in range(I):
for c in range(C):
for t in range(T):
for j in J2:
model.addConstr(S[i, c, j, t] <= 2)
..... Same thing for J4 J6....JBthe probleme is that my solution doesn't respect thoses constraint, so i wonder where i did a mistake definining those constraint ?Thnaks a lot0 -
I also tried you recommondation and it give me an objectif function that equals 1, i really dont understand
0
Please sign in to leave a comment.
Comments
7 comments