Skip to content

Commit 78e3756

Browse files
committed
Linearizing nonlinear constraints and debugging
1 parent a6e1fc1 commit 78e3756

2 files changed

Lines changed: 39 additions & 10 deletions

File tree

src/constraints/water_power_constraints.jl

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,27 @@ function add_water_power_constraints(m,p)
157157
@variable(m, turbine_power_rating[t in p.techs.water_power_turbines] >= 0)
158158

159159
# If the existing power ratings are defined, limit the power rating to the existing kw
160-
if p.s.water_power.existing_kw_per_turbine != nothing
160+
if (p.s.water_power.existing_kw_per_turbine != nothing) && (p.s.water_power.existing_kw_per_turbine != 0)
161161
@constraint(m, [t in p.techs.water_power_turbines], m[:turbine_power_rating][t] == p.s.water_power.existing_kw_per_turbine)
162162
else
163+
print("\n ***** Adding the min and max turbine kw ratings")
164+
print(", p.s.water_power.max_kw_turbine is $(p.s.water_power.max_kw_turbine)")
163165
@constraint(m, [t in p.techs.water_power_turbines], m[:turbine_power_rating][t] >= p.s.water_power.min_kw_turbine)
164166
@constraint(m, [t in p.techs.water_power_turbines], m[:turbine_power_rating][t] <= p.s.water_power.max_kw_turbine)
165167
end
166168

169+
# Define the TurbinePowerGeneration variable
170+
@variable(m, TurbinePowerGenerationMaximum[t in p.techs.water_power_turbines, ts in p.time_steps] >= 0)
171+
167172
# Limit power output from the water_power turbines:
168-
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_turbines], m[:dvRatedProduction][t,ts] <= m[:binTurbineActive][t,ts]* m[:turbine_power_rating][t])
173+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_turbines], m[:dvRatedProduction][t,ts] <= m[:TurbinePowerGenerationMaximum][t,ts])
169174

175+
# Method for linearizing the product of a binary variable and a continuous variable:
176+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_turbines], m[:TurbinePowerGenerationMaximum][t,ts] <= m[:binTurbineActive][t,ts] * 1000000)
177+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_turbines], m[:TurbinePowerGenerationMaximum][t,ts] <= m[:turbine_power_rating][t])
178+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_turbines], m[:TurbinePowerGenerationMaximum][t,ts] >= m[:turbine_power_rating][t] - (1000000*(1-m[:binTurbineActive][t,ts])))
179+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_turbines], m[:TurbinePowerGenerationMaximum][t,ts] >= 0)
180+
170181
# Limit the water flow through the spillway, if a value was input
171182
if !isnothing(p.s.water_power.spillway_maximum_cubic_meter_per_second)
172183
@constraint(m, [ts in p.time_steps], m[:dvSpillwayWaterFlow][ts] <= p.s.water_power.spillway_maximum_cubic_meter_per_second)
@@ -227,20 +238,27 @@ function add_water_power_constraints(m,p)
227238
@variable(m, pump_power_rating[t in p.techs.water_power_pumps] >= 0)
228239

229240
# Pump size constraints
230-
if p.s.water_power.are_pumps_reversible && (p.s.water_power.existing_kw_per_pump == nothing)
241+
if p.s.water_power.are_pumps_reversible && ((p.s.water_power.existing_kw_per_pump == nothing) || (p.s.water_power.existing_kw_per_pump != 0))
231242
@constraint(m, [t in p.techs.water_power_pumps], m[:pump_power_rating][t] == p.s.water_power.pump_kw_to_turbine_kw_ratio_for_reversible_pumps * m[:turbine_power_rating][t])
232-
elseif p.s.water_power.existing_kw_per_pump != nothing
243+
elseif (p.s.water_power.existing_kw_per_pump != nothing) && (p.s.water_power.existing_kw_per_pump != 0)
233244
@constraint(m, [t in p.techs.water_power_pumps], m[:pump_power_rating][t] == p.s.water_power.existing_kw_per_pump)
234245
else
235246
@constraint(m, [t in p.techs.water_power_pumps], m[:pump_power_rating][t] >= p.s.water_power.min_kw_pump)
236247
@constraint(m, [t in p.techs.water_power_pumps], m[:pump_power_rating][t] <= p.s.water_power.max_kw_pump)
237248
end
238249

