Skip to content

Commit

Permalink
Update to the indexes for regions
Browse files Browse the repository at this point in the history
This commit:
1) Uniforms the definition of constraints for technology groups to constraints for single technology concerning the association to the regions index.
2) Removes the automatic permutation of the region names to obtain all the possible regions combination, since it caused instability when dealing with more than 10 regions. If more regions are associated with an item, the region combination must be added to the regions table.
3) Fixes other minor issues.
  • Loading branch information
matteo-nicoli committed Apr 19, 2024
1 parent badf53b commit f63a331
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 112 deletions.
26 changes: 14 additions & 12 deletions data_files/temoa_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ CREATE TABLE "groups" (
PRIMARY KEY("group_name")
);
CREATE TABLE "TechGroupWeight" (
"regions" text,
"tech" text,
"group_name" text,
"weight" real,
"tech_desc" text,
PRIMARY KEY("tech","group_name","regions")
PRIMARY KEY("tech","group_name")
);
CREATE TABLE "MinActivityGroup" (
"regions" text,
Expand All @@ -116,20 +115,23 @@ CREATE TABLE "MinActivityGroup" (
PRIMARY KEY("periods","group_name","regions")
);
CREATE TABLE "MaxActivityGroup" (
"regions" text,
"periods" integer,
"group_name" text,
"max_act_g" real,
"notes" text,
PRIMARY KEY("periods","group_name")
);
CREATE TABLE "MinCapacityGroup" (
"regions" text,
"periods" integer,
"group_name" text,
"min_cap_g" real,
"notes" text,
PRIMARY KEY("periods","group_name")
);
CREATE TABLE "MaxCapacityGroup" (
"regions" text,
"periods" integer,
"group_name" text,
"max_cap_g" real,
Expand Down Expand Up @@ -240,22 +242,22 @@ CREATE TABLE "StorageDuration" (
PRIMARY KEY("regions","tech")
);
CREATE TABLE "PlanningReserveMargin" (
`regions` text,
`reserve_margin` REAL,
PRIMARY KEY(regions),
FOREIGN KEY(`regions`) REFERENCES regions
"regions" text,
"reserve_margin" REAL,
PRIMARY KEY("regions"),
FOREIGN KEY("regions") REFERENCES regions
);
CREATE TABLE "RampDown" (
`regions` text,
`tech` text,
`ramp_down` real,
"regions" text,
"tech" text,
"ramp_down" real,
PRIMARY KEY("regions", "tech"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech")
);
CREATE TABLE "RampUp" (
`regions` text,
`tech` text,
`ramp_up` real,
"regions" text,
"tech" text,
"ramp_up" real,
PRIMARY KEY("regions", "tech"),
FOREIGN KEY("tech") REFERENCES "technologies"("tech")
);
Expand Down
Binary file modified data_files/temoa_schema.sqlite
Binary file not shown.
10 changes: 5 additions & 5 deletions temoa_model/temoa_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ def query_table (t_properties, f):
['set', 'tech_annual', '', '', 0],
['set', 'tech_variable', '', '', 0],
['set', 'groups', '', '', 0],
['param','TechGroupWeight', '', '', 3],
['param','MinActivityGroup', '', '', 2],
['param','MaxActivityGroup', '', '', 2],
['param','MinCapacityGroup', '', '', 2],
['param','MaxCapacityGroup', '', '', 2],
['param','TechGroupWeight', '', '', 2],
['param','MinActivityGroup', '', '', 3],
['param','MaxActivityGroup', '', '', 3],
['param','MinCapacityGroup', '', '', 3],
['param','MaxCapacityGroup', '', '', 3],
['param','MinInputGroup', '', '', 4],
['param','MaxInputGroup', '', '', 4],
['param','MinOutputGroup', '', '', 4],
Expand Down
18 changes: 2 additions & 16 deletions temoa_model/temoa_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ def CreateRegionalIndices ( M ):
regional_indices.add(r_i)
else:
regional_indices.add(r_i+"-"+r_j)
regional_indices.add('global')
return regional_indices


Expand Down Expand Up @@ -800,9 +801,7 @@ def CapacityFactorIndices(M):
indices = set(
(r, t, v)

for r in M.regions
for t in M.tech_all
for v in M.vintage_all
for r, i, t, v, o in M.Efficiency.sparse_iterkeys()
)

return indices
Expand Down Expand Up @@ -842,19 +841,6 @@ def CostInvestIndices ( M ):

return indices

def RegionalGlobalInitializedIndices ( M ):
from itertools import permutations
indices = set()
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('global')
indices = indices.union(M.RegionalIndices)

return indices


def EmissionActivityIndices ( M ):
indices = set(
(r, e, i, t, v, o)
Expand Down
49 changes: 24 additions & 25 deletions temoa_model/temoa_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,25 @@ def temoa_create_model(name="Temoa"):
)

# Define parameters associated with user-defined constraints
M.RegionalGlobalIndices = Set(initialize=RegionalGlobalInitializedIndices)
M.MinCapacity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.MaxCapacity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.MaxResource = Param(M.RegionalIndices, M.tech_all)
M.MaxActivity = Param(M.RegionalGlobalIndices, M.time_optimize, M.tech_all)
M.MinActivity = Param(M.RegionalGlobalIndices, M.time_optimize, M.tech_all)
M.MaxActivity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.MinActivity = Param(M.RegionalIndices, M.time_optimize, M.tech_all)
M.GrowthRateMax = Param(M.RegionalIndices, M.tech_all)
M.GrowthRateSeed = Param(M.RegionalIndices, M.tech_all)
M.EmissionLimit = Param(M.RegionalGlobalIndices, M.time_optimize, M.commodity_emissions)
M.EmissionLimit = Param(M.RegionalIndices, M.time_optimize, M.commodity_emissions)
M.EmissionActivity_reitvo = Set(dimen=6, initialize=EmissionActivityIndices)
M.EmissionActivity = Param(M.EmissionActivity_reitvo, default=0)
M.TechGroupWeight = Param(M.RegionalIndices, M.tech_groups, M.groups, default=0)
M.MinActivityGroup = Param(M.time_optimize, M.groups)
M.MaxActivityGroup = Param(M.time_optimize, M.groups)
M.MinCapacityGroup = Param(M.time_optimize, M.groups)
M.MaxCapacityGroup = Param(M.time_optimize, M.groups)
M.MinInputGroup = Param(M.regions, M.time_optimize, M.commodity_physical, M.groups)
M.MaxInputGroup = Param(M.regions, M.time_optimize, M.commodity_physical, M.groups)
M.MinOutputGroup = Param(M.regions, M.time_optimize, M.commodity_physical, M.groups)
M.MaxOutputGroup = Param(M.regions, M.time_optimize, M.commodity_physical, M.groups)
M.TechGroupWeight = Param(M.tech_groups, M.groups, default=0)
M.MinActivityGroup = Param(M.RegionalIndices, M.time_optimize, M.groups)
M.MaxActivityGroup = Param(M.RegionalIndices, M.time_optimize, M.groups)
M.MinCapacityGroup = Param(M.RegionalIndices, M.time_optimize, M.groups)
M.MaxCapacityGroup = Param(M.RegionalIndices, M.time_optimize, M.groups)
M.MinInputGroup = Param(M.RegionalIndices, M.time_optimize, M.commodity_physical, M.groups)
M.MaxInputGroup = Param(M.RegionalIndices, M.time_optimize, M.commodity_physical, M.groups)
M.MinOutputGroup = Param(M.RegionalIndices, M.time_optimize, M.commodity_physical, M.groups)
M.MaxOutputGroup = Param(M.RegionalIndices, M.time_optimize, M.commodity_physical, M.groups)
M.LinkedTechs = Param(M.RegionalIndices, M.tech_all, M.commodity_emissions)

# Define parameters associated with electric sector operation
Expand Down Expand Up @@ -455,32 +454,32 @@ def temoa_create_model(name="Temoa"):
M.MinActivityConstraint_rpt, rule=MinActivity_Constraint
)

M.MinActivityGroup_pg = Set(
dimen=2, initialize=lambda M: M.MinActivityGroup.sparse_iterkeys()
M.MinActivityGroup_rpg = Set(
dimen=3, initialize=lambda M: M.MinActivityGroup.sparse_iterkeys()
)
M.MinActivityGroupConstraint = Constraint(
M.MinActivityGroup_pg, rule=MinActivityGroup_Constraint
M.MinActivityGroup_rpg, rule=MinActivityGroup_Constraint
)

M.MaxActivityGroup_pg = Set(
dimen=2, initialize=lambda M: M.MaxActivityGroup.sparse_iterkeys()
M.MaxActivityGroup_rpg = Set(
dimen=3, initialize=lambda M: M.MaxActivityGroup.sparse_iterkeys()
)
M.MaxActivityGroupConstraint = Constraint(
M.MaxActivityGroup_pg, rule=MaxActivityGroup_Constraint
M.MaxActivityGroup_rpg, rule=MaxActivityGroup_Constraint
)

M.MinCapacityGroupConstraint_pg = Set(
dimen=2, initialize=lambda M: M.MinCapacityGroup.sparse_iterkeys()
M.MinCapacityGroupConstraint_rpg = Set(
dimen=3, initialize=lambda M: M.MinCapacityGroup.sparse_iterkeys()
)
M.MinCapacityGroupConstraint = Constraint(
M.MinCapacityGroupConstraint_pg, rule=MinCapacityGroup_Constraint
M.MinCapacityGroupConstraint_rpg, rule=MinCapacityGroup_Constraint
)

M.MaxCapacityGroupConstraint_pg = Set(
dimen=2, initialize=lambda M: M.MaxCapacityGroup.sparse_iterkeys()
M.MaxCapacityGroupConstraint_rpg = Set(
dimen=3, initialize=lambda M: M.MaxCapacityGroup.sparse_iterkeys()
)
M.MaxCapacityGroupConstraint = Constraint(
M.MaxCapacityGroupConstraint_pg, rule=MaxCapacityGroup_Constraint
M.MaxCapacityGroupConstraint_rpg, rule=MaxCapacityGroup_Constraint
)

M.MinInputGroup_Constraint_rpig = Set(
Expand Down
Loading

0 comments on commit f63a331

Please sign in to comment.