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:
objectA 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 parameterinputswhen 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
- 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
ValueErroris 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_coordsare generated using the parameterstime_coords_freq,time_coords_numandtime_coords_year.time_coords_freq (str) – used only if
time_coordsisNone, frequency of the time coordinatestime_coords_num (int) – used only if
time_coordsisNone, 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_coordsisNone, 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 insyfop.units.default_units. Required for commodities, which are not defined insyfop.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.variablesor by node attributes, e.g. inNetwork.nodes_dict['wind'].sizefor 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:
solver_name (str, optional) – all solvers supported by linopy
**kwargs – additional parameters passed to the solver via
linopy.model.Model.solve().
- 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.