Search code examples
optimizationlinear-programminggurobi

Gurobi optimization problem (not sure if my approach is correct)


This is the question

enter image description here

This is the optimization model i wrote out: enter image description here

m = gp.Model(env=env)
x1 = m.addVar(name='x1', lb=0, ub=5000)
x2 = m.addVar(name='x2', lb=0, ub=5000)
y1 = m.addVar(name='y1', lb=0)
y2 = m.addVar(name='y2', lb=0)
y3 = m.addVar(name='y3', lb=0)

m.setObjective(70*y1 + 60*y2 + 50*y3 - 45*x1 - 35*x2, sense=gp.GRB.MAXIMIZE)
m.addConstr(x1 <= 5000)
m.addConstr(x2 <= 5000)
m.addConstr(x1 + x2 <= 9000)
m.addConstr(12*x1 + 6*x2 >= 10*y1)
m.addConstr(12*x1 + 6*x2 >= 8*y2)
m.addConstr(12*x1 + 6*x2 >= 6*y3)
m.addConstr(0.5*x1 + 2*x2 <= y1)
m.addConstr(0.5*x1 + 2*x2 <= 2*y2)
m.addConstr(0.5*x1 + 2*x2 <= y3)
m.addConstr( x1 >= 0)
m.addConstr( x2 >= 0)
m.addConstr( y1 >= 0)
m.addConstr( y2 >= 0)
m.addConstr( y3 >= 0)
m.optimize()
print('Optimal objective value:', m.objVal)
print('x1:', x1.x)
print('x2:', x2.x)
print('y1:', y1.x)
print('y2:', y2.x)
print('y3:', y3.x)

Can someone check if my approach is correct because im quite confused when it comes to the octane rating and iron content portion


Solution

  • Yes correct. you can remove the bound constraints as variable declarations are covering that. You can also scale down the Octane rating constraints (divide both sides of first 2 octane rating constraints by 2 & the third one by 6)