pownet.optim_model package
Subpackages
- pownet.optim_model.constraints package
- Submodules
- pownet.optim_model.constraints.energy_storage_constr module
- pownet.optim_model.constraints.nondispatch_constr module
- pownet.optim_model.constraints.system_constr module
- pownet.optim_model.constraints.thermal_unit_constr module
add_c_link_ppbar()add_c_link_pthermal()add_c_link_pu_lower()add_c_link_pu_upper()add_c_link_spin()add_c_link_uvw()add_c_link_uvw_init()add_c_min_down()add_c_min_down_init()add_c_min_up()add_c_min_up_init()add_c_peak_down_bound()add_c_peak_up_bound()add_c_ramp_down()add_c_ramp_down_init()add_c_ramp_up()add_c_ramp_up_init()
- Module contents
Submodules
pownet.optim_model.model module
model.py: PowerSystemModel is wrapper of gurobipy.Model and highspy.Highs to provide a more user-friendly interface while compatible with HiGHs solver.
- class pownet.optim_model.model.PowerSystemModel(model)[source]
Bases:
object- optimize_with_rounding(rounding_strategy, max_rounding_iter, threshold=0, mipgap=0.001, timelimit=600, num_threads=0, log_to_console=False)[source]
- Return type:
None
- solve_for_export_capacity(shared_nodes, sim_horizon, step_k)[source]
Return the export capacity and hourly prices at the shared nodes
- Return type:
tuple
- solve_for_export_prices(shared_nodes, sim_horizon, step_k)[source]
The export prices are locational marginal prices at the shared nodes.
- Return type:
DataFrame
pownet.optim_model.objfunc module
objfunc.py: Functions for constructing the objective function.
- pownet.optim_model.objfunc.get_marginal_cost_coeff(step_k, timesteps, units, nondispatch_contracts, contract_costs)[source]
Generic helper function to calculate coefficients based on marginal cost or a similar attribute for a list of units.
- Parameters:
step_k (
int) – Current step in the simulationtimesteps (
range) – Range of timesteps for the simulationunits (
list) – List of units to calculate coefficients fornondispatch_contracts (
dict) – Dictionary mapping units to their respective contractscontract_costs (
dict) – Dictionary mapping contracts to their respective costs
- Return type:
dict
- Returns
A dictionary mapping (unit, t) tuples to the calculated coefficients
- pownet.optim_model.objfunc.get_thermal_fixed_coeff(timesteps, thermal_units, thermal_fixed_cost, thermal_rated_capacity)[source]
Fixed cost is a function of rated capacity and fixed cost per unit.
- Return type:
dict
pownet.optim_model.rounding_algo module
rounding_algo.py: Functions to perform iterative rounding.
- pownet.optim_model.rounding_algo.check_binary_values(var_dict)[source]
Check if all variables in a dictionary have binary values (0 or 1).
- Parameters:
var_dict (dict) – A dictionary where keys are variable names and values are gurobipy.Var objects.
- Returns:
True if all variables have binary values, False otherwise.
- Return type:
bool
- pownet.optim_model.rounding_algo.fast_rounding(fraction_vars, threshold=0)[source]
- Return type:
None
- pownet.optim_model.rounding_algo.find_fraction_vars(binary_vars, atol=1e-05)[source]
Return a list of variable names when their values are fractional.
- Return type:
dict
- pownet.optim_model.rounding_algo.get_variables(model, target_varnames=None)[source]
Extract non-binary variables from a Gurobi model.
- Parameters:
model (gp.Model) – The Gurobi model to extract variables from.
target_varnames (list[str], optional) – A list of variable name prefixes to include. If None, defaults to [“status”].
- Returns:
- A dictionary mapping variable names to their corresponding
non-binary values (v.X).
- Return type:
dict
- pownet.optim_model.rounding_algo.optimize_with_rounding(model, rounding_strategy, threshold, max_rounding_iter, mipgap, timelimit, num_threads, log_to_console)[source]
Optimize a Gurobi model using iterative rounding with a given threshold.
This function first relaxes the input model and then iteratively rounds fractional variables until an integer solution is found or the maximum number of iterations is reached.
- Parameters:
model (gp.Model) – The Gurobi model to optimize.
threshold (float) – The threshold for rounding fractional variables.
max_rounding_iter (int) – The maximum number of rounding iterations.
log_to_console (bool) – Whether to log optimization output to the console.
mipgap (float) – The relative MIP optimality gap.
timelimit (int) – The time limit for the optimization in seconds.
num_threads (int) – The number of threads to use for optimization.
- Returns:
The optimized Gurobi model.
- Return type:
gp.Model
pownet.optim_model.variable_func module
variable_func.py: Contains functions for adding variables to the optimization model.
- pownet.optim_model.variable_func.add_var_with_variable_ub(model, varname, timesteps, step_k, units, capacity_df)[source]
Add a variable with a variable upper bound in a day-ahead rolling horizon optimization.
- Parameters:
model (gp.Model) – The optimization model.
varname (str) – The name of the variable.
timesteps (range) – The range of timesteps.
step_k (int) – The step index.
units (list) – The list of units.
capacity_df (pd.DataFrame) – The dataframe of capacities.
- Returns:
The variable with a variable upper bound.
- Return type:
gp.tupledict
- pownet.optim_model.variable_func.update_flow_vars(flow_variables, step_k, capacity_df, line_capacity_factor)[source]
Update the lower and upper bounds of the flow variables based on the capacity dataframes
- Return type:
None
- pownet.optim_model.variable_func.update_var_with_variable_ub(variables, step_k, capacity_df)[source]
Update the time-dependent upper bound of the variable.
- Parameters:
variables (gp.tupledict) – The variable with a variable upper bound.
step_k (int) – The step index.
capacity_df (pd.DataFrame) – The dataframe of capacities.
- Return type:
None- Returns:
None
Module contents
The optim_model module provides the core optimization model for power system operations.