monee optimization problem

Problem definitions

class monee.problem.AttributeParameter(min: collections.abc.Callable[[str, float], float], max: collections.abc.Callable[[str, float], float], val: collections.abc.Callable[[str, float], float], integer: bool = False)[source]

Bases: object

integer: bool = False
max: Callable[[str, float], float]
min: Callable[[str, float], float]
val: Callable[[str, float], float]
class monee.problem.Constraints[source]

Bases: object

all(network, period_index=None)[source]
all_temporal(network, temporal_state, period_index=None)[source]
property empty
property has_temporal
regulation_ramp(limit)[source]

Limit per-period change of regulation to limit (skips models without a regulation Var).

select(component_selection_function)[source]
Return type:

monee.problem.core.Constraint

select_grids(grid_cls_tuple)[source]
Return type:

monee.problem.core.Constraint

select_types(model_cls_tuple)[source]
Return type:

monee.problem.core.Constraint

with_models(models)[source]
Return type:

monee.problem.core.Constraint

class monee.problem.GeneralResiliencePerformanceMetric[source]

Bases: PerformanceMetric

calc(network, inv=False, include_ext_grid=True, include_coupling_points=False)[source]
get_coupling_point_components(network: monee.model.network.Network)[source]

All coupling-point components: control-node CPs live as compound subnodes (in network.nodes) and HG-variant CPs live as branches.

get_relevant_components(network: monee.model.network.Network)[source]
class monee.problem.Objectives[source]

Bases: object

all(network, period_index=None)[source]
select(model_selection_function)[source]
Return type:

monee.problem.core.Objective

with_models(models_link)[source]
Return type:

monee.problem.core.Objective

class monee.problem.OptimizationProblem(debug=False, lex_objectives: bool = False)[source]

Bases: object

Declares which components are free variables plus optional objectives/constraints.

Workflow: create → call controllable_* helpers → set objectives and constraints → pass to run_multi_period() / run_mpc().

Parameters:
  • debug – verbose logging during variable promotion.

  • lex_objectives (bool) – Pyomo-only two-phase solve: first user objectives, then formulation-tightening terms (branch/node/child.minimize) with the phase-1 optimum pinned. Removes weight tuning. GEKKO falls back to single-objective sum.

add_to_controllable(model, attributes: list[str | tuple[str, monee.problem.core.AttributeParameter]])[source]
bounds(minmax, component_condition=<function OptimizationProblem.<lambda>>, attributes=None)[source]

Override min/max for Var attributes on matching components. component_condition is (model, grid) -> bool.

property constraints
controllable(attributes: list[str | tuple[str, monee.problem.core.AttributeParameter]], component_condition=<function OptimizationProblem.<lambda>>)[source]

Promote attributes on matching components to free Vars. Low-level primitive; prefer the typed controllable_* helpers. Each attribute entry is a name or (name, AttributeParameter) tuple.

controllable_all(attributes)[source]
controllable_backup_lines()[source]

Add a binary on_off ∈ {0,1} on every branch with backup=True.

controllable_cps(attributes)[source]

Make all coupling-point components (CHP / P2H / G2H / P2G / G2P / their HG variants) controllable on attributes.

controllable_demands(attributes: list[str | tuple[str, monee.problem.core.AttributeParameter]])[source]

Make PowerLoad/HeatLoad/HeatExchangerLoad/PassiveHeatExchangerLoad, gas Sinks, and consuming HeatExchanger/PassiveHeatExchanger controllable.

Note: an attribute currently at 0.0 with no AttributeParameter is locked to [0,0]. Use prob.bounds() or pass an AttributeParameter for real bounds.

controllable_ext()[source]

Declare ExtPowerGrid / ExtHydrGrid connections controllable.

Purely declarative: these models already expose their exchange (p_mw / mass_flow_kgs) as free Vars from their own __init__, so no attribute is (re)bound here (attributes=[]). The call documents intent and registers the components with the controllable set; it does not itself make the ext-grid exchange free.

controllable_generators(attributes)[source]

Make PowerGenerator/HeatGenerator/HeatExchangerGenerator/ PassiveHeatExchangerGenerator/Source controllable. See controllable_demands() for the 0.0-locks-to-[0,0] caveat.

controllable_storages()[source]

Promote dispatch on all storage components via their make_controllable.

property lex_objectives: bool
property objectives
monee.problem.calc_general_resilience_performance(network: monee.model.network.Network, **kwargs)[source]
monee.problem.create_economic_dispatch_problem(gen_cost_default=1.0, ext_grid_cost_default=None, bounds_vm=(0.9, 1.1), bounds_lp=(0, 1.0), ext_grid_bounds=None, ramp_limit=None, check_vm=True, check_lp=True, debug=False)[source]

Economic dispatch OPF minimising Σ cost · p_gen. Set each generator’s cost (currency/MW) directly or per-period via TimeseriesData.add_objective_data.

monee.problem.create_min_load_shedding_problem(*, demand_weight=1000.0, generator_weight=0.1, weight_for_load=None, bounds_vm=(0.9, 1.1), bounds_pressure=(0.9, 1.1), bounds_t=(0.9, 1.1), max_line_loading=1.5, bounds_ext_el=(-3, 3), bounds_ext_gas=(-10, 10), bounds_ext_heat=(-10, 10), regulation_ramp_limit=None, include_storages=False, include_ext_grids=True, include_coupling_points=False, check_vm=True, check_pressure=True, check_t=True, check_lp=True, lex_objectives=False, auto_priority_floor=True, priority_safety_factor=10.0, debug=False)[source]

Create a minimal load-shedding optimisation problem for multi-energy grids.

Each demand/generator/coupling gets a regulation Var ∈ [0,1]; the objective penalises (1-regulation) weighted per category. Gas Sink/Source shed is energy-converted via the enclosing grid’s HHV. External grids contribute only via ext_grid_*_bounds constraints (and an optional quadratic slack nudge to zero exchange when include_ext_grids=True).

lex_objectives (Pyomo only) solves in two phases: shed first, then formulation-tightening aux terms with the phase-1 optimum pinned. auto_priority_floor (default True) scales demand_weight to α · A_max so the shed term dominates aux terms regardless of network size.

include_coupling_points (default False) extends the demand-side of the objective to coupling-point components (CHP / CHPHG / G2H / P2H control nodes and the HG branch variants P2G / G2P / P2H_HG / G2H_HG). Each CP is penalised at demand_weight · cp_input_rated_mw · (1 - regulation) - i.e. treated like a load on its input carrier (gas or power).

monee.problem.create_multi_period_economic_dispatch_problem(gen_cost_default=1.0, ext_grid_cost_default=None, bounds_vm=(0.9, 1.1), bounds_lp=(0, 1.0), ext_grid_bounds=None, ramp_limit=None, check_vm=True, check_lp=True, debug=False)[source]

Alias for create_economic_dispatch_problem() (mirrors load_shedding naming).

Utilities

Shared constraint helpers used by the problem factories.

Cross-cutting helpers used by load-shedding / dispatch problems.

monee.problem.utils.cp_input_rated_mw(component)[source]

Return (carrier, rated_input_mw) for a coupling-point component or None if component is not a coupling point.

carrier is 'gas' or 'power' (the carrier the CP draws from). rated_input_mw is the nameplate input the CP consumes at regulation 1.0. Used both by the resilience metric (to account CP curtailment) and by min_load_shedding (to treat CPs as additional loads in the objective).

monee.problem.utils.line_loading_limit(branch_model, side: str, max_loading: float)[source]

LP-writable line-loading constraint.

AC: loading_*_percent max. MISOCP: emit current_pu_squared · scale² max² using the formulation-stashed _misocp_loading_*_scale_squared (the sqrt form is LP-incompatible).

Metrics

Post-solve performance and resilience metrics.

class monee.problem.metric.GeneralResiliencePerformanceMetric[source]

Bases: PerformanceMetric

calc(network, inv=False, include_ext_grid=True, include_coupling_points=False)[source]
get_coupling_point_components(network: monee.model.network.Network)[source]

All coupling-point components: control-node CPs live as compound subnodes (in network.nodes) and HG-variant CPs live as branches.

get_relevant_components(network: monee.model.network.Network)[source]
class monee.problem.metric.PerformanceMetric[source]

Bases: ABC

abstractmethod calc(network: monee.model.network.Network)[source]
class monee.problem.metric.ResilienceMetric[source]

Bases: ABC

abstractmethod calc()[source]
abstractmethod gather(network: monee.model.network.Network, step, **kwargs)[source]
monee.problem.metric.is_load(component)[source]