33
44It takes in wind_to_solar_ratio.csv that has the following format
55
6- PERIOD,wind_to_solar_ratio
7- 2020,.
8- 2030,0.5
9- 2040,1
10- 2050,1.5
6+ PERIOD,wind_to_solar_ratio,wind_to_solar_ratio_const_gt
7+ 2020,.,.
8+ 2030,0.5,0
9+ 2040,1,0
10+ 2050,1.5,1
1111
1212Here when wind_to_solar_ratio is specified (i.e. not '.') a constraint is activated that enforces that
1313
14- Online wind capacity = Online solar capacity * wind_to_solar_ratio
14+ Online wind capacity >=/< = Online solar capacity * wind_to_solar_ratio
1515
1616for the entire period.
17+
18+ When wind_to_solar_ratio_const_gt is true (1) the constraint is a >= constraint.
19+ When wind_to_solar_ratio_const_gt is False (0) the constraint is a <= constraint.
1720"""
1821import os
1922
@@ -30,51 +33,77 @@ def define_components(mod):
3033 mod .WindCapacity = Expression (
3134 mod .PERIODS ,
3235 rule = lambda m , p : sum (
33- m .GenCapacity [g , p ] for g in m .VARIABLE_GENS if m .gen_energy_source [g ] == _WIND_ENERGY_TYPE
34- )
36+ m .GenCapacity [g , p ]
37+ for g in m .VARIABLE_GENS
38+ if m .gen_energy_source [g ] == _WIND_ENERGY_TYPE
39+ ),
3540 )
3641
3742 mod .SolarCapacity = Expression (
3843 mod .PERIODS ,
3944 rule = lambda m , p : sum (
40- m .GenCapacity [g , p ] for g in m .VARIABLE_GENS if m .gen_energy_source [g ] == _SOLAR_ENERGY_TYPE
41- )
45+ m .GenCapacity [g , p ]
46+ for g in m .VARIABLE_GENS
47+ if m .gen_energy_source [g ] == _SOLAR_ENERGY_TYPE
48+ ),
4249 )
4350
4451 mod .wind_to_solar_ratio = Param (
4552 mod .PERIODS ,
4653 default = 0 , # 0 means the constraint is inactive
47- within = NonNegativeReals
54+ within = NonNegativeReals ,
4855 )
4956
57+ mod .wind_to_solar_ratio_const_gt = Param (mod .PERIODS , default = True , within = Boolean )
58+
5059 # We use a scaling factor to improve the numerical properties
5160 # of the model.
5261 # Learn more by reading the documentation on Numerical Issues.
5362 # 1e-3 was picked since this value is normally on the order of GW instead of MW
5463 scaling_factor = 1e-3
64+
65+ def wind_to_solar_ratio_const_rule (m , p ):
66+ if m .wind_to_solar_ratio [p ] == 0 : # 0 means Constraint is inactive
67+ return Constraint .Skip
68+
69+ lhs = m .WindCapacity [p ] * scaling_factor
70+ rhs = m .SolarCapacity [p ] * m .wind_to_solar_ratio [p ] * scaling_factor
71+ if m .wind_to_solar_ratio_const_gt [p ]:
72+ return lhs >= rhs
73+ else :
74+ return lhs <= rhs
75+
5576 mod .wind_to_solar_ratio_const = Constraint (
56- mod .PERIODS ,
57- rule = lambda m , p : Constraint .skip if m .wind_to_solar_ratio == 0 else (
58- m .WindCapacity [p ] * scaling_factor == m .SolarCapacity [p ] * m .wind_to_solar_ratio [p ] * scaling_factor
59- )
77+ mod .PERIODS , rule = wind_to_solar_ratio_const_rule
6078 )
6179
6280
6381def load_inputs (mod , switch_data , inputs_dir ):
6482 switch_data .load_aug (
65- index = mod .PERIODS ,
66- filename = os .path .join (inputs_dir , 'wind_to_solar_ratio.csv' ),
83+ filename = os .path .join (inputs_dir , "wind_to_solar_ratio.csv" ),
6784 auto_select = True ,
68- param = (mod .wind_to_solar_ratio ,),
69- optional = True
85+ param = (mod .wind_to_solar_ratio , mod . wind_to_solar_ratio_const_gt ),
86+ optional = True , # We want to allow including this module even if the file isn't there
7087 )
7188
7289
7390def post_solve (m , outdir ):
74- df = pd .DataFrame ({
75- "WindCapacity (GW)" : value (m .WindCapacity [p ]) / 1000 ,
76- "SolarCapacity (GW)" : value (m .SolarCapacity [p ]) / 1000 ,
77- "ComputedRatio" : value (m .WindCapacity [p ] / m .SolarCapacity [p ]),
78- "ExpectedRatio" : value (m .wind_to_solar_ratio [p ])
79- } for p in m .PERIODS if m .wind_to_solar_ratio [p ] != 0 )
80- write_table (m , output_file = os .path .join (outdir , "wind_to_solar_ratio.csv" ), df = df , index = False )
91+ df = pd .DataFrame (
92+ {
93+ "WindCapacity (GW)" : value (m .WindCapacity [p ]) / 1000 ,
94+ "SolarCapacity (GW)" : value (m .SolarCapacity [p ]) / 1000 ,
95+ "ComputedRatio" : value (m .WindCapacity [p ] / m .SolarCapacity [p ])
96+ if value (m .SolarCapacity [p ]) != 0
97+ else "." ,
98+ "ExpectedRatio" : value (m .wind_to_solar_ratio [p ])
99+ if m .wind_to_solar_ratio [p ] != 0
100+ else "." ,
101+ }
102+ for p in m .PERIODS
103+ )
104+ write_table (
105+ m ,
106+ output_file = os .path .join (outdir , "wind_to_solar_ratio.csv" ),
107+ df = df ,
108+ index = False ,
109+ )
0 commit comments