amplpower
- class amplpower.PowerSystem(case_file: str, max_voltage_angle: float = 1.5707963267948966, min_voltage_angle: float = -1.5707963267948966)[source]
PowerSystem class for solving optimal power flow problems.
- __init__(case_file: str, max_voltage_angle: float = 1.5707963267948966, min_voltage_angle: float = -1.5707963267948966)[source]
Initialize the power system with a MATPOWER case file.
- compute_lodf()[source]
Compute the LODF (Line Outage Distribution Factor) matrix and store it in self.lodf. Uses the PTDF matrix already stored in self.ptdf.
- compute_ptdf()[source]
Compute the PTDF (Power Transfer Distribution Factor) matrix and store it in self.ptdf. The slack bus is the one with BUS_TYPE == 3 in self.buses dataframe.
- create_model(opf_type='dc', connectivity='off')[source]
Compute the feasible region for the power system. Parameters: opf_type (str): Type of optimal power flow (‘dc’, ‘acrect’, ‘acjabr’) connectivity (str): Connectivity for topology solutions (‘off’, ‘on’)
- get_results_opf(opf_type='dc')[source]
Get results from the solved model. Returns: object: Results of the optimization with attributes like obj, time, generators, buses, branches, etc.
- initialize(voltages=None, angles=None)[source]
Initialize the voltage magnitudes, angles, flows, and generation levels.
- is_feasible(voltages, angles)[source]
Check feasibility of a given voltage and angle vector. Returns a dictionary with slacks for each constraint. If a variable is feasible, slack is 0. Otherwise, it is the absolute value needed to make it feasible.
- set_switching(switching)[source]
Set the switching status of the branches.
Explanations: - ‘off’: All lines are connected (no switching, all BR_SWITCH=1). - ‘nl’: Use binary variables for line connection with a non-linear formulation (BR_SWITCH=2). - ‘bigm’: Use binary variables for line connection with a Big-M formulation (BR_SWITCH=3). - ‘df’: Use the values already stored in BR_SWITCH (do not modify). - numpy.ndarray: Directly set BR_SWITCH to the provided array.
Switching statuses: 0: The line is off. 1: The line is on. 2: The line is switchable and modeled with a non-linear approach. 3: The line is switchable and modeled with a Big-M approach.
Parameters: switching (str or np.ndarray): The switching strategy or array of statuses.
- solve_model(solver='gurobi', options='')[source]
Solve the model using the specified solver. Parameters: solver (str): Solver to use (‘gurobi’, ‘cplex’, ‘cbc’) options (str): Options for the solver Returns: dict: Results of the optimization
- solve_opf(opf_type='dc', switching='off', connectivity='off', solver='gurobi', options='')[source]
Solve the optimal power flow problem using AMPL. Parameters: opf_type (str): Type of optimal power flow (‘dc’, ‘acrect’, ‘acjabr’) switching (str): Switching strategy (‘off’, ‘nl’, ‘bigm’) connectivity (str): Connectivity for topology solutions (‘off’, ‘on’) solver (str): Solver to use (‘gurobi’, ‘cplex’, ‘cbc’) options (str): Options for the solver Returns: dict: Results of the optimal power flow problem