4

I have to adopt an existing script where they used the PuLP package. I need to know how the result of the following line looks like:

unit = ["one", "two", "three"]
time = range(10)

status=LpVariable.dicts("status",[(f,g) for f in unit for g in time],0,1,LpBinary)

How does the keys/values looks like?

status["one"] = [0,1,1,1...]?

Thank you very much for your help!

Matias
  • 581
  • 1
  • 5
  • 16
  • Here is the documentation for [`LpVariable.dicts`](http://www.coin-or.org/PuLP/pulp.html#pulp.LpVariable.dicts). Which part of that code are you specifically confused about, the list comprehension? – Cory Kramer Sep 07 '16 at 12:55
  • Hey! thank you for your reply. I looked at the documentation - but unfortunatelly I am not sure how "status" would look like (there is also no example of results in the documentation) – Matias Sep 07 '16 at 12:59
  • you mean status, not "status", because the later just is a string, right? – Dschoni Sep 07 '16 at 13:03
  • can you just run the code and introspect? – Dschoni Sep 07 '16 at 13:04

1 Answers1

2
from pulp import *
unit = ["one", "two"]
time = range(2)

status=LpVariable.dicts("status",[(f,g) for f in unit for g in time],0,1,LpBinary)

Leads to

>>> status

{('two', 1): status_('two',_1), 
('two', 2): status_('two',_2), 
('one', 2): status_('one',_2), 
('one', 0): status_('one',_0), 
('one', 1): status_('one',_1), 
('two', 0): status_('two',_0)}

So, there is no entry with the key "one".

Dschoni
  • 3,714
  • 6
  • 45
  • 80
  • thank you very much for your reply! One additional question: What does that "0,1,LpBinary" mean? That the values have to be binaries? – Matias Sep 07 '16 at 13:29
  • as mentioned above dicts(name, indexs, lowBound=None, upBound=None, cat=0, indexStart=[]). with cat – The category this variable is in, Integer, Binary or Continuous(default). – Dschoni Sep 07 '16 at 13:31
  • status_unit= [status["one",i].value() for i in time] give me [None,None] --> does that mean that the value (for instance "status_("two",_1) could be 0 or 1? – Matias Sep 07 '16 at 13:42
  • to get a value from a dictionary you have to query for the key. In this case it would be `status[("one",1)]` to yield `status_('one',_1)` – Dschoni Sep 07 '16 at 13:55
  • I suggest you start looking into python documentation of dictionaries before trying to understand PuLP. – Dschoni Sep 07 '16 at 14:00