Unable to retrieve attribute 'objVal'
回答済みimport gurobipy as gp
from gurobipy import GRB
import math
import numpy as np
from matplotlib import pyplot as plt
options = {
"WLSACCESSID": "xxx",
"WLSSECRET": "xxx",
"LICENSEID": xxx,
}
import pandas as pd
import numpy as np
import random
R = np.array([])
for o in range(3,10):
T = np.zeros((o,3))
n = np.zeros(3)
n = np.array([10,15,20])
Totalmaterials = 15
beta_0 = 1
beta_1 = 1
beta_2 = 1
def Traveltime():
random_integer = random.randint(2,4)
return(random_integer)
for i in range(0,o):
for j in range(0,3):
T[i][j]= Traveltime()
def Optimize(n,T,o):
env = gp.Env(params=options)
model = gp.Model(env=env)
z = model.addVars(3, lb = 0, vtype = GRB.CONTINUOUS, name = 'z')
Vi = model.addVars(o, lb = 0, vtype = GRB.CONTINUOUS, name = 'Vi')
qij = model.addMVar((o,3), lb = 0, vtype = GRB.CONTINUOUS, name = 'qij')
Pij = model.addMVar((o,3), vtype = GRB.CONTINUOUS, name = 'Pij')
Qij = model.addMVar((o,3), vtype = GRB.CONTINUOUS, name = 'Qij')
W = model.addMVar((o,3), vtype = GRB.CONTINUOUS, name = 'W')
model.addConstrs(Qij[i,j] == beta_0 - beta_1*T[i,j] + beta_2*Vi[i] for i in range(0,o) for j in range(0,3))
for i in range(0,o):
for j in range(0,3):
model.addGenConstrExp(Qij[i,j], W[i,j], "FuncPieces=-2 FuncPieceError=0.01")
model.addConstrs(Pij[i,j]*sum(W[l,j] for l in range(0,o)) == W[i,j] for i in range(0,o) for j in range(0,3))
model.addConstr(sum(Vi[i] for i in range(0,o)) <= Totalmaterials)
model.addConstrs(Vi[i] == sum(qij[i,j] for j in range(0,3)) for i in range(0,o))
model.addConstrs(qij[i,j] <= n[j]*Pij[i,j] for i in range(0,o) for j in range(0,3))
model.addConstrs(sum(Pij[i,j] for i in range(0,o)) == 1 for j in range(0,3))
model.addConstrs(z[j] == n[j]- sum(qij[i,j] for i in range(0,o)) for j in range(0,3))
obj_fn = gp.quicksum(z[j] for j in range(0,3))
model.setObjective(obj_fn, GRB.MINIMIZE)
model.optimize()
print('Optimization is done. Objective Function Value: %.2f' %model.objVal)
for v in model.getVars():
print('%s: %g' %(v.varName, v.x))
return model.objVal
R = np.append(R,Optimize(n,T,o))
The question is while running the above code for o = 6 it is not able to retrieve attribute 'objVal' and the model is infeasible. But when i solved the problem with another algorithm, I am getting feasible solution for o = 6.
0
-
正式なコメント
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Did you check the article How do I diagnose a wrong result?
A common issue is that the default lower bound in Gurobi is 0.0 and not -INF as in other solvers.0 -
Thanks Marika Karbstein. It was really helpful insight about the model.
Best,
Dhiraj
0
投稿コメントは受け付けていません。
コメント
3件のコメント