Cannot find the optimal solution for linear programming problem
AnsweredHello
I want to solve the following linear programming problem:

Here is my code:
from gurobipy import *
# define the model
M_LP = Model("LP_Exam")
N = 5
F_e = 160 * 10 **7
t = 1
H_t = [0, 46410792960, 146112512, 26905404824, 0]
# define the optimization variable
f = []
for i in range(N):
name = 'f_' + str(i)
x = M_LP.addVar(10, 100, vtype=GRB.CONTINUOUS, name=name)
f.append(x)
# define the objective function
obj = LinExpr(0)
for i in range(N):
a = H_t[i] * F_e * t
obj.addTerms(a, f[i])
M_LP.setObjective(obj, GRB.MAXIMIZE)
# define the constraints
constr = LinExpr(0)
for i in range(N):
constr.addTerms(1, f[i])
M_LP.addConstr(constr == 100, name="c1")
M_LP.setParam('OutPutFlag', 0)
M_LP.optimize()
for i in range(len(f)):
print(f[i].X)
print("Obj: ", M_LP.objVal)
The above code can be run and the obtained optimal solution is:

However, using another set of solution(x1=10, x2=50, x3=1, x4=29, x5=10), the calculated objective function value will be larger(obj=4.9612742206336e+21). Hence, I want to know how to solve this problem. Thanks a lot!
-
This model has extremely large objective values:
Maximize
7.4257268736e+19 f_1 + 2.337800192e+17 f_2 + 4.30486477184e+19 f_3
Subject To
c1: f_0 + f_1 + f_2 + f_3 + f_4 = 100
Bounds
10 <= f_0 <= 100
10 <= f_1 <= 100
10 <= f_2 <= 100
10 <= f_3 <= 100
10 <= f_4 <= 100
EndIn any case, you should scale those objective coefficients to avoid numerical issues in more complex models. For example, you can just scale the objective function by 1e-17.
Having said that, the answer that Gurobi provides is still optimal. With the given bounds on the variables, you cannot go any higher than 60 for f_1 because the other variables need to be at least 10. Your other proposed solution is infeasible because of f_3=1.
Cheers,
Matthias0 -
Dear Matthias,
I'm sorry that I overlooked the other solution is infeasible. Thanks for your help!
0
Please sign in to leave a comment.
Comments
2 comments