Adwaitvedant Mathkar
unread,May 12, 2012, 10:41:30 PM5/12/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gur...@googlegroups.com
Hey,
I'm running the following program:
from gurobipy import *
from string import *
def optimize_linear_function(gradient,dimension,upper_bound):
m=Model("MNL_func_optimization")
weighted_sum = {}
s={}
for index in range(dimension):
weighted_sum[index] = m.addVar(obj = gradient[index])
s[index] = m.addVar(ub=upper_bound,lb=0,name = str(index)) #I HAVE DECLARED VARIABLE s HERE
m.modelSense = GRB.MAXIMIZE
m.update()
for index in range(dimension):
m.addConstr( weighted_sum[index] <= s[index])
m.addConstr( weighted_sum[index] <= -s[index])
m.addConstr(quicksum(s) <= upper_bound) #THIS IS WHERE I GET THE ERROR
m.optimize()
for index in range(dimension):
print weighted_sum[index].x
-----------------------------------------------------------------
On running the program I get:
TypeError: 'NoneType' object is not subscriptable
Probably saying that dictionary s is non-type. However I have clearly added s to variable list
s[index] = m.addVar(ub=upper_bound,lb=0,name = str(index))
Question being, why am I still getting such an error?
Any help would be greatly appreciated!
Thanks!
Best,
Adwait
--
Adwaitvedant Mathkar
Junior Undergraduate
Department of Electrical Engineering
IIT Bombay