def test_pm_tnep_cigre_dc(): # get the grid net = cigre_grid() # add the possible new lines define_possible_new_lines(net) # check if max line loading percent is violated (should be) pp.runpp(net) print("Max line loading prior to optimization:") print(net.res_line.loading_percent.max()) assert np.any(net["res_line"].loc[:, "loading_percent"] > net["line"].loc[:, "max_loading_percent"]) # run power models tnep optimization pp.runpm_tnep(net, pm_solver="juniper", pm_model="DCPPowerModel" ) # gurobi is a better option, but not for travis # print the information about the newly built lines print("These lines are to be built:") print(net["res_ne_line"]) # set lines to be built in service lines_to_built = net["res_ne_line"].loc[net["res_ne_line"].loc[:, "built"], "built"].index net["line"].loc[lines_to_built, "in_service"] = True # run a power flow calculation again and check if max_loading percent is still violated pp.runpp(net) # check max line loading results assert not np.any(net["res_line"].loc[:, "loading_percent"] > net["line"].loc[:, "max_loading_percent"]) print("Max line loading after the optimization:") print(net.res_line.loading_percent.max())
def test_pm_tnep(): net = tnep_grid() # check if max line loading percent is violated (should be) pp.runpp(net) assert np.any(net["res_line"].loc[:, "loading_percent"] > net["line"].loc[:, "max_loading_percent"]) # run power models tnep optimization pp.runpm_tnep(net, pm_model="ACPPowerModel") # set lines to be built in service lines_to_built = net["res_ne_line"].loc[net["res_ne_line"].loc[:, "built"], "built"].index net["line"].loc[lines_to_built, "in_service"] = True # run a power flow calculation again and check if max_loading percent is still violated pp.runpp(net) # check max line loading results assert not np.any(net["res_line"].loc[:, "loading_percent"] > net["line"].loc[:, "max_loading_percent"])
def run_pm_tnep(net, **settings): logger.debug("Starting PowerModels.jl TNEP:") lines = set() # these steps are the decreasing line loading limits so that we get different measures # we need this becaus: DCP 80% I_max != DCP 90% I_max steps = [.9, .95, 1.] step1_sol = [] # time limits for PowerModels.jl solver pm_time_limits = {"pm_time_limit": settings["pm_time_limit"], "pm_nl_time_limit": settings["pm_nl_time_limit"], "pm_mip_time_limit": settings["pm_mip_time_limit"]} for step in steps: logger.debug(f"starting PowerModels.jl TNEP with with max. line loading {step}") # reduce the max. line loading net.line.loc[:, "max_loading_percent"] = settings["i_lim"] * step net.ne_line.loc[:, "max_loading_percent"] = settings["i_lim"] * step try: # runs PowerModels.jl TNEP pp.runpm_tnep(net, pm_model=settings["model"], pm_solver=settings["solver"], pm_log_level=1, pm_time_limits=pm_time_limits) except: logger.error("power models failed.") continue # the PowerModels.jl solution sol = net["res_ne_line"].loc[net["res_ne_line"].loc[:, "built"], "built"].index if step == 1.: # 90% solution of PowerModels (probably not AC feasible) step1_sol = sol # all lines 'recommended' by the TNEP opt lines |= set(list(sol)) # reset the limits to the original value net.ne_line.loc[:, "max_loading_percent"] = settings["i_lim"] net.line.loc[:, "max_loading_percent"] = settings["i_lim"] if len(step1_sol): # check if the best PowerModels.jl solution is good check_pm_solution(net, step1_sol) return lines, step1_sol