|
| 1 | +""" |
| 2 | +This module allows defining a constraint that specifies a minimum buildout for a certain type of gen_tech. |
| 3 | +
|
| 4 | +The advantage of this module is that it stills allows switch to decide where to place |
| 5 | +the specified technology. |
| 6 | +""" |
| 7 | +import os |
| 8 | + |
| 9 | +from pyomo.environ import * |
| 10 | + |
| 11 | +from switch_model.reporting import write_table |
| 12 | + |
| 13 | + |
| 14 | +def define_components(mod): |
| 15 | + mod.GEN_TECH_PER_PERIOD = Set( |
| 16 | + initialize=lambda m: m.GENERATION_TECHNOLOGIES * m.PERIODS, |
| 17 | + dimen=2 |
| 18 | + ) |
| 19 | + |
| 20 | + mod.minimum_capacity_mw = Param( |
| 21 | + mod.GEN_TECH_PER_PERIOD, |
| 22 | + within=NonNegativeReals, |
| 23 | + default=0 |
| 24 | + ) |
| 25 | + |
| 26 | + mod.GenCapacityPerTech = Expression( |
| 27 | + mod.GEN_TECH_PER_PERIOD, |
| 28 | + rule=lambda m, tech, p: sum(m.GenCapacity[g, p] for g in m.GENS_BY_TECHNOLOGY[tech]) |
| 29 | + ) |
| 30 | + |
| 31 | + mod.Enforce_Minimum_Capacity_Per_Tech = Constraint( |
| 32 | + mod.GEN_TECH_PER_PERIOD, |
| 33 | + rule=lambda m, tech, p: |
| 34 | + Constraint.Skip if m.minimum_capacity_mw[tech, p] == 0 else m.GenCapacityPerTech[tech, p] >= |
| 35 | + m.minimum_capacity_mw[tech, p] |
| 36 | + ) |
| 37 | + |
| 38 | + |
| 39 | +def load_inputs(mod, switch_data, inputs_dir): |
| 40 | + """ |
| 41 | + Expected input file: |
| 42 | +
|
| 43 | + min_per_tech.csv with the following format: |
| 44 | + gen_tech,period,minimum_capacity_mw |
| 45 | + Nuclear,2040,10 |
| 46 | + """ |
| 47 | + switch_data.load_aug( |
| 48 | + filename=os.path.join(inputs_dir, "min_per_tech.csv"), |
| 49 | + param=mod.minimum_capacity_mw, |
| 50 | + auto_select=True, |
| 51 | + # We want this module to run even if we don't specify a constraint so we still get the useful outputs |
| 52 | + optional=True |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +def post_solve(mod, outdir): |
| 57 | + write_table( |
| 58 | + mod, |
| 59 | + mod.GEN_TECH_PER_PERIOD, |
| 60 | + output_file=os.path.join(outdir, "gen_cap_per_tech.csv"), |
| 61 | + headings=("gen_tech", "period", "gen_capacity", "minimum_capacity_mw"), |
| 62 | + values=lambda m, tech, p: (tech, p, m.GenCapacityPerTech[tech, p], m.minimum_capacity_mw[tech, p]) |
| 63 | + ) |
0 commit comments