250+
# Define the PumpPowerInput variable
251+
@variable(m, PumpPowerInputMaximum[t in p.techs.water_power_pumps, ts in p.time_steps] >= 0)
252+
239253
# The electric power input into each pump must be below the pump's electric power rating
240-
@constraint(m, [t in p.techs.water_power_pumps, ts in p.time_steps],
241-
m[:dvPumpPowerInput][t, ts] <= m[:binPumpingWaterActive][t,ts] * m[:pump_power_rating][t]
242-
)
243-
254+
@constraint(m, [t in p.techs.water_power_pumps, ts in p.time_steps], m[:dvPumpPowerInput][t, ts] <= m[:PumpPowerInputMaximum][t, ts])
255+
256+
# Method for linearizing the product of a binary variable and a continuous variable (PumpPowerInputMaximum * binPumpingWaterActive)
257+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_pumps], m[:PumpPowerInputMaximum][t,ts] <= m[:binPumpingWaterActive][t,ts] * 1000000)
258+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_pumps], m[:PumpPowerInputMaximum][t,ts] <= m[:pump_power_rating][t])
259+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_pumps], m[:PumpPowerInputMaximum][t,ts] >= m[:pump_power_rating][t] - (1000000*(1-m[:binPumpingWaterActive][t,ts])))
260+
@constraint(m, [ts in p.time_steps, t in p.techs.water_power_pumps], m[:PumpPowerInputMaximum][t,ts] >= 0)
261+
244262
if p.s.water_power.computation_type == "average_power_conversion"
245263

246264
# Conversion between pumped water flow rate and power input into the pump

src/core/scenario.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ function Scenario(d::Dict; flex_hvac_from_json=false)
256256

257257
water_power = WaterPower(;
258258
existing_kw_per_turbine = d["water_power"]["existing_kw_per_turbine"],
259+
turbine_cost_per_kw = d["water_power"]["turbine_cost_per_kw"],
260+
min_kw_turbine = d["water_power"]["min_kw_turbine"],
261+
max_kw_turbine = d["water_power"]["max_kw_turbine"],
262+
259263
number_of_turbines = d["water_power"]["number_of_turbines"],
260264
computation_type = d["water_power"]["computation_type"],
261265
average_cubic_meters_per_second_per_kw = d["water_power"]["average_cubic_meters_per_second_per_kw"],
@@ -291,8 +295,15 @@ function Scenario(d::Dict; flex_hvac_from_json=false)
291295
maximum_downstream_reservoir_volume_cubic_meters=d["water_power"]["maximum_downstream_reservoir_volume_cubic_meters"],
292296
number_of_pumps=d["water_power"]["number_of_pumps"],
293297
water_pump_average_cubic_meters_per_second_per_kw=d["water_power"]["water_pump_average_cubic_meters_per_second_per_kw"],
294-
existing_kw_per_pump=d["water_power"]["existing_kw_per_pump"]
295-
)
298+
existing_kw_per_pump=d["water_power"]["existing_kw_per_pump"],
299+
min_kw_pump = d["water_power"]["min_kw_pump"],
300+
max_kw_pump = d["water_power"]["max_kw_pump"],
301+
pump_cost_per_kw = d["water_power"]["pump_cost_per_kw"],
302+
are_pumps_reversible = d["water_power"]["are_pumps_reversible"],
303+
pump_kw_to_turbine_kw_ratio_for_reversible_pumps = d["water_power"]["pump_kw_to_turbine_kw_ratio_for_reversible_pumps"],
304+
minimum_water_flow_cubic_meter_per_second_per_pump = d["water_power"]["minimum_water_flow_cubic_meter_per_second_per_pump"],
305+
maximum_water_flow_cubic_meter_per_second_per_pump = d["water_power"]["maximum_water_flow_cubic_meter_per_second_per_pump"]
306+
)
296307

297308
else
298309
water_power = WaterPower(; existing_kw_per_turbine = 0)

0 commit comments

Comments
 (0)