AttributeError:“元组”对象没有属性“ addVar”

时间:2019-04-23 15:43:38

标签: python gurobi

我被卡在这个错误上:

AttributeError: 'tuple' object has no attribute 'addVar'

这是我的代码的一部分

from gurobipy import*
m = ()
#model data
import xlrd
file_location = "C:/Users/Mohamed/Desktop/Service.xlsx"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_name("servicetime")
data = [[sheet.cell_value(r, c) for c in range(sheet.ncols)] for r in range(sheet.nrows)]
Trucks=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]
Slots=[1,2,3,4,5,6,7,8,9,10]
Areas=[1,2,3,4,5]
U=[1,2]
R=[1]
tin=[0.1667,0.3333,0.1667,0.3333,0.25]
tout=[0.1667,0.3333,0.1667,0.3333,0.25]
T=[0.75]
x,g,tin,tout,ta1a2,t,U,P,V,R={},{},{},{},{},{},{},{},{},{}
#define variables
for n in Trucks:
    g[n]=m.addVar(vtype=GRB.INTEGER,name="g[%s]"%(n))

1 个答案:

答案 0 :(得分:1)

您需要一个Gurobi模型对象:m = Model()。另外,如果您使用Model.addVars(),则更容易,例如:

g = m.addVars(Trucks, vtype=GRB.INTEGER, name="g")
相关问题