Skip to content

Commit

Permalink
refactoring to joint "generic" and "commodity" share constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
gidden committed Aug 10, 2018
1 parent 6b69873 commit 48d3edd
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 127 deletions.
28 changes: 19 additions & 9 deletions message_ix/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,34 @@ def _init_scenario(s, commit=False):
'exec': [
(s.init_set, {'args': ('shares',)}),
(s.init_set, {
'args': ('map_shares_commodity_level',),
'args': ('map_shares_commodity_share',),
'kwargs': dict(
idx_sets=['shares', 'commodity', 'level', 'type_tec',
'type_tec'],
idx_names=['shares', 'commodity', 'level',
'type_tec_share', 'type_tec_total'])
# idx_sets=['shares', 'node', 'node', 'type_tec', 'mode',
# 'commodity', 'level', 'year', 'time'],
idx_sets=['shares', 'node', 'node', 'type_tec',
'mode', 'commodity', 'level'],
idx_names=['shares', 'node_share', 'node', 'type_tec',
'mode', 'commodity', 'level'])
}),
(s.init_set, {
'args': ('map_shares_commodity_total',),
'kwargs': dict(
idx_sets=['shares', 'node', 'node', 'type_tec',
'mode', 'commodity', 'level'],
idx_names=['shares', 'node_share', 'node', 'type_tec',
'mode', 'commodity', 'level'])
}),
(s.init_par, {
'args': ('share_factor_up',),
'args': ('share_commodity_up',),
'kwargs': dict(
idx_sets=['shares', 'node', 'year', 'time'],
idx_names=['shares', 'node_loc', 'year_act', 'time'])
idx_names=['shares', 'node_share', 'year_act', 'time'])
}),
(s.init_par, {
'args': ('share_factor_lo',),
'args': ('share_commodity_lo',),
'kwargs': dict(
idx_sets=['shares', 'node', 'year', 'time'],
idx_names=['shares', 'node_loc', 'year_act', 'time'])
idx_names=['shares', 'node_share', 'year_act', 'time'])
}),
(s.init_par, {
'args': ('share_mode_up',),
Expand Down
3 changes: 2 additions & 1 deletion message_ix/model/MESSAGE/data_load.gms
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ abs_cost_new_capacity_soft_up, abs_cost_new_capacity_soft_lo, level_cost_new_cap
abs_cost_activity_soft_up, abs_cost_activity_soft_lo, level_cost_activity_soft_up, level_cost_activity_soft_lo,
soft_new_capacity_up, soft_new_capacity_lo, soft_activity_up, soft_activity_lo,
* share constraints
share_factor_up,share_factor_lo,map_shares_commodity_level,share_mode_up,share_mode_lo,
map_shares_commodity_share,map_shares_commodity_total,share_commodity_up,share_commodity_lo
share_mode_up,share_mode_lo,
* addon technologies
addon_conversion, addon_up, addon_lo
* parameters for reliability, flexibility and renewable potential constraints
Expand Down
90 changes: 33 additions & 57 deletions message_ix/model/MESSAGE/model_core.gms
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ Equations
ACTIVITY_BOUND_LO lower bound on activity summed over all vintages
ACTIVITY_BOUND_ALL_MODES_UP upper bound on activity summed over all vintages and modes
ACTIVITY_BOUND_ALL_MODES_LO lower bound on activity summed over all vintages and modes
SHARES_COMMODITY_LEVEL_UP upper bounds on share constraints for commodities and levels
SHARES_COMMODITY_LEVEL_LO lower bounds on share constraints for commodities and levels
SHARES_MODE_UP upper bounds on share constraints for modes of a given technology
SHARES_MODE_LO lower bounds on share constraints for modes of a given technology
ACTIVITY_CONSTRAINT_UP dynamic constraint on the market penetration of a technology activity (upper bound)
SHARE_CONSTRAINT_COMMODITY_UP upper bounds on share constraints for commodities
SHARE_CONSTRAINT_COMMODITY_LO lower bounds on share constraints for commodities
SHARE_CONSTRAINT_MODE_UP upper bounds on share constraints for modes of a given technology
SHARE_CONSTRAINT_MODE_LO lower bounds on share constraints for modes of a given technology
ACTIVITY_CONSTRAINT_UP dynamic constraint on the market penetration of a tgeneric_share_factor_upechnology activity (upper bound)
ACTIVITY_SOFT_CONSTRAINT_UP bound on relaxation of the dynamic constraint on market penetration (upper bound)
ACTIVITY_CONSTRAINT_LO dynamic constraint on the market penetration of a technology activity (lower bound)
ACTIVITY_SOFT_CONSTRAINT_LO bound on relaxation of the dynamic constraint on market penetration (lower bound)
Expand Down Expand Up @@ -1262,7 +1262,7 @@ ACTIVITY_BOUND_ALL_MODES_LO(node,tec,year,time)$( bound_activity_lo(node,tec,yea
* \sum_{m\prime} ACT_{n^L,t,y^V,y,m\prime,h^A}
*
***
SHARES_MODE_UP(shares,node,tec,mode,year,time)$(
SHARE_CONSTRAINT_MODE_UP(shares,node,tec,mode,year,time)$(
map_tec_act(node,tec,year,mode,time) AND
share_mode_up(shares,node,tec,mode,year,time)
)..
Expand Down Expand Up @@ -1294,7 +1294,7 @@ SHARES_MODE_UP(shares,node,tec,mode,year,time)$(
* \sum_{m\prime} ACT_{n^L,t,y^V,y,m\prime,h^A}
*
***
SHARES_MODE_LO(shares,node,tec,mode,year,time)$(
SHARE_CONSTRAINT_MODE_LO(shares,node,tec,mode,year,time)$(
map_tec_act(node,tec,year,mode,time) AND
share_mode_lo(shares,node,tec,mode,year,time)
)..
Expand All @@ -1313,42 +1313,30 @@ SHARES_MODE_LO(shares,node,tec,mode,year,time)$(
;

***
* Equation SHARES_COMMODITY_LEVEL_UP
* """"""""""""""""""""""""""""""""""
* This constraint provides upper bounds of the share of the amount of a
* commodity provided at a certain level. For example, it could limit the share
* of electricity generated by fossil fuel technologies on the secondary energy
* level.
*
* .. math::
* \sum_{\substack{n^L,t,m,h^A \\ y^V \leq y}} output_{n^L,t,y^V,y,m,n,c,l,h^A,h} + input_{n^L,t,y^V,y,m,n,c,l,h^A,h}
* \cdot duration\_time\_rel_{h,h^A} \cdot ACT_{n^L,t,y^V,y,m,h^A} \\
* \leq share\_factor\_up_{s,n,y,h} \cdot
* \sum_{\substack{n^L,t\prime,m,h^A \\ y^V \leq y}} output_{n^L,t\prime,y^V,y,m,n,c,l,h^A,h} + input_{n^L,t\prime,y^V,y,m,n,c,l,h^A,h}
* \cdot duration\_time\_rel_{h,h^A} \cdot ACT_{n^L,t\prime,y^V,y,m,h^A}
*
* TODO: add docs
***
SHARES_COMMODITY_LEVEL_UP(shares,node,commodity,level,year,time,type_tec_share,type_tec_total)$(
map_shares_commodity_level(shares,commodity,level,type_tec_share,type_tec_total) AND
share_factor_up(shares,node,year,time)
)..
SUM( (location,tec,vintage,mode,time2)$(
SHARE_CONSTRAINT_COMMODITY_UP(shares,node_share,year,time)$( share_commodity_up(shares,node_share,year,time) )..
* activity by type_tec_share technologies with map_shares_generic_share entries and a specific mode
SUM( (node,location,type_tec_share,tec,vintage,mode,commodity,level,time2)$(
( map_shares_commodity_share(shares,node_share,node,type_tec_share,mode,commodity,level) OR
map_shares_commodity_share(shares,node_share,node,type_tec_share,'all',commodity,level) ) AND
cat_tec(type_tec_share,tec) AND
map_tec_act(location,tec,year,mode,time2) AND
map_tec_lifetime(location,tec,vintage,year)
),
* commodity activity generated by type_tec_share technologies
(
output(location,tec,vintage,year,mode,node,commodity,level,time2,time) +
input(location,tec,vintage,year,mode,node,commodity,level,time2,time)
) *
duration_time_rel(time,time2) *
ACT(location,tec,vintage,year,mode,time2)
)
)
=L=
share_factor_up(shares,node,year,time) *
* commodity activity generated by type_tec_total technologies
SUM( (location,tec,vintage,mode,time2)$(
share_commodity_up(shares,node_share,year,time) * (
* total input and output by `type_tec_total` technologies mapped to respective commodity, level and node
SUM( (node,location,type_tec_total,tec,vintage,mode,commodity,level,time2)$(
( map_shares_commodity_total(shares,node_share,node,type_tec_total,mode,commodity,level) OR
map_shares_commodity_total(shares,node_share,node,type_tec_total,'all',commodity,level) ) AND
cat_tec(type_tec_total,tec) AND
map_tec_act(location,tec,year,mode,time2) AND
map_tec_lifetime(location,tec,vintage,year)
Expand All @@ -1359,46 +1347,34 @@ SHARES_COMMODITY_LEVEL_UP(shares,node,commodity,level,year,time,type_tec_share,t
) *
duration_time_rel(time,time2) *
ACT(location,tec,vintage,year,mode,time2)
)
) )
;

***
* Equation SHARES_COMMODITY_LEVEL_LO
* """"""""""""""""""""""""""""""""""
* This constraint provides lower bounds of the share of the amount of a
* commodity provided at a certain level. For example, it could require the share
* of electricity generated by renewables technologies on the secondary energy
* level.
*
* .. math::
* \sum_{\substack{n^L,t,m,h^A \\ y^V \leq y}} output_{n^L,t,y^V,y,m,n,c,l,h^A,h} + input_{n^L,t,y^V,y,m,n,c,l,h^A,h}
* \cdot duration\_time\_rel_{h,h^A} \cdot ACT_{n^L,t,y^V,y,m,h^A} \\
* \geq share\_factor\_up_{s,n,y,h} \cdot
* \sum_{\substack{n^L,t\prime,m,h^A \\ y^V \leq y}} output_{n^L,t\prime,y^V,y,m,n,c,l,h^A,h} + input_{n^L,t\prime,y^V,y,m,n,c,l,h^A,h}
* \cdot duration\_time\_rel_{h,h^A} \cdot ACT_{n^L,t\prime,y^V,y,m,h^A}
*
* TODO: add docs
***
SHARES_COMMODITY_LEVEL_LO(shares,node,commodity,level,year,time,type_tec_share,type_tec_total)$(
map_shares_commodity_level(shares,commodity,level,type_tec_share,type_tec_total) AND
share_factor_lo(shares,node,year,time)
)..
SUM( (location,tec,vintage,mode,time2)$(
SHARE_CONSTRAINT_COMMODITY_LO(shares,node_share,year,time)$( share_commodity_lo(shares,node_share,year,time) )..
* total input and output by `type_tec_share` technologies mapped to respective commodity, level and node
SUM( (node,location,type_tec_share,tec,vintage,mode,commodity,level,time2)$(
( map_shares_commodity_share(shares,node_share,node,type_tec_share,mode,commodity,level) OR
map_shares_commodity_share(shares,node_share,node,type_tec_share,'all',commodity,level) ) AND
cat_tec(type_tec_share,tec) AND
map_tec_act(location,tec,year,mode,time2) AND
map_tec_lifetime(location,tec,vintage,year)
),
* commodity activity generated by type_tec_share technologies
(
output(location,tec,vintage,year,mode,node,commodity,level,time2,time) +
input(location,tec,vintage,year,mode,node,commodity,level,time2,time)
) *
duration_time_rel(time,time2) *
ACT(location,tec,vintage,year,mode,time2)
)
)
=G=
share_factor_lo(shares,node,year,time) *
* commodity activity generated by type_tec_total technologies
SUM( (location,tec,vintage,mode,time2)$(
share_commodity_lo(shares,node_share,year,time) * (
* total input and output by `type_tec_total` technologies mapped to respective commodity, level and node
SUM( (node,location,type_tec_total,tec,vintage,mode,commodity,level,time2)$(
( map_shares_commodity_total(shares,node_share,node,type_tec_total,mode,commodity,level) OR
map_shares_commodity_total(shares,node_share,node,type_tec_total,'all',commodity,level) ) AND
cat_tec(type_tec_total,tec) AND
map_tec_act(location,tec,year,mode,time2) AND
map_tec_lifetime(location,tec,vintage,year)
Expand All @@ -1409,7 +1385,7 @@ SHARES_COMMODITY_LEVEL_LO(shares,node,commodity,level,year,time,type_tec_share,t
) *
duration_time_rel(time,time2) *
ACT(location,tec,vintage,year,mode,time2)
)
) )
;

***
Expand Down
12 changes: 6 additions & 6 deletions message_ix/model/MESSAGE/parameter_def.gms
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ Parameters
*
* * - Parameter name
* - Index dimensions
* * - share_factor_up
* - ``shares`` | ``node_loc`` | ``year_act`` | ``time``
* * - share_factor_lo
* - ``shares`` | ``node_loc`` | ``year_act`` | ``time``
* * - share_commodity_up
* - ``shares`` | ``node_share`` | ``year_act`` | ``time``
* * - share_commodity_lo
* - ``shares`` | ``node`` | ``year_act`` | ``time``
* * - share_mode_up
* - ``shares`` | ``node_loc`` | ``technology`` | ``mode`` | ``year_act`` | ``time``
* * - share_mode_lo
Expand All @@ -581,8 +581,8 @@ Parameters
***

Parameters
share_factor_up(shares,node,year_all,time) upper bound of share constraint
share_factor_lo(shares,node,year_all,time) lower bound of share constraint
share_commodity_up(shares,node,year_all,time) upper bound of commodity share constraint
share_commodity_lo(shares,node,year_all,time) lower bound of commodity share constraint
share_mode_up(shares,node,tec,mode,year_all,time) upper bound of mode share constraint
share_mode_lo(shares,node,tec,mode,year_all,time) lower bound of mode share constraint
;
Expand Down
8 changes: 5 additions & 3 deletions message_ix/model/MESSAGE/sets_maps_def.gms
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ Sets

* definition of aliases
Alias(node,location);
Alias(node,subnode);
Alias(node,node2);
Alias(node,node3);
Alias(node,node_share);
Alias(tec,tec2);
Alias(commodity,commodity2);
Alias(level,level2);
Expand Down Expand Up @@ -294,7 +293,10 @@ Sets
map_spatial_hierarchy(lvl_spatial,node,node) mapping of spatial resolution to nodes (last index is 'parent')
map_temporal_hierarchy(lvl_temporal,time,time) mapping of temporal resolution to time (last index is 'parent')

map_shares_commodity_level(shares,commodity,level,type_tec,type_tec) mapping of commodity and level share constraints
map_shares_commodity_share(shares,node,
node,type_tec,mode,commodity,level) mapping for commodity share constraints (numerator)
map_shares_commodity_total(shares,node,
node,type_tec,mode,commodity,level) mapping for commodity share constraints (denominator)

map_land(node,land_scenario,year_all) mapping of land-use model emulator scenarios to nodes and years
map_relation(relation,node,year_all) mapping of generic (user-defined) relations to nodes and years
Expand Down
Loading

0 comments on commit 48d3edd

Please sign in to comment.