Tupledict with lists for values
AnsweredHello!
I am trying to create a tupledict() where :
("Type A" , "Time period 1") , ("Type B" , "Time period 1") etc are the keys and the corresponding values are in the form of lists. Let us consider an example of 5 elements with values (5,10,15,20,21) and (3,6,9,12,15) respectively.
When I am referring to this tupledict in a constraint, how do I access each of the values in the list/ refer to them separately as an index? For example, I want to refer to the following:
("Type A", "Time period 1", "Element 1") : 5
("Type A", "Time period 1", "Element 2") : 10
("Type A", "Time period 1", "Element 3") : 5
etc.
Normally, I would type this out but I am dealing with a list which is significantly larger than 5 elements. How can I proceed with this?
Thank you in advance!
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Pavithra,
Let values be the list of the elements, (5, 10, 15, 20, 21) in your example. You can just write:
d = tupledict([(("Type A", "Time period 1", index), value) for
index, value in enumerate(values)])Then \(\texttt{d}\) will be:
{
('Type A', 'Time period 1', 0): 5, ('Type A', 'Time period 1', 1): 10,
('Type A', 'Time period 1', 2): 15, ('Type A', 'Time period 1', 3): 20,
('Type A', 'Time period 1', 4): 21
}
Best regards,Maliheh
0
Post is closed for comments.
Comments
2 comments