pownet.optim_model package

Subpackages

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

check_feasible()[source]
Return type:

bool

get_model()[source]
get_objval()[source]
Return type:

float

get_runtime()[source]
Return type:

float

get_runtime_gurobi()[source]
Return type:

float

get_runtime_highs()[source]
Return type:

float

get_solution()[source]
Return type:

DataFrame

get_solution_gurobi()[source]
Return type:

dict

get_solution_highs()[source]
Return type:

dict

get_status()[source]
optimize(solver='gurobi', log_to_console=True, mipgap=0.001, timelimit=600, num_threads=0)[source]
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

print_added_constraints()[source]
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

solve_for_lmp()[source]
Return type:

dict

solve_for_lmp_gurobi()[source]

Return the locational marginal price (LMP).

Parameters:

model – The Gurobi model.

Return type:

dict

Returns:

The LMP at each node.

solve_for_lmp_highs()[source]
Return type:

dict

write_ilp_mps(output_folder, instance_name)[source]
write_mps(output_folder, filename)[source]

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 simulation

  • timesteps (range) – Range of timesteps for the simulation

  • units (list) – List of units to calculate coefficients for

  • nondispatch_contracts (dict) – Dictionary mapping units to their respective contracts

  • contract_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.objfunc.get_thermal_opex_coeff(step_k, timesteps, thermal_units, thermal_opex, fuel_contracts, contract_costs, thermal_heat_rate)[source]

Variable cost is a function of fuel cost, heat rate, and opex.

Return type:

dict

pownet.optim_model.objfunc.get_thermal_startup_coeff(timesteps, thermal_units, thermal_startup_cost, thermal_rated_capacity)[source]

Startup cost is a function of rated capacity and startup 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.rounding_algo.round_down(variable)[source]
Return type:

None

pownet.optim_model.rounding_algo.round_up(variable)[source]
Return type:

None

pownet.optim_model.rounding_algo.slow_rounding(fraction_vars, threshold=0)[source]

Iteratively rounding variables with the largest value at each iteration. Values above the threshold are rounded up. Values below the threshold are rounded down.

Return type:

None

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.