echo.models.base.node module
- class echo.models.base.node.Node(uid: str = NOTHING, node_name: str = NOTHING, ports: dict[str, Port] = NOTHING, objective: NumericExpression | float = 0)
Bases:
objectNodes are collections of one or more ports that can include non-trivial relationships between the ports, this allows transformations to be implemented.
- add_node_to_model(model: EchoConcreteModel, profile: DataFrame) None
Add this node to a concrete model.
- Parameters:
model – The concrete model to add the node to.
profile – The data associated with this node.
- add_objective(model: EchoConcreteModel) None
Define objective/s and add to self.objective. To be overwritten.
Should be implemented as an expression that needs to be concatanated to self.objective. For example:
- def add_objective(self, model: EchoConcreteModel) -> None:
total = 0
- if self.regularise is True:
- total += (
- sum(
getattr(model, self.flow_value)[p, t] * getattr(model, self.flow_value)[p, t] for p in model.Expansion for t in model.Time
) * 0.0000001
)
self.objective += total
- Parameters:
model – The model to add the objective/s to.
- Returns:
None
- add_ports_from_list(names: Iterable[str], port_type: type[Port], **kwargs) None
Creates a set of ports (using port_type) and adds them to this Node. The ports will be constructed using port_type and the supplied kwargs
- apply_node_constraints(model: EchoConcreteModel) None
Apply constraints associated with this node to a concrete model.
Intended to be overridden in subclasses.
Define constraints as functions that returns a Constraint, EqualityExpression or InequalityExpression.
Define a subfunction of the form detailed in the example below, then apply with setattr. For example:
- def apply_node_constraints(self, model: EchoConcreteModel) -> None:
- def tellegen_node_rule(model: EchoConcreteModel, p: int, t:int) -> EqualityExpression:
a = 0 for port in node_ports.values():
a += getattr(model, port.port_name)[p, t]
return a == 0
node_ports = self.ports con_name = “reliability_con_” + self.node_name setattr(model, con_name, en.Constraint(model.Expansion, model.Time, rule=tellegen_node_rule))
- Parameters:
model – The model to add the constraints to.
- Returns:
None
- get_port(port_name: str) Port | None
Returns the Port object with the name port_name.
- Parameters:
port_name – The name of the Port.
- Returns:
The port object with the name port_name, or None if the port isn’t found
- Return type:
- get_port_name_to_port_dict_name_map() dict[str, str]
Map the port name key in self.ports to the corresponding Port.port_name.
Returns:
- property inflow: str
- node_name: str
- num_ports() int
Returns the number of ports associated with this node.
- Returns:
The number of ports for this node.
- objective: NumericExpression | float
- uid: str
- verify_node() None
Checks there is at least one port associated with this node.
- Raises:
ConfigurationError – If there are no ports present on this node.