APPENDING TO A MULTIDICT

555 views
Skip to first unread message

aal...@g.rit.edu

unread,
Mar 11, 2014, 1:57:11 PM3/11/14
to gur...@googlegroups.com
def solve_it(input_date):
# parse the input
lines = input_data.split('\n')
firstLine = lines[0].split()
item_count = int(firstLine[0])
capacity = int(firstLine[1])

items = []
v = []
w = []

for i in range(1, item_count+1):
line = lines[i]
parts = line.split()
v.append(int(parts[0]))
w.append(int(parts[0]))

for i in range(0,item_count):
items,value,weight = multidict({
i: [v[i],w[i]]})


Now in the last for loop how to i append values or add values to it. I am taking values in from a data file and thus cannot just copy paste the data in the dict need some way to append it. Please help or suggest a alternate way to do so.

Christopher Maes

unread,
Mar 11, 2014, 5:09:37 PM3/11/14
to gur...@googlegroups.com
multidict is a function that takes a single dict and splits it into
multiple dicts. multidict is not a data structure that you append
values to. For more info see the reference manual on multidict:
http://www.gurobi.com/documentation/5.6/reference-manual/py_multidict

You also might find the python documentation on dicts useful:
http://docs.python.org/2/tutorial/datastructures.html#dictionaries

It's a little difficult to tell from your code, but I'm guessing you
want to construct the value and weight dicts as follows:
value = {}
weight = {}
for i in range(1, item_count+1)
line = lines[i]
parts = line.split()
value[i] = int(parts[0])
weight[i] = int(parts[1])


Keep in mind that this forum is for Gurobi. So questions on Python
dicts or Python programming (that are separate from Gurobi) are
probably best asked at another forum like StackOverflow.

I hope that helps,
Chris
Reply all
Reply to author
Forward
0 new messages