monee models¶
monee base models for model creation¶
- class monee.model.Branch(model, from_node_id, to_node_id, formulation=None, constraints=None, grid=None, name=None, active=True, independent=True)[source]¶
Bases:
ComponentNo docstring provided.
- property tid¶
No docstring provided.
- class monee.model.BranchModel(**kwargs)[source]¶
Bases:
GenericModelAbstract base class for network branch models, defining the interface for branch-specific equations, loss calculation, and initialization.
BranchModel provides a common foundation for implementing custom branch types (such as power lines or pipes) in network simulations. Subclasses must implement the abstract equations method to define the physical relationships for the branch. Optional methods such as loss_percent, is_cp, and init can be overridden to customize loss calculations, control point designation, and initialization logic. This class inherits from GenericModel and is intended for use within extensible, multi-domain network modeling frameworks.
- equations(grid, from_node_model, to_node_model, ``**kwargs``)[source]¶
Abstract. Must be implemented by subclasses to define branch equations.
Example:
class MyCustomBranch(BranchModel): def equations(self, grid, from_node_model, to_node_model, **kwargs): # Implement branch-specific equations pass def loss_percent(self): # Custom loss calculation return compute_actual_loss(self) def is_cp(self): # Mark this branch as a control point return True def init(self, grid): # Custom initialization logic pass
- abstractmethod equations(grid, from_node_model, to_node_model, **kwargs)[source]¶
No docstring provided.
- is_cp()[source]¶
Indicates whether the branch model represents a control point (CP) in the network.
This method is used to determine if the current branch model instance should be treated as a control point, which may affect optimization or control strategies in network simulations. By default, this implementation always returns False, meaning the branch is not a control point. Override this method in subclasses if specific branch types should be considered as control points.
- Returns:
False, indicating the branch model is not a control point by default.
- Return type:
Examples
- Check if a branch model is a control point:
- if branch_model.is_cp():
# Apply control logic …
- loss_percent()[source]¶
Returns the percentage of losses for the branch model, defaulting to zero.
This method provides a placeholder for calculating the loss percentage associated with a branch in the network, such as power or heat losses. By default, it returns 0, indicating no losses are considered. Override this method in subclasses to implement specific loss calculations relevant to the branch type.
- Returns:
Always returns 0, representing zero loss percentage by default.
- Return type:
Examples
# In a custom branch model, override to provide actual loss calculation class MyBranchModel(BranchModel): def loss_percent(self): return compute_actual_loss(self)
In base usage:
loss = branch_model.loss_percent() # Returns 0 unless overridden
- class monee.model.Bus(base_kv)[source]¶
Bases:
NodeModelNo docstring provided.
- calc_signed_power_values(from_branch_models, to_branch_models, connected_node_models)[source]¶
No docstring provided.
- class monee.model.CHP(diameter_m: float, efficiency_power: float, efficiency_heat: float, mass_flow_setpoint: float, q_mvar_setpoint: float = 0, temperature_ext_k: float = 293, regulation=1)[source]¶
Bases:
MultiGridCompoundModelNo docstring provided.
- create(network: monee.model.network.Network, gas_node: monee.model.core.Node, heat_node: monee.model.core.Node, heat_return_node: monee.model.core.Node, power_node: monee.model.core.Node)[source]¶
No docstring provided.
- class monee.model.CHPControlNode(mass_flow_capacity, efficiency_power, efficiency_heat, hhv, q_mvar=0, regulation=1, **kwargs)[source]¶
Bases:
MultiGridNodeModel,Junction,BusRepresents a control node for combined heat and power (CHP) systems, managing energy and mass balances across power, heat, and gas domains.
CHPControlNode extends MultiGridNodeModel, Junction, and Bus to provide a unified interface for modeling the operational logic and constraints of a CHP unit within a multi-energy network. It tracks key parameters such as fuel mass flow, electrical and thermal efficiencies, and regulation factors, and exposes variables for integration with network branches. Use this class when simulating or optimizing CHP systems that require explicit coupling between gas, heat, and electrical grids.
Example:
chp_node = CHPControlNode( mass_flow_capacity=1.2, efficiency_power=0.35, efficiency_heat=0.5, hhv=42.5e6, q_mvar=0, regulation=1 ) # Integrate chp_node into a network and call chp_node.equations(...) during simulation
- Parameters:
mass_flow_capacity – Maximum or setpoint mass flow of fuel (e.g., gas) supplied to the CHP unit.
efficiency_power – Electrical efficiency (fraction, 0 < value ≤ 1).
efficiency_heat – Thermal efficiency (fraction, 0 < value ≤ 1).
hhv – Higher heating value of the fuel (J/kg).
q_mvar (optional) – Reactive power setpoint for the generator. Defaults to 0.
regulation (optional) – Regulation factor for operational flexibility. Defaults to 1.
**kwargs – Additional keyword arguments for parent class initialization.
- mass_flow_capacity¶
Fuel mass flow capacity or setpoint.
- efficiency_power¶
Electrical efficiency.
- efficiency_heat¶
Thermal efficiency.
- gen_q_mvar¶
Reactive power setpoint.
- _hhv¶
Higher heating value of the fuel.
- regulation¶
Regulation factor.
- _gen_p_mw¶
Electrical power generation variable.
- heat_gen_w¶
Thermal power generation variable.
- el_gen_mw¶
Electrical power generation variable (duplicate for unified interface).
- el_mw¶
Unified electrical power variable.
- gas_kgps¶
Unified gas mass flow variable.
- heat_w¶
Unified heat power variable.
- t_k¶
Node temperature (K).
- t_pu¶
Node temperature (per unit).
- pressure_pa¶
Node pressure (Pa).
- pressure_pu¶
Node pressure (per unit).
- equations(grid, from_branch_models, to_branch_models, childs, **kwargs)[source]¶
Defines the system of equations for the CHP node, including mass and energy balances, power and heat conversion, and normalization constraints.
- equations(grid, from_branch_models, to_branch_models, childs, **kwargs)[source]¶
Defines the system of equations for a combined heat and power (CHP) control node, capturing energy and mass balances across power, heat, and gas domains.
This method assembles the physical and operational constraints for a CHP node, including mass flow balances for heat and gas, power balance equations, and thermodynamic relationships for energy conversion. It integrates the effects of efficiency, regulation, and fuel properties, and links the node’s internal variables to the connected branches. Use this method during network simulation or optimization to ensure the CHP node’s behavior is accurately represented within the multi-energy system.
- Parameters:
grid – List or collection of grid objects, where grid[1] is expected to be the heat grid for reference values.
from_branch_models (list) – Branch models representing flows entering the node.
to_branch_models (list) – Branch models representing flows leaving the node.
childs (list) – Child component models attached to the node.
**kwargs – Additional keyword arguments for solver options or equation customization.
- Returns:
A tuple of equations representing:
Heat mass flow balance at the node.
Heat energy flow balance at the node.
Gas mass flow balance at the node.
Power balance equations (active and reactive).
Heat exchanger energy conversion constraint.
Electrical power generation constraint.
Consistency between internal heat and electrical variables and branch flows.
Temperature and pressure normalization constraints.
- Return type:
- Raises:
IndexError – If no SubHE branch is found in the heat_from_branches list.
KeyError – If expected variables are missing from branch models.
Examples
# Called automatically during network simulation: eqs = chp_control_node.equations(grid, from_branches, to_branches, childs)
- class monee.model.Child(child_id, model, formulation=None, constraints=None, grid=None, name=None, active=True, independent=True)[source]¶
Bases:
ComponentNo docstring provided.
- class monee.model.ChildModel(regulation: float = 1.0, **kwargs)[source]¶
Bases:
GenericModelBase class for leaf components attached to a single node (loads, generators, ext-grids).
Sign convention — the internal representation follows the load convention:
Positive values represent consumption (load, sink).
Negative values represent generation (injection, source).
Concrete subclasses such as
PowerGeneratorandSourcenegate the user-supplied magnitude in__init__so that the public API always accepts positive numbers for generators:PowerGenerator(p_mw=5) → self.p_mw = -5 (injecting 5 MW) PowerLoad(p_mw=5) → self.p_mw = +5 (consuming 5 MW)
- Parameters:
regulation (float) – Scaling factor applied to the component’s setpoint, in the range
[0.0, 1.0]. A value of1.0(default) means full output/consumption;0.0effectively disables the component. The factor is used by multi-energy coupling components (P2H, CHP, …) to model partial dispatch.**kwargs – Forwarded to
GenericModel.
- minimize(grid, node_model, **kwargs)[source]¶
Minimization of an expression as minimization may necessary due to some formulation (when replacing constraints with slack variables)
- Parameters:
self – Description
- overwrite(node_model, grid)[source]¶
Pin node variables to fixed setpoints (optional).
Override this method in grid-forming components (e.g.
ExtPowerGrid) to replace free nodeVarinstances withConstvalues before the solver runs. The default implementation is a no-op.- Parameters:
node_model – The node model the child is attached to.
grid – The grid domain of the node.
- class monee.model.Component(id, model, formulation=None, constraints=None, grid=None, name=None, active=True, independent=True)[source]¶
Bases:
ABCNo docstring provided.
- property formulation¶
- property nid¶
No docstring provided.
- property tid¶
No docstring provided.
- class monee.model.Compound(compound_id, model: monee.model.core.CompoundModel, connected_to, subcomponents, formulation=None, constraints=None, grid=None, name=None, active=True)[source]¶
Bases:
ComponentNo docstring provided.
- class monee.model.CompoundModel(**kwargs)[source]¶
Bases:
GenericModelBase class for composite components that span multiple nodes and/or carriers.
A
CompoundModelgroups several sub-components (internal branches, child attachments, etc.) into a single logical unit — for example a P2H unit that internally creates a water pipe and couples it to an electricity bus.Subclasses must implement
create(), which receives the network and is expected to add the required sub-components. Optionally overrideequations()to add coupling constraints between the sub-components’ variables, andminimize()to contribute objective terms.- abstractmethod create(network)[source]¶
Materialise the compound’s sub-components in network.
Called once when the compound is added to the network. Implementations should call
network.node(),network.branch(),network.child_to()etc. to create internal topology.- Parameters:
network – The
Networkthe compound belongs to.
- equations(network, **kwargs)[source]¶
Return coupling constraints between sub-component variables.
Override this method to add equations that link variables across the compound’s internal sub-components (e.g. energy-balance between the electrical and hydraulic side of a P2H unit). Returns an empty list by default.
- class monee.model.Const(value)[source]¶
Bases:
objectA fixed (non-optimised) constant that participates in the model attribute protocol.
Use
Constwhen a value must be readable byvalue()but should never be turned into a solver decision variable. The primary use-case is insideoverwrite()implementations, where a child component pins a node variable to a fixed setpoint:node_model.vm_pu = Const(1.02) # fixed voltage — not a free variable
- Parameters:
value – The fixed scalar value.
- class monee.model.ConsumeHydrGrid(mass_flow=0.1, pressure_pu=1, t_k=293, **kwargs)[source]¶
Bases:
NoVarChildModelHydraulic demand point (consumption) for gas or water networks.
Represents a fixed-pressure offtake point (e.g. a building substation or a gas consumer). Pins the junction pressure to a setpoint and applies a fixed mass-flow consumption.
Follows the load convention: internally stores a negative mass-flow so that the junction balance treats it as withdrawal. The constructor accepts positive magnitudes and negates them:
ConsumeHydrGrid(mass_flow=0.5) → self.mass_flow = -0.5
- Parameters:
- class monee.model.ElectricityIslandingMode(angle_bound: float = 3.15, big_m_conn: int = 200)[source]¶
Bases:
IslandingModeIslanding configuration for the electricity carrier.
Adds: * Single-commodity connectivity-flow constraints (via the base class). *
source_reference_angleat every grid-forming bus → θ = 0. *angle_{upper,lower}_bound_energizedat every regular bus →forces θ = 0 when
e_i = 0(de-energised).- Parameters:
- add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]¶
Electricity-specific physical constraint equations (returned as a list).
Grid-forming nodes: angle reference = 0 (
source_reference_anglefrom dc.py).Regular nodes: angle bounds conditional on energisation.
- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Phase 1 — add electricity islanding Var placeholders.
- Return type:
- class monee.model.ExtHydrGrid(mass_flow=-1, pressure_pu=1, t_k=356, **kwargs)[source]¶
Bases:
NoVarChildModel,GridFormingMixinExternal hydraulic grid (slack source) — the pressure/temperature reference for a gas or water island.
ExtHydrGridpins the junction pressure and temperature to fixed setpoints (viaoverwrite()) and exposesmass_flowas a freeVardecision variable that absorbs the island’s flow imbalance.Follows the load convention: the default
mass_flow=-1represents injection (negative = generation/source). The solver determines the actual mass flow.- Parameters:
- class monee.model.ExtPowerGrid(p_mw, q_mvar, vm_pu=1, va_degree=0, **kwargs)[source]¶
Bases:
NoVarChildModel,GridFormingMixinExternal (slack) power grid connection — the reference bus for an electrical island.
ExtPowerGridpins the bus voltage magnitude and angle to fixed setpoints (viaoverwrite()) and exposesp_mw/q_mvaras freeVardecision variables that absorb the island’s power imbalance.Follows the load convention: positive
p_mw/q_mvarat the node represents net import from the external grid (consumption perspective). Thep_mw/q_mvarinitial values are starting guesses; the solver determines the final values.- Parameters:
- class monee.model.GasGrid(name: str, compressibility: float, molar_mass: float, gas_temperature: float, dynamic_visc: float, higher_heating_value: float, universal_gas_constant: float, t_k: float, t_ref: float, pressure_ref: float, nominal_pressure_pu: float, f_max: float, p_squared_pu_max: float, p_squared_pu_min: float)[source]¶
Bases:
GridRepresents a gas grid domain within a multi-energy network model, encapsulating physical and thermodynamic properties of the gas system.
GasGrid extends the base Grid class to provide attributes and parameters specific to gas networks, such as compressibility, molar mass, temperature, and reference pressures. Use this class to model gas infrastructure, perform flow calculations, or integrate gas dynamics into multi-domain simulations. It is typically instantiated as part of a larger network model where gas transport, conversion, or coupling with other energy domains is required.
Example
gas_grid = GasGrid() gas_grid.compressibility = 0.98 gas_grid.molar_mass = 0.016 gas_grid.gas_temperature = 293.15 # … set other properties as needed
- class monee.model.GasIslandingMode(big_m_conn: int = 200)[source]¶
Bases:
IslandingModeIslanding configuration for the gas carrier.
Adds: * Single-commodity connectivity-flow constraints (via the base class). * Pressure bounds conditional on energisation for regular junctions:
pressure_pu ≤ p_max · e_iso that de-energised junctions have pressure = 0.The pressure at grid-forming junctions is already pinned by
GridFormingSource.overwrite()(orExtHydrGrid.overwrite()), so no additional pinning is needed for GF nodes in this method.- Parameters:
big_m_conn (int) – Big-M for connectivity-flow arc capacity. Must be ≥ number of carrier nodes.
- add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]¶
Gas-specific physical constraint equations (returned as a list).
Force
pressure_pu = 0for de-energised junctions via an upper bound that is conditional one_i.- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Phase 1 — add gas islanding Var placeholders.
- Return type:
- class monee.model.GasPipe(diameter_m, length_m, temperature_ext_k=296.15, roughness=0.0001, on_off=1, friction=None)[source]¶
Bases:
BranchModelNo docstring provided.
- equations(grid: monee.model.grid.GasGrid, from_node_model, to_node_model, **kwargs)[source]¶
No docstring provided.
- class monee.model.GasToHeat(heat_energy_w, diameter_m, temperature_ext_k, efficiency)[source]¶
Bases:
MultiGridCompoundModelNo docstring provided.
- create(network: monee.model.network.Network, gas_node: monee.model.core.Node, heat_node: monee.model.core.Node, heat_return_node: monee.model.core.Node)[source]¶
No docstring provided.
- class monee.model.GasToHeatControlNode(heat_gen_w, efficiency_heat, hhv, regulation=1, **kwargs)[source]¶
Bases:
MultiGridNodeModel,JunctionNo docstring provided.
- class monee.model.GasToPower(efficiency, p_mw_setpoint, q_mvar_setpoint=0, regulation=1)[source]¶
Bases:
MultiGridBranchModelNo docstring provided.
- class monee.model.GenericModel(**kwargs)[source]¶
Bases:
ABCBase class for all component models (nodes, branches, children, compounds).
Provides the
varsandvaluesintrospection properties that the solver backends use to discover and inject decision variables. Any attribute whose name does not start with_is considered part of the model’s public state and will be included invars/valuesand in the result DataFrames.Subclasses should store parameters and decision variables as plain Python attributes in
__init__. UseVarfor decision variables,Constfor fixed setpoints that must participate in the attribute protocol, and plain scalars for parameters that never enter the solver.Extra keyword arguments passed to
__init__are stored in_ext_dataand ignored by the solver.- property values¶
All public attributes with
Var/Const/Intermediateunwrapped to scalars.
- property vars¶
All public attributes as a
{name: value}dict (includesVar,Const, scalars).
- class monee.model.GenericPowerBranch(tap, shift, br_r, br_x, g_fr, b_fr, g_to, b_to, max_i_ka=3.19, backup=False, on_off=1, **kwargs)[source]¶
Bases:
BranchModelNo docstring provided.
_summary_
- Parameters:
tap (_type_) – _description_
shift (_type_) – _description_
br_r (_type_) – resistence
br_x (_type_) – reactance
g_fr (_type_) – from conductance
b_fr (_type_) – from susceptance
g_to (_type_) – to conductance
b_to (_type_) – to susceptance
- equations(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model, **kwargs)[source]¶
No docstring provided.
- property loading_percent¶
No docstring provided.
- class monee.model.GenericTransferBranch(loss=0, **kwargs)[source]¶
Bases:
MultiGridBranchModelNo docstring provided.
- equations(grids, from_node_model, to_node_model, **kwargs)[source]¶
Defines the system of equations for a multi-grid branch, relating variables across multiple grids and connected nodes.
This abstract method must be implemented by subclasses to specify the physical or operational relationships governing the branch’s behavior in a multi-grid context (e.g., coupling between electrical, gas, and heat networks). Use this method when modeling branches that interact with more than one grid domain. The method is typically called during network simulation or optimization to assemble the overall system equations.
- Parameters:
grids (dict) – Dictionary of grid objects involved in the branch (e.g., {‘el’: el_grid, ‘gas’: gas_grid}).
from_node_model – Model instance representing the source node connected to the branch.
to_node_model – Model instance representing the destination node connected to the branch.
**kwargs – Additional keyword arguments for solver options or equation customization.
- Returns:
The equations or constraints representing the branch’s behavior. The return type and structure depend on the modeling framework and implementation.
- Return type:
Any
- Raises:
NotImplementedError – If not implemented in a subclass.
Examples
class MyMultiGridBranch(MultiGridBranchModel): def equations(self, grids, from_node_model, to_node_model, **kwargs): # Define equations coupling electrical and gas flows return [eq1, eq2, eq3]
- class monee.model.Grid(name: str)[source]¶
Bases:
objectRepresents a resource grid or domain within a multi-energy network model.
The Grid class serves as an abstract base or marker for specific grid types, such as electrical, gas, or heat grids. It provides a common interface for identifying and managing different resource domains in network simulations or optimization frameworks. Use this class as a foundation for implementing grid-specific logic, attributes, or methods.
Example
- class ElectricalGrid(Grid):
- def __init__(self):
self.name = “el”
grid = ElectricalGrid() print(grid.name) # Output: “el”
- class monee.model.GridFormingGenerator(p_mw_max: float, q_mvar_max: float, vm_pu: float = 1.0, **kwargs)[source]¶
Bases:
NoVarChildModel,GridFormingMixinGrid-forming generator for islanded electricity networks.
Acts as the slack bus of its island: variable active/reactive power output (absorbs the island’s power imbalance) with a fixed voltage magnitude setpoint.
Unlike
PowerGenerator(which has fixed p/q), this component has variablep_mwandq_mvarso that it can balance any generation–load mismatch in its island. The voltage angle is not pinned here; instead, theElectricityIslandingModeformulation pins the angle to 0 viasource_reference_anglefromdc.py.- Parameters:
p_mw_max (float) – Maximum active power injection (and absorption) in MW.
q_mvar_max (float) – Maximum reactive power injection (and absorption) in Mvar.
vm_pu (float) – Voltage magnitude setpoint in per-unit. The
overwrite()method pinsnode_model.vm_puto this constant, making this bus a PV/slack bus.
- class monee.model.GridFormingMixin[source]¶
Bases:
objectMarker mixin: this child component can serve as the reference node (slack bus / pressure reference) for an islanded sub-network.
Any child class that carries this mixin must implement
overwrite()to pin the carrier-specific reference variable (voltage angle, pressure, …) on the node model it is attached to. When islanding is enabled,find_ignored_nodestreats components that contain aGridFormingMixinchild as “leading” and keeps them in the solve.
- class monee.model.GridFormingSource(pressure_pu: float = 1.0, t_k: float = 356.0, mass_flow_max: float = 1000000.0)[source]¶
Bases:
ChildModel,GridFormingMixinGrid-forming source for islanded gas or water networks.
Acts as the pressure reference of its island: the node’s pressure is pinned to
pressure_puviaoverwrite(), and the source’smass_flowis a variable so it can absorb any supply–demand imbalance in the island.- Parameters:
- class monee.model.HeatExchanger(q_mw, diameter_m, roughness=0.0001, length_m=2.5, temperature_ext_k=293, regulation=1, friction=None)[source]¶
Bases:
BranchModelNo docstring provided.
- equations(grid: monee.model.grid.WaterGrid, from_node_model, to_node_model, **kwargs)[source]¶
No docstring provided.
- class monee.model.HeatExchangerGenerator(q_mw, diameter_m, temperature_ext_k=293)[source]¶
Bases:
HeatExchangerNo docstring provided.
- class monee.model.HeatExchangerLoad(q_mw, diameter_m, temperature_ext_k=293)[source]¶
Bases:
HeatExchangerNo docstring provided.
- class monee.model.Intermediate(value=0)[source]¶
Bases:
objectA placeholder for a computed (derived) quantity that is not itself a decision variable.
The solver backend evaluates
IntermediateEqexpressions and writes the result back to the correspondingIntermediate.valueafter each solve. Use this when you want a model attribute to hold a derived quantity (e.g. a line loading percentage) that can be read from results but is not an independent variable in the optimisation.- Parameters:
value – Initial/default value before the first solve.
- class monee.model.IntermediateEq(attr, eq)[source]¶
Bases:
objectDeclares how to compute an
Intermediateattribute from other variables.Return an
IntermediateEqfrom a model’sequations()method to register a derived quantity. The solver extracts it from the equation list, evaluates the expression, and stores the result on the model attribute named by attr:class MyBranch(BranchModel): def __init__(self): self.loading_percent = Intermediate() def equations(self, grid, from_node, to_node, **kwargs): return [ ..., # regular constraints IntermediateEq("loading_percent", self.i_from_ka / self.max_i_ka * 100), ]
- Parameters:
attr – Name of the
Intermediateattribute on the model.eq – The expression (solver-native or Python numeric) to evaluate.
- class monee.model.IslandingMode[source]¶
Bases:
NetworkConstraint,ABCPer-carrier islanding configuration.
Subclasses must set the class attributes
carrier_grid_typeandvar_prefix, and may overrideadd_physical_constraintsto add carrier-specific constraints (e.g. angle pinning for DC electricity, pressure bounds for gas/water).Implements
NetworkConstraint: -prepare(network)→ Phase 1: adds Var placeholders. -equations(network, ignored)→ Phase 2: returns constraint list.- add_physical_constraints(*_)[source]¶
Carrier-specific physical constraints (returned as a plain list).
Override in subclasses to add e.g. angle pinning for electricity or pressure bounds for gas/water. The default returns an empty list.
- Return type:
- equations(network: monee.model.network.Network, ignored_nodes: set)[source]¶
Phase 2 — return all islanding constraint equations as a plain list.
Combines connectivity-flow constraints with carrier-specific physical constraints from
add_physical_constraints.- Return type:
- is_grid_forming(child)[source]¶
Return True if child anchors an island for this carrier.
- Return type:
- abstractmethod prepare(network: monee.model.network.Network)[source]¶
Phase 1 — add
Varplaceholders to node and branch models before solver variable injection.The normal
inject_gekko_vars/inject_pyomo_varsloops pick up theseVarobjects automatically. Each subclass sets its attributes directly, e.g.node.model.e_el = Var(...).- Return type:
- class monee.model.Junction[source]¶
Bases:
NodeModelNo docstring provided.
- calc_signed_heat_flow(from_branch_models, to_branch_models, connected_node_models, grid)[source]¶
No docstring provided.
- class monee.model.MultiGridBranchModel(**kwargs)[source]¶
Bases:
BranchModelAbstract base class for branch models that couple multiple grid domains, such as electrical, gas, and heat networks.
This class extends BranchModel to support branches that interact with more than one grid type, enabling the modeling of multi-energy systems and sector coupling. Subclasses must implement the abstract equations method to define the physical or operational relationships across the involved grids. The is_cp method returns True by default, indicating that multi-grid branches are treated as control points in the network. The init method can be overridden to perform any setup or pre-processing required for multi-grid branches.
- equations(grids, from_node_model, to_node_model, ``**kwargs``)[source]¶
Abstract. Must be implemented by subclasses to define the system of equations for the multi-grid branch.
Example:
class MyMultiGridBranch(MultiGridBranchModel): def equations(self, grids, from_node_model, to_node_model, **kwargs): # Define equations coupling electrical and gas flows return [eq1, eq2, eq3] def init(self, grids): self.el_grid = grids['el'] self.gas_grid = grids['gas']
- abstractmethod equations(grids, from_node_model, to_node_model, **kwargs)[source]¶
Defines the system of equations for a multi-grid branch, relating variables across multiple grids and connected nodes.
This abstract method must be implemented by subclasses to specify the physical or operational relationships governing the branch’s behavior in a multi-grid context (e.g., coupling between electrical, gas, and heat networks). Use this method when modeling branches that interact with more than one grid domain. The method is typically called during network simulation or optimization to assemble the overall system equations.
- Parameters:
grids (dict) – Dictionary of grid objects involved in the branch (e.g., {‘el’: el_grid, ‘gas’: gas_grid}).
from_node_model – Model instance representing the source node connected to the branch.
to_node_model – Model instance representing the destination node connected to the branch.
**kwargs – Additional keyword arguments for solver options or equation customization.
- Returns:
The equations or constraints representing the branch’s behavior. The return type and structure depend on the modeling framework and implementation.
- Return type:
Any
- Raises:
NotImplementedError – If not implemented in a subclass.
Examples
class MyMultiGridBranch(MultiGridBranchModel): def equations(self, grids, from_node_model, to_node_model, **kwargs): # Define equations coupling electrical and gas flows return [eq1, eq2, eq3]
- init(grids)[source]¶
Initializes the multi-grid branch model with the provided grid objects.
This method is intended to perform any setup or pre-processing required before the branch is used in simulation or optimization, such as caching grid parameters or establishing references to grid-specific data. Override this method in subclasses to implement custom initialization logic for multi-grid branches. It is typically called once during network assembly or before equation evaluation.
- Parameters:
grids (dict) – Dictionary of grid objects relevant to the branch (e.g., {‘el’: el_grid, ‘gas’: gas_grid}).
- Returns:
None
Examples
- class MyMultiGridBranch(MultiGridBranchModel):
- def init(self, grids):
self.el_grid = grids[‘el’] self.gas_grid = grids[‘gas’]
- is_cp()[source]¶
Indicates that the multi-grid branch model is a control point (CP) in the network.
This method returns True to signal that this branch should be treated as a control point, which may affect optimization, control strategies, or system observability in multi-grid network simulations. Override this method in subclasses if a different control point designation is required.
- Returns:
Always returns True, indicating the branch is a control point.
- Return type:
Examples
- if branch_model.is_cp():
# Apply control logic specific to control points …
- class monee.model.MultiGridCompoundModel(**kwargs)[source]¶
Bases:
CompoundModelNo docstring provided.
- class monee.model.Network(active_grid=None, el_model=None, water_model=None, gas_model=None)[source]¶
Bases:
objectNo docstring provided.
- add_extension(ext: monee.model.formulation.core.NetworkConstraint)[source]¶
Register a NetworkConstraint extension on this network.
- Return type:
- apply_formulation(network_formulation: monee.model.formulation.core.NetworkFormulation)[source]¶
- branch(model, from_node_id, to_node_id, formulation=None, constraints=None, grid=None, name=None, auto_node_creator=None, auto_grid_key=None, **kwargs)[source]¶
No docstring provided.
- child(model, attach_to_node_id=None, formulation=None, constraints=None, overwrite_id=None, name=None, auto_node_creator=None, auto_grid_key=None)[source]¶
No docstring provided.
- child_to(model, node_id, formulation=None, constraints=None, overwrite_id=None, name=None, auto_node_creator=None, auto_grid_key=None)[source]¶
No docstring provided.
- compound(model: monee.model.core.CompoundModel, formulation=None, constraints=None, overwrite_id=None, **connected_node_ids)[source]¶
No docstring provided.
- property constraints¶
No docstring provided.
- property cps: list[GenericModel]¶
No docstring provided.
- property extensions: list[NetworkConstraint]¶
Solver-agnostic network-level constraint extensions.
- property graph¶
No docstring provided.
- property grids¶
No docstring provided.
- node(model, grid=None, formulation=None, child_ids=None, constraints=None, overwrite_id=None, name=None, position=None)[source]¶
- property objectives¶
No docstring provided.
- class monee.model.NetworkIslandingConfig(electricity: monee.model.islanding.core.IslandingMode | None = None, gas: monee.model.islanding.core.IslandingMode | None = None, water: monee.model.islanding.core.IslandingMode | None = None)[source]¶
Bases:
NetworkConstraintContainer bundling per-carrier
IslandingModeinstances.Register on a network via
network.add_extension(config), or use the top-levelenable_islanding()helper which also setsnetwork.islanding_configforfind_ignored_nodescompatibility.- equations(network: monee.model.network.Network, ignored_nodes: set)[source]¶
Phase 2: return equations for all active carrier modes.
- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Phase 1: add Var placeholders for all active carrier modes.
- Return type:
- class monee.model.Node(node_id, model, child_ids=None, formulation=None, constraints=None, grid=None, name=None, position=None, active=True, independent=True)[source]¶
Bases:
ComponentRepresents a node in the network, managing connectivity, child components, and node-specific attributes.
The Node class extends Component to provide functionality for managing network nodes, including tracking incoming and outgoing branches, associated child components, and node-specific constraints or metadata. Nodes serve as connection points for branches and can represent buses, junctions, or other network entities. Use this class when constructing or modifying network topologies, performing connectivity analysis, or managing nodal attributes in simulation workflows.
Example
node = Node(node_id=1, model=my_node_model, position=(10, 20)) node.add_from_branch_id((2, 1, 0)) node.add_to_branch_id((1, 3, 0)) node.remove_branch((2, 1, 0))
- Parameters:
node_id – Unique identifier for the node.
model – The node’s associated model object.
child_ids (list, optional) – List of child component IDs attached to the node.
constraints (list, optional) – List of operational constraints for the node.
grid (optional) – The grid or domain to which the node belongs.
name (str, optional) – Human-readable name for the node.
position (optional) – Geographical or logical position of the node.
active (bool, optional) – Whether the node is active in the network. Defaults to True.
independent (bool, optional) – Whether the node is independent in the network. Defaults to True.
- position¶
Geographical or logical position of the node.
- remove_branch(branch_id)[source]¶
Removes both a branch and its reversed counterpart from the node’s branch lists.
- add_from_branch_id(branch_id)[source]¶
Adds a branch identifier to the list of incoming branches for the node.
Use this method to register a new incoming branch connection to the node, typically during network construction or when dynamically modifying the network topology. This ensures that the node maintains an accurate record of all branches entering it, which is essential for connectivity management and nodal analysis.
- Parameters:
branch_id – The identifier of the branch to add as an incoming connection. Must be a hashable object representing the branch.
- Returns:
None
Examples
node.add_from_branch_id((1, 2, 0)) # Registers branch (1, 2, 0) as incoming to the node.
- add_to_branch_id(branch_id)[source]¶
Adds a branch identifier to the list of outgoing branches for the node.
This method is used to register a new outgoing branch connection from the node, typically during network construction or when updating the network topology. Maintaining an accurate list of outgoing branches is essential for connectivity management, nodal analysis, and network traversal algorithms.
- Parameters:
branch_id – The identifier of the branch to add as an outgoing connection. Should be a hashable object representing the branch.
- Returns:
None
Examples
node.add_to_branch_id((2, 3, 1)) # Registers branch (2, 3, 1) as outgoing from the node.
- remove_branch(branch_id)[source]¶
Removes a branch identifier and its reversed counterpart from the node’s branch lists.
This method updates the node’s connectivity by removing both the specified branch ID and its reversed form (with the from/to nodes swapped) from the incoming and outgoing branch lists. Use this method when deleting a branch or reconfiguring the network to ensure all references to the branch are cleared, regardless of direction. It is typically called during network modification or cleanup operations.
- Parameters:
branch_id – The identifier of the branch to remove, as a tuple (from_node, to_node, branch_index).
- Returns:
None
Examples
node.remove_branch((1, 2, 0)) # Removes both (1, 2, 0) and (2, 1, 0) from the node’s branch lists if present.
- class monee.model.NodeModel(**kwargs)[source]¶
Bases:
GenericModelAbstract base class for node models in a network, defining the interface for nodal equations and behavior.
NodeModel provides a foundation for representing nodes within various grid domains (e.g., electrical, gas, heat) in network simulations. Subclasses must implement the abstract equations method to specify the physical or operational relationships at the node, such as flow conservation, voltage balance, or other nodal constraints. This class is intended for use in extensible, multi-domain network modeling frameworks and supports integration with branch and child component models.
Example:
class MyNodeModel(NodeModel): def equations(self, grid, in_branch_models, out_branch_models, childs, **kwargs): # Implement nodal balance equations return [eq1, eq2]
- equations(grid, in_branch_models, out_branch_models, childs, ``**kwargs``)[source]¶
Abstract. Must be implemented by subclasses to define the system of equations for the node.
- abstractmethod equations(grid, in_branch_models, out_branch_models, childs, **kwargs)[source]¶
Defines the system of equations for a node in the network, relating incoming and outgoing branches and attached child components.
This abstract method must be implemented by subclasses to specify the physical or operational relationships governing the node’s behavior within a grid. Use this method to model node constraints such as flow conservation, voltage balance, or other nodal conditions. It is typically called during network simulation or optimization to assemble the overall system equations.
- Parameters:
grid – The grid object to which the node belongs (e.g., electrical, gas, or heat grid).
in_branch_models (list) – List of branch model instances representing incoming branches to the node.
out_branch_models (list) – List of branch model instances representing outgoing branches from the node.
childs (list) – List of child component models attached to the node (e.g., loads, generators).
**kwargs – Additional keyword arguments for solver options or equation customization.
- Returns:
The equations or constraints representing the node’s behavior. The return type and structure depend on the modeling framework and implementation.
- Return type:
Any
- Raises:
NotImplementedError – If not implemented in a subclass.
Examples
class MyNodeModel(NodeModel): def equations(self, grid, in_branch_models, out_branch_models, childs, **kwargs): # Define nodal balance equations return [eq1, eq2]
- class monee.model.PowerBranch(tap, shift, backup=False, on_off=1, **kwargs)[source]¶
Bases:
GenericPowerBranch,ABCNo docstring provided.
_summary_
- Parameters:
tap (_type_) – _description_
shift (_type_) – _description_
br_r (_type_) – resistence
br_x (_type_) – reactance
g_fr (_type_) – from conductance
b_fr (_type_) – from susceptance
g_to (_type_) – to conductance
b_to (_type_) – to susceptance
- equations(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model, **kwargs)[source]¶
No docstring provided.
- class monee.model.PowerGenerator(p_mw, q_mvar, **kwargs)[source]¶
Bases:
NoVarChildModelFixed-setpoint active/reactive power generator.
Follows the load convention: internally stores negative values so that the node balance sees this component as an injection. The constructor accepts positive magnitudes and negates them:
PowerGenerator(p_mw=5, q_mvar=0) → p_mw=-5, q_mvar=0
- class monee.model.PowerGrid(name: str, sn_mva: float = 1)[source]¶
Bases:
GridRepresents an electrical power grid domain within a multi-energy network model.
PowerGrid extends the base Grid class to encapsulate properties specific to electrical networks, such as the system base power (sn_mva). Use this class to model electrical infrastructure, perform power flow calculations, or integrate electrical dynamics into multi-domain simulations. It is typically instantiated as part of a larger network model where electrical transmission, distribution, or sector coupling is required.
- sn_mva¶
System base power in megavolt-amperes (MVA). Used for per-unit normalization and power system calculations. Defaults to 1.
- Type:
Example
power_grid = PowerGrid(name=”el”, sn_mva=100) print(power_grid.name) # Output: “el” print(power_grid.sn_mva) # Output: 100
- class monee.model.PowerLine(length_m, r_ohm_per_m, x_ohm_per_m, parallel, backup=False, on_off=1, **kwargs)[source]¶
Bases:
PowerBranchNo docstring provided.
_summary_
- Parameters:
tap (_type_) – _description_
shift (_type_) – _description_
br_r (_type_) – resistence
br_x (_type_) – reactance
g_fr (_type_) – from conductance
b_fr (_type_) – from susceptance
g_to (_type_) – to conductance
b_to (_type_) – to susceptance
- calc_r_x(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model)[source]¶
No docstring provided.
- class monee.model.PowerLoad(p_mw, q_mvar, **kwargs)[source]¶
Bases:
NoVarChildModelFixed-setpoint active/reactive power load.
Follows the load convention: positive values represent consumption. Unlike
PowerGenerator, the constructor does not negate the supplied values:PowerLoad(p_mw=5, q_mvar=1) → p_mw=+5, q_mvar=+1
- class monee.model.PowerToGas(efficiency, mass_flow_setpoint, consume_q_mvar_setpoint=0, regulation=1)[source]¶
Bases:
MultiGridBranchModelNo docstring provided.
- class monee.model.PowerToHeat(heat_energy_w, diameter_m, temperature_ext_k, efficiency, q_mvar_setpoint=0)[source]¶
Bases:
MultiGridCompoundModelNo docstring provided.
- create(network: monee.model.network.Network, power_node: monee.model.core.Node, heat_node: monee.model.core.Node, heat_return_node: monee.model.core.Node)[source]¶
No docstring provided.
- class monee.model.PowerToHeatControlNode(load_p_mw, load_q_mvar, heat_energy_w, efficiency, **kwargs)[source]¶
Bases:
MultiGridNodeModel,Junction,BusNo docstring provided.
- class monee.model.Sink(mass_flow, **kwargs)[source]¶
Bases:
NoVarChildModelFixed-setpoint mass-flow sink (withdrawal) for gas or water networks.
Follows the load convention: positive values represent consumption. Unlike
Source, the constructor does not negate the supplied value:Sink(mass_flow=2.0) → self.mass_flow = +2.0
- Parameters:
mass_flow (float) – Mass flow rate in kg/s to withdraw (positive = consumption).
- class monee.model.Source(mass_flow, **kwargs)[source]¶
Bases:
NoVarChildModelFixed-setpoint mass-flow source (injection) for gas or water networks.
Follows the load convention: internally stores a negative mass-flow so that the junction balance treats this component as an injection. The constructor accepts positive magnitudes and negates them:
Source(mass_flow=2.0) → self.mass_flow = -2.0
- Parameters:
mass_flow (float) – Mass flow rate in kg/s to inject (positive = injection).
- class monee.model.Trafo(vk_percent=12.2, vkr_percent=0.25, sn_trafo_mva=160, shift=0)[source]¶
Bases:
PowerBranchNo docstring provided.
_summary_
- Parameters:
tap (_type_) – _description_
shift (_type_) – _description_
br_r (_type_) – resistence
br_x (_type_) – reactance
g_fr (_type_) – from conductance
b_fr (_type_) – from susceptance
g_to (_type_) – to conductance
b_to (_type_) – to susceptance
- calc_r_x(grid: monee.model.grid.PowerGrid, lv_model, hv_model)[source]¶
No docstring provided.
- equations(grid: monee.model.grid.PowerGrid, from_node_model, to_node_model, **kwargs)[source]¶
No docstring provided.
- class monee.model.Var(value, max=None, min=None, integer=False, name=None)[source]¶
Bases:
objectA decision variable (or mutable parameter) in the energy-flow / optimisation model.
During a solve the solver backend replaces
Varinstances with its own internal variable objects via the injection/withdrawal protocol. After the solve, the result is written back toVar.valueso callers can read it withvalue().Sign convention for child components — positive values represent consumption (load), negative values represent generation (injection). Child model constructors such as
PowerGeneratorandSourcenegate their constructor argument so that user-facing API always receives positive magnitudes:PowerGenerator(p_mw=5) → internally stores p_mw = -5 (generation) PowerLoad(p_mw=5) → internally stores p_mw = +5 (consumption)
Comparison operators (
<,<=,>,>=) compare against the bound of the variable, not the current value. They returnFalsewhen the relevant bound isNone(i.e. the variable is unbounded in that direction). This is useful for bound-checking in formulation code:v = Var(10, max=100) v < 200 # True — upper bound 100 < 200 v > 0 # False — lower bound is None (not 10)
- Parameters:
value – Initial/default value. Serves as the solver’s starting point.
max – Upper bound.
Nonemeans unbounded above.min – Lower bound.
Nonemeans unbounded below.integer – If
True, the variable is constrained to integer values (requires a MINLP-capable solver backend).name – Optional symbolic name forwarded to the solver for diagnostics.
- class monee.model.WaterGrid(name: str, fluid_density: float = 998, dynamic_visc: float = 0.000596, t_ref: float = 356, pressure_ref: float = 1000000, f_max: float = 200)[source]¶
Bases:
GridRepresents a water grid domain within a multi-energy network model, encapsulating key physical properties for hydraulic simulations.
WaterGrid extends the base Grid class to provide attributes specific to water networks, such as fluid density, dynamic viscosity, reference temperature, and reference pressure. Use this class to model water infrastructure, perform hydraulic calculations, or integrate water system dynamics into multi-domain simulations. It is typically instantiated as part of a larger network model where water transport, distribution, or sector coupling is required.
Example
water_grid = WaterGrid() print(water_grid.fluid_density) # Output: 998 print(water_grid.dynamic_visc) # Output: 0.000596
- class monee.model.WaterIslandingMode(big_m_conn: int = 200)[source]¶
Bases:
IslandingModeIslanding configuration for the water/heat carrier.
Structurally identical to
GasIslandingMode; pressure bounds are applied to de-energised junctions so thatpressure_pu = 0whene_i = 0.Use
GridFormingSource(frommonee.model.islanding.gas) as the grid-forming child for water junctions.- Parameters:
big_m_conn (int) – Big-M for connectivity-flow arc capacity. Must be ≥ number of carrier nodes.
- add_physical_constraints(network, gf_nodes, regular_nodes, e_vars)[source]¶
Force
pressure_pu = 0for de-energised water junctions (returned as list).- Return type:
- prepare(network: monee.model.network.Network)[source]¶
Phase 1 — add water islanding Var placeholders.
- Return type:
- class monee.model.WaterPipe(diameter_m, length_m, temperature_ext_k=283.15, roughness=4.5e-05, lambda_insulation_w_per_k=0.025, insulation_thickness_m=0.12, on_off=1, friction=None)[source]¶
Bases:
BranchModelNo docstring provided.
- equations(grid: monee.model.grid.WaterGrid, from_node_model, to_node_model, **kwargs)[source]¶
No docstring provided.
- monee.model.calc_coordinates(network: monee.model.network.Network, component: monee.model.core.Component)[source]¶
No docstring provided.
- monee.model.create_gas_grid(name, type='lgas')[source]¶
Creates and returns a GasGrid instance with predefined attributes for a specified gas grid type.
This function streamlines the instantiation of a GasGrid by automatically applying a set of standard physical and thermodynamic properties based on the selected grid type (e.g., ‘lgas’). Use this function when you need to quickly set up a gas grid domain for simulation, analysis, or integration into a multi-energy network model. The function retrieves the appropriate attribute set from GAS_GRID_ATTRS and passes them to the GasGrid constructor.
- Parameters:
- Returns:
An instance of GasGrid initialized with the specified name and standard attributes for the chosen type.
- Return type:
- Raises:
KeyError – If the specified type is not found in GAS_GRID_ATTRS.
Examples
# Create a default low-pressure gas grid gas_grid = create_gas_grid(‘city_gas’)
# Create a high-pressure gas grid if defined in GAS_GRID_ATTRS gas_grid = create_gas_grid(‘transmission_gas’, type=’hgas’)
- monee.model.create_power_grid(name, sn_mva=1)[source]¶
Creates and returns a PowerGrid instance with the specified name and system base power.
Use this function to instantiate an electrical power grid domain for use in network modeling, simulation, or optimization. The function allows you to specify the grid’s unique name and the system base power (sn_mva), which is essential for per-unit calculations and power system analysis.
- Parameters:
- Returns:
An instance of PowerGrid initialized with the given name and base power.
- Return type:
Examples
# Create a default power grid with 1 MVA base grid = create_power_grid(‘el’)
# Create a power grid with a custom base power grid = create_power_grid(‘transmission’, sn_mva=100)
- monee.model.create_water_grid(name)[source]¶
Creates and returns a WaterGrid instance with the specified name.
Use this function to instantiate a water grid domain for use in network modeling, hydraulic simulation, or multi-domain energy system analysis. The function initializes a WaterGrid object with default physical properties and assigns the provided name for identification within the network.
- Parameters:
name (str) – The unique name or identifier for the water grid.
- Returns:
An instance of WaterGrid initialized with the given name and default attributes.
- Return type:
Examples
# Create a water grid named “district_water” grid = create_water_grid(‘district_water’)
- monee.model.lower(var_or_const)[source]¶
Returns the lower bound (minimum value) of a variable or constant.
This function is used to extract the minimum allowed value from a Var instance, which may represent a decision variable or parameter in an optimization or simulation context. If the input is a Var and its min attribute is set, that value is returned; otherwise, the current value is returned. For non-Var inputs, the input is returned unchanged. Use this function when you need to retrieve the lower bound for constraints, reporting, or validation.
- Parameters:
var_or_const – A Var instance or a constant value. If a Var, must have a min attribute.
- Returns:
The minimum value for a Var, or the input value for constants.
- Return type:
float or Any
Examples
v = Var(5, min=2) lower(v) # Returns 2 lower(10) # Returns 10 v2 = Var(7) lower(v2) # Returns 7 (since min is None)
- monee.model.model(cls)[source]¶
Class decorator that registers a model class in the global component registry.
Applying
@modelto aNodeModel,BranchModel,ChildModel, orCompoundModelsubclass adds the class tocomponent_list, which is used by introspection utilities (e.g. serialisation helpers) to enumerate all known component types at runtime.Usage:
@model class MyLoad(ChildModel): def equations(self, grid, node_model, **kwargs): return [self.p_mw == node_model.p_mw]
- monee.model.to_spanning_tree(network: monee.model.network.Network)[source]¶
No docstring provided.
- class monee.model.tracked(value, max=None, min=None, integer=False, name=None)[source]¶
Bases:
VarA
Varwhose solved value is automatically carried to the next timestep in a timeseries simulation.Use this as a drop-in replacement for
Varon any attribute that should participate in inter-step state tracking. The framework detectstrackedinstances during variable injection, records the attribute name on the model, and extracts the solved float value after each step — nointer_step_vars()method required.Example:
class RampGenerator(PowerGenerator): def __init__(self, p_mw, ramp_up, ramp_down, **kwargs): super().__init__(p_mw, **kwargs) self.p_mw = tracked(p_mw, min=0, max=500) self.ramp_up = ramp_up self.ramp_down = ramp_down def inter_step_equations(self, prev_state, component_id, **kwargs): prev_p = prev_state.get(component_id, 'p_mw') if prev_p is None: return [] return [ self.p_mw - prev_p <= self.ramp_up, prev_p - self.p_mw <= self.ramp_down, ]
- monee.model.transform_network(network: monee.model.network.Network, graph_transform)[source]¶
No docstring provided.
- monee.model.upper(var_or_const)[source]¶
Returns the upper bound (maximum value) of a variable or constant.
This function extracts the maximum allowed value from a Var instance, which may represent a decision variable or parameter in an optimization or simulation context. If the input is a Var and its max attribute is set, that value is returned; otherwise, the current value is returned. For non-Var inputs, the input is returned unchanged. Use this function to retrieve the upper bound for constraints, reporting, or validation.
- Parameters:
var_or_const – A Var instance or a constant value. If a Var, must have a max attribute.
- Returns:
The maximum value for a Var, or the input value for constants.
- Return type:
float or Any
Examples
v = Var(5, max=10) upper(v) # Returns 10 upper(7) # Returns 7 v2 = Var(3) upper(v2) # Returns 3 (since max is None)
- monee.model.value(var_or_const)[source]¶
Extract the scalar value from a
Var,Const, orIntermediate.Plain Python numbers and other non-model types are returned unchanged. This is the canonical way to read back a result after a solve, because the solver replaces
Varinstances with its own objects during injection and restores them (with updated.value) during withdrawal.- Parameters:
var_or_const – A
Var,Const,Intermediate, or plain scalar.- Returns:
The
.valueattribute for model types, or var_or_const unchanged.
Examples:
v = Var(42.0) value(v) # 42.0 value(3.14) # 3.14