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
- class monee.problem.Constraints[source]¶
Bases:
object- property empty¶
- property has_temporal¶
- class monee.problem.GeneralResiliencePerformanceMetric[source]¶
Bases:
PerformanceMetric- 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.OptimizationProblem(debug=False, lex_objectives: bool = False)[source]¶
Bases:
objectDeclares which components are free variables plus optional objectives/constraints.
Workflow: create → call
controllable_*helpers → setobjectivesandconstraints→ pass torun_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
Varattributes on matching components.component_conditionis(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_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 controllables_link¶
- 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’scost(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 viaext_grid_*_boundsconstraints (and an optional quadratic slack nudge to zero exchange wheninclude_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) scalesdemand_weighttoα · A_maxso 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 atdemand_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 orNoneif component is not a coupling point.carrieris'gas'or'power'(the carrier the CP draws from).rated_input_mwis the nameplate input the CP consumes at regulation 1.0. Used both by the resilience metric (to account CP curtailment) and bymin_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: emitcurrent_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]