def run_lopf(n, allow_warning_status=False, fix_ext_lines=False):
        free_output_series_dataframes(n)

        pypsa.opf.network_lopf_build_model(n, formulation=solve_opts['formulation'])
        add_opts_constraints(n, opts)
        if not fix_ext_lines:
            add_lv_constraint(n)
            add_lc_constraint(n)

        pypsa.opf.network_lopf_prepare_solver(n, solver_name=solver_name)

        if fix_ext_lines:
            fix_branches(n,
                         lines_s_nom=n.lines.loc[n.lines.s_nom_extendable, 's_nom_opt'],
                         links_p_nom=n.links.loc[n.links.p_nom_extendable, 'p_nom_opt'])

        # Firing up solve will increase memory consumption tremendously, so
        # make sure we freed everything we can
        gc.collect()
        status, termination_condition = \
        pypsa.opf.network_lopf_solve(n,
                                     solver_logfile=solver_log,
                                     solver_options=solver_options,
                                     formulation=solve_opts['formulation'],
                                     extra_postprocessing=extra_postprocessing
                                     #free_memory={'pypsa'}
                                     )

        assert status == "ok" or allow_warning_status and status == 'warning', \
            ("network_lopf did abort with status={} "
             "and termination_condition={}"
             .format(status, termination_condition))

        return status, termination_condition
Beispiel #2
0
    def run_lopf(n, allow_warning_status=False, fix_zero_lines=False, fix_ext_lines=False):
        free_output_series_dataframes(n)

        if fix_zero_lines:
            fix_lines_b = (n.lines.s_nom_opt == 0.) & n.lines.s_nom_extendable
            fix_links_b = (n.links.carrier=='DC') & (n.links.p_nom_opt == 0.) & n.links.p_nom_extendable
            fix_branches(n,
                         lines_s_nom=pd.Series(0., n.lines.index[fix_lines_b]),
                         links_p_nom=pd.Series(0., n.links.index[fix_links_b]))

        if fix_ext_lines:
            fix_branches(n,
                         lines_s_nom=n.lines.loc[n.lines.s_nom_extendable, 's_nom_opt'],
                         links_p_nom=n.links.loc[(n.links.carrier=='DC') & n.links.p_nom_extendable, 'p_nom_opt'])
            if "line_volume_constraint" in n.global_constraints.index:
                n.global_constraints.drop("line_volume_constraint",inplace=True)
        else:
            if "line_volume_constraint" not in n.global_constraints.index:
                line_volume = getattr(n, 'line_volume_limit', None)
                if line_volume is not None and not np.isinf(line_volume):
                    n.add("GlobalConstraint",
                          "line_volume_constraint",
                          type="transmission_volume_expansion_limit",
                          carrier_attribute="AC,DC",
                          sense="<=",
                          constant=line_volume)


        # Firing up solve will increase memory consumption tremendously, so
        # make sure we freed everything we can
        gc.collect()

        #from pyomo.opt import ProblemFormat
        #print("Saving model to MPS")
        #n.model.write('/home/ka/ka_iai/ka_kc5996/projects/pypsa-eur/128-B-I.mps', format=ProblemFormat.mps)
        #print("Model is saved to MPS")
        #sys.exit()


        status, termination_condition = n.lopf(pyomo=False,
                                               solver_name=solver_name,
                                               solver_logfile=solver_log,
                                               solver_options=solver_options,
                                               extra_functionality=extra_functionality,
                                               formulation=solve_opts['formulation'])
                                               #extra_postprocessing=extra_postprocessing
                                               #keep_files=True
                                               #free_memory={'pypsa'}

        assert status == "ok" or allow_warning_status and status == 'warning', \
            ("network_lopf did abort with status={} "
             "and termination_condition={}"
             .format(status, termination_condition))

        if not fix_ext_lines and "line_volume_constraint" in n.global_constraints.index:
            n.line_volume_limit_dual = n.global_constraints.at["line_volume_constraint","mu"]
            print("line volume limit dual:",n.line_volume_limit_dual)

        return status, termination_condition
Beispiel #3
0
    def run_lopf(n,
                 allow_warning_status=False,
                 fix_zero_lines=False,
                 fix_ext_lines=False):
        free_output_series_dataframes(n)

        if not hasattr(n, 'opt') or not isinstance(n.opt,
                                                   pypsa.opf.PersistentSolver):
            pypsa.opf.network_lopf_build_model(
                n, formulation=solve_opts['formulation'])
            add_opts_constraints(n, opts)
            add_lv_constraint(n)
            # add_eps_storage_constraint(n)

            pypsa.opf.network_lopf_prepare_solver(n, solver_name=solver_name)

        if fix_zero_lines:
            fix_lines_b = (n.lines.s_nom_opt == 0.) & n.lines.s_nom_extendable
            fix_links_b = (n.links.p_nom_opt == 0.) & n.links.p_nom_extendable
            fix_branches(n,
                         lines_s_nom=pd.Series(0., n.lines.index[fix_lines_b]),
                         links_p_nom=pd.Series(0., n.links.index[fix_links_b]))

        if fix_ext_lines:
            fix_branches(n,
                         lines_s_nom=n.lines.loc[n.lines.s_nom_extendable,
                                                 's_nom_opt'],
                         links_p_nom=n.links.loc[n.links.p_nom_extendable,
                                                 'p_nom_opt'])

        # Firing up solve will increase memory consumption tremendously, so
        # make sure we freed everything we can
        gc.collect()
        status, termination_condition = \
        pypsa.opf.network_lopf_solve(n,
                                     solver_logfile=solver_log,
                                     solver_options=solver_options,
                                     formulation=solve_opts['formulation'],
                                     #free_memory={'pypsa'}
                                     )

        assert status == "ok" or allow_warning_status and status == 'warning', \
            ("network_lopf did abort with status={} "
             "and termination_condition={}"
             .format(status, termination_condition))

        return status, termination_condition