Skip to content

Commit

Permalink
Allow '-', '+' in regions index for constraints
Browse files Browse the repository at this point in the history
This commit allows the use of '-' and '+' in the regions index
of the MinActivity, MaxActivity and EmissionLimit constraints.
The use of '-' allows for technologies in the tech_exchange set
to be specified.
The use of '+' allows for constraints on the same technology across
multiple regions.
  • Loading branch information
aranyavenkatesh committed Jun 28, 2022
1 parent 7bbb935 commit 58a029a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion temoa_model/temoa_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,9 @@ def RegionalGlobalInitializedIndices ( M ):
for n in range(1,len(M.regions)+1):
regional_perms = permutations(M.regions,n)
for i in regional_perms:
indices.add("-".join(i))
indices.add("+".join(i))
indices.add('global')
indices = indices.union(M.RegionalIndices)

return indices

Expand Down
29 changes: 19 additions & 10 deletions temoa_model/temoa_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,13 +1531,18 @@ def EmissionLimit_Constraint(M, r, p, e):
"""
emission_limit = M.EmissionLimit[r, p, e]

# r can be an individual region (r='US'), or a combination of regions separated by hyphen (r='Mexico-US-Canada'), or 'global'.
# Note that regions!=M.regions. We iterate over regions to find actural_emissions and actual_emissions_annual.
regions = set(r.split("-"))
# r can be an individual region (r='US'), or a combination of regions separated by a + (r='Mexico+US+Canada'), or 'global'.
# Note that regions!=M.regions. We iterate over regions to find actual_emissions and actual_emissions_annual.


# if r == 'global', the constraint is system-wide
if regions == {'global'}:

if r == 'global':
regions = M.regions
elif '+' in r:
regions = r.split('+')
else:
regions = [r]


actual_emissions = sum(
Expand Down Expand Up @@ -1672,17 +1677,19 @@ def MaxActivity_Constraint(M, r, p, t):
\forall \{r, p, t \in T^{a}\} \in \Theta_{\text{MaxActivity}}
"""
# r can be an individual region (r='US'), or a combination of regions separated by hyphen (r='Mexico-US-Canada'), or 'global'.
# r can be an individual region (r='US'), or a combination of regions separated by a + (r='Mexico+US+Canada'), or 'global'.
# if r == 'global', the constraint is system-wide
if r == 'global':
reg = M.regions
elif '+' in r:
reg = r.split('+')
else:
reg = [r]

try:
activity_rpt = sum(
M.V_FlowOut[r, p, s, d, S_i, t, S_v, S_o]
for r in reg if '-' not in r
for r in reg
for S_v in M.processVintages[r, p, t]
for S_i in M.processInputs[r, p, t, S_v]
for S_o in M.ProcessOutputsByInput[r, p, t, S_v, S_i]
Expand All @@ -1692,7 +1699,7 @@ def MaxActivity_Constraint(M, r, p, t):
except:
activity_rpt = sum(
M.V_FlowOutAnnual[r, p, S_i, t, S_v, S_o]
for r in reg if '-' not in r
for r in reg
for S_v in M.processVintages[r, p, t]
for S_i in M.processInputs[r, p, t, S_v]
for S_o in M.ProcessOutputsByInput[r, p, t, S_v, S_i]
Expand Down Expand Up @@ -1725,17 +1732,19 @@ def MinActivity_Constraint(M, r, p, t):
\forall \{r, p, t \in T^{a}\} \in \Theta_{\text{MinActivity}}
"""
# r can be an individual region (r='US'), or a combination of regions separated by hyphen (r='Mexico-US-Canada'), or 'global'.
# r can be an individual region (r='US'), or a combination of regions separated by a + (r='Mexico+US+Canada'), or 'global'.
# if r == 'global', the constraint is system-wide
if r == 'global':
reg = M.regions
elif '+' in r:
reg = r.split('+')
else:
reg = [r]

try:
activity_rpt = sum(
M.V_FlowOut[r, p, s, d, S_i, t, S_v, S_o]
for r in reg if '-' not in r
for r in reg
for S_v in M.processVintages[r, p, t]
for S_i in M.processInputs[r, p, t, S_v]
for S_o in M.ProcessOutputsByInput[r, p, t, S_v, S_i]
Expand All @@ -1745,7 +1754,7 @@ def MinActivity_Constraint(M, r, p, t):
except:
activity_rpt = sum(
M.V_FlowOutAnnual[r, p, S_i, t, S_v, S_o]
for r in reg if '-' not in r
for r in reg
for S_v in M.processVintages[r, p, t]
for S_i in M.processInputs[r, p, t, S_v]
for S_o in M.ProcessOutputsByInput[r, p, t, S_v, S_i]
Expand Down

0 comments on commit 58a029a

Please sign in to comment.