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

943 views
Skip to first unread message

penpichaya thamthada

unread,
Aug 29, 2017, 12:14:07 PM8/29/17
to Gurobi Optimization
I use Gurobi optimizer in Python. However, I run it and it said AttributeError: 'int' object has no attribute 'addVar'. The following is how I obtain Vi, K which are used to create the variable x.

###############################################################
################ Set of available vehicles ####################
###############################################################
n_vehicle = sheet.cell_value(13, 23)
n_vehicle = int(round(n_vehicle))
K = []
for i in range(1,n_vehicle+1):
K.append(i)

###############################################################
###################### New EDGE ###############################
###############################################################
edge = {}
temp_for_all_j = []
for i in range(1,count_temp+1):
edge[i] = {}
for j in range(1,count_temp+1):
edge[i][j] = []
temp_for_all_j.append(i)

for i in range(1,len(temp_for_all_j)+1):
for j in range(1,len(temp_for_all_j)+1):
for k in range(len(V_i)):
for l in range(len(V_i[k])):
if i == V_i[k][l]:
fromI = k
if j == V_i[k][l]:
toI = k
if fromI == toI:
if i == j:
edge[i][j].append({"From Imaging Center":fromI, "To Imaging Center":toI, "From Patient":i, "To Patient":j, "distance":0, "time":0, "cost":2000})
else:
edge[i][j].append({"From Imaging Center":fromI, "To Imaging Center":toI, "From Patient":i, "To Patient":j, "distance":0, "time":0, "cost":0})
else:
for m in range(13,41):
if fromI == int(round((sheet.cell_value(m, 4)))) and toI == int(round((sheet.cell_value(m, 5)))):
distance = int(round((sheet.cell_value(m, 6))))
time = int(round((sheet.cell_value(m, 10))))
cost = (distance*m_v)+(time*m_t)
edge[i][j].append({"From Imaging Center":fromI, "To Imaging Center":toI, "From Patient":i, "To Patient":j, "distance":distance, "time":time, "cost":cost})
else:
if fromI == int(round((sheet.cell_value(m, 5)))) and toI == int(round((sheet.cell_value(m, 4)))):
distance = int(round((sheet.cell_value(m, 6))))
time = int(round((sheet.cell_value(m, 10))))
cost = (distance*m_v)+(time*m_t)
edge[i][j].append({"From Imaging Center":fromI, "To Imaging Center":toI, "From Patient":i, "To Patient":j, "distance":distance, "time":time, "cost":cost})

json_data = json.dumps(edge) 

#with open("Output.txt", "w") as text_file:
#    print(json_data, file=text_file)

#print("complete")
Vi = temp_for_all_j
1.jpg

Renan Garcia

unread,
Aug 29, 2017, 12:19:17 PM8/29/17
to gur...@googlegroups.com
Note you are using the 'm' variable in 2 different contexts. 'for m in range(13,41)' assigns it an integer value, and then you are trying to work with it as a model with 'm.addVar()'.

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<1.jpg>

penpichaya thamthada

unread,
Aug 30, 2017, 11:29:59 AM8/30/17
to Gurobi Optimization
Ohh I see. Thank you
Reply all
Reply to author
Forward
0 new messages