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