Understanding Python / PuLP Code Snippets

I need to accept an existing script where they used the PuLP package. I need to know what 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)

What do the keys / values ​​look like?

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

Many thanks for your help!

+4
source share
1 answer
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 record with the key "one".

+2
source

Source: https://habr.com/ru/post/1653909/


All Articles