syfop.network

class syfop.network.Network(nodes, time_coords=None, time_coords_freq='h', time_coords_num=8760, time_coords_year=2020, total_cost_unit=<Unit('EUR')>, solver_dir=None, units={})[source]

Bases: object

A network is a directed acyclic graph of nodes, which represents the flow of commodities between nodes. Nodes are represented by objects of classes defined in syfop.node. The connections between nodes are defined by the parameter inputs when creating node objects.

The network is used to optimize the sizes of the nodes, such that the total costs are minimized.

Attributes of this class are not supposed to be modified outside of this class - use the methods instead.

nodes

List of nodes to be included in the network. All nodes used as input nodes need to be included in this list.

Type:

list of subclasses of syfop.node.NodeBase

time_coords

time coordinates for the optimization problem

Type:

pandas.DatetimeIndex

nodes_dict

dictionary of nodes with node names as keys

Type:

dict

model

optimization model for the network

Type:

linopy.model.Model

Parameters:
  • nodes (list of subclasses of syfop.node.NodeBase) – List of nodes to be included in the network. All nodes used as input nodes need to be included in this list otherwise a ValueError is raised.

  • time_coords (pandas.DatetimeIndex) – time coordinates used for all time series in the network, typically hourly time steps for a year. If None, time_coords are generated using the parameters time_coords_freq, time_coords_num and time_coords_year.

  • time_coords_freq (str) – used only if time_coords is None, frequency of the time coordinates

  • time_coords_num (int) – used only if time_coords is None, number of time stamps generated. Note that the default value might be wrong in case of a leap year.

  • time_coords_year (int) – used only if time_coords is None, year used for generating time stamps (first hour of this year will be used for the first time stamp)

  • total_cost_unit (pint.Unit) – unit of the objective function, needs to be a currency

  • solver_dir (str) – Path where temporary files for the lp file, see linopy.model.Model. This is used as workaround on the VSC, because the default temp folder is on a partition with very limited space and deleting the files after the optimization does not work (always?).

  • units (dict) – A mapping from commodity to unit, e.g. {"electricity": ureg.MW}. This overwrites the default units in syfop.units.default_units. Required for commodities, which are not defined in syfop.units.default_units.

add_constraints(*args, **kwargs)[source]

Add custom constraints to the linopy optimization model. See linopy.model.Model.add_constraints() for a documentation of the parameters.

To create the constraint, variables can be accessed via Network.model.variables or by node attributes, e.g. in Network.nodes_dict['wind'].size for a node with name wind.

This method must be called before Network.optimize() is called.

add_variables(*args, **kwargs)[source]

Add custom variables to the linopy optimization model. See linopy.model.Model.add_variables() for a documentation of the parameters.

This method must be called before Network.optimize() is called.

draw(mode='netgraph')[source]

Draw a graphic representation of the network of all nodes and edges.

Parameters:

mode (str) – choice of plotting library used to draw the graph, one of: netgraph, graphviz

optimize(solver_name='highs', **kwargs)[source]

Optimize all node sizes: minimize total costs (sum of all (scaled) node costs) with subject to all constraints induced by the network.

Parameters:
total_costs()[source]

Return the total costs of the network as a linopy expression: this is the sum of all node costs (size of the node times the cost per unit) and input flow costs (sum of all input flows of the complete time span times the cost per unit).

This is used as objective in the optimization problem.

The result of the solved optimization can be found in the attribute Network.model.objective.value.

exception syfop.network.SolverError[source]

Bases: Exception

Raised when the solver fails to find an optimal solution.