Skip to content

Commit

Permalink
Adjust data structure used by Model.initialize_items
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Feb 11, 2020
1 parent 3a3155f commit b8f0151
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
12 changes: 6 additions & 6 deletions ixmp/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def initialize_items(cls, scenario, items):
----------
scenario : .Scenario
Scenario object to initialize.
items : list of dict
Each entry is one ixmp item (set, parameter, equation, or variable)
to initialize. Each dict **must** have the key 'ix_type'; one of
'set', 'par', 'equ', or 'var'; any other entries are keyword
items : dict of (str -> dict)
Each key is the name of an ixmp item (set, parameter, equation, or
variable) to initialize. Each dict **must** have the key 'ix_type';
one of 'set', 'par', 'equ', or 'var'; any other entries are keyword
arguments to the methods :meth:`.init_set` etc.
See also
Expand All @@ -79,7 +79,7 @@ def initialize_items(cls, scenario, items):
# attempt raises an exception
pass

for item_info in items:
for name, item_info in items.items():
# Copy so that pop() below does not modify *items*
item_info = item_info.copy()

Expand All @@ -89,7 +89,7 @@ def initialize_items(cls, scenario, items):

try:
# Add the item
init_method(**item_info)
init_method(name=name, **item_info)
except ValueError:
# Item already exists
pass
Expand Down
26 changes: 13 additions & 13 deletions ixmp/model/dantzig.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
from .gams import GAMSModel


ITEMS = (
ITEMS = {
# Plants
dict(ix_type='set', name='i'),
'i': dict(ix_type='set'),
# Markets
dict(ix_type='set', name='j'),
'j': dict(ix_type='set'),
# Capacity of plant i in cases
dict(ix_type='par', name='a', idx_sets=['i']),
'a': dict(ix_type='par', idx_sets=['i']),
# Demand at market j in cases
dict(ix_type='par', name='b', idx_sets=['j']),
'b': dict(ix_type='par', idx_sets=['j']),
# Distance between plant i and market j
dict(ix_type='par', name='d', idx_sets=['i', 'j']),
'd': dict(ix_type='par', idx_sets=['i', 'j']),
# Transport cost per case per 1000 miles
dict(ix_type='par', name='f', idx_sets=None),
'f': dict(ix_type='par', idx_sets=None),
# Decision variables and equations
dict(ix_type='var', name='x', idx_sets=['i', 'j']),
dict(ix_type='var', name='z', idx_sets=None),
dict(ix_type='equ', name='cost', idx_sets=None),
dict(ix_type='equ', name='demand', idx_sets=['j']),
dict(ix_type='equ', name='supply', idx_sets=['i']),
)
'x': dict(ix_type='var', idx_sets=['i', 'j']),
'z': dict(ix_type='var', idx_sets=None),
'cost': dict(ix_type='equ', idx_sets=None),
'demand': dict(ix_type='equ', idx_sets=['j']),
'supply': dict(ix_type='equ', idx_sets=['i']),
}

DATA = {
'i': ['seattle', 'san-diego'],
Expand Down
1 change: 0 additions & 1 deletion ixmp/model/gams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


from ixmp.backend import ItemType
from ixmp.backend.jdbc import JDBCBackend
from ixmp.model.base import Model
from ixmp.utils import as_str_list

Expand Down

0 comments on commit b8f0151

Please sign in to comment.