@@ -260,63 +260,3 @@ def plot_lmp(self, output_folder: str = None) -> None:
260260 lmp_df = self .system_record .get_lmp (),
261261 output_folder = output_folder ,
262262 )
263-
264- def reoperate (
265- self ,
266- k : int ,
267- builder : ModelBuilder ,
268- init_conds : dict ,
269- mip_gap : float = None ,
270- timelimit : float = None ,
271- ):
272- raise NotImplementedError ("Reoperation is not implemented yet." )
273- reop_converge = False
274- reop_k = 0
275- while not reop_converge :
276- print (f"\n Reservoirs reoperation iteration { reop_k } " )
277- print ("New Capacity vs. Current Dispatch" )
278-
279- # PowNet returns the hydropower dispatch in hourly resolution across the simulation horizon
280- hydro_dispatch , start_day , end_day = get_hydro_from_model (
281- self .model .model , k
282- )
283- # Convert to daily dispatch
284- hydro_dispatch = convert_to_daily_hydro (hydro_dispatch , start_day , end_day )
285- new_hydro_capacity = self .reservoir_operator .reoperate_basins (
286- pownet_dispatch = hydro_dispatch
287- )
288-
289- for res in new_hydro_capacity .columns :
290- print (
291- f"{ res } : { round (new_hydro_capacity [res ].sum (),2 )} vs { round (hydro_dispatch [res ].sum (),2 )} " ,
292- )
293-
294- max_deviation = (new_hydro_capacity - hydro_dispatch ).abs ().max ()
295- # The tolerance for convergence should be 5% of the largest hydro capacity
296- reop_tol = 0.05 * new_hydro_capacity .max ()
297- if (max_deviation <= reop_tol [max_deviation .index ]).all ():
298- reop_converge = True
299- print (f"PowNet: Day { k + 1 } - Reservoirs converged at iteration { reop_k } " )
300-
301- if reop_k > 50 :
302- raise ValueError (
303- "Reservoirs reoperation did not converge after 100 iterations"
304- )
305-
306- # To reoptimize PowNet with the new hydropower capacity,
307- # update the builder class
308- builder .update_hydro_capacity (new_hydro_capacity )
309- self .model = builder .update (
310- k = k ,
311- init_conds = init_conds ,
312- mip_gap = mip_gap ,
313- timelimit = timelimit ,
314- )
315- self .model .optimize ()
316-
317- # Keep track of optimization time oand reoperation iterations
318- self .reop_opt_time += self .model .get_runtime ()
319- reop_k += 1
320-
321- # Record the number of iterations after convergence
322- self .reop_iter .append (reop_k )
0 commit comments