frequenz_microgrid_component_graph/
lib.rs

1// License: MIT
2// Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3
4/*!
5# Frequenz Microgrid Component Graph
6
7This is a library for representing the components of a microgrid and the
8connections between them as a Directed Acyclic Graph (DAG).
9
10A graph representation makes it easy to reason about the relationships between
11the components and to come up with formulas for calculating aggregated metrics
12for the microgrid.
13
14## The `Node` and `Edge` traits
15
16The main struct is [`ComponentGraph`], instances of which can be created by
17passing an iterator of components and the connections between them to the
18[`try_new`][ComponentGraph::try_new] method.
19
20But because `component_graph` is an independent library, it doesn't know about
21the component and connection types and instead uses traits to interact with
22them.
23
24Therefore, to be usable with this library, the component and connection types
25must implement the [`Node`] and [`Edge`] traits, respectively.  Check out the
26documentation for these traits for sample implementations.
27
28## Validation
29
30The [`try_new`][ComponentGraph::try_new] method several checks on the graph
31including checking that:
32
33- There is exactly one root node.
34- All edges point to existing nodes.
35- All nodes are reachable from the root node.
36- There are no cycles in the graph.
37- The components have sensible neighbor types.  For example, a battery shouldn't
38  have successors and should have a battery inverter as a predecessor.
39
40If any of the validation steps fail, the method will return an [`Error`], and a
41[`ComponentGraph`] instance otherwise.
42
43## Formula generation
44
45The component graph library has methods for generating formulas for various
46metrics of the microgrid.  The following formulas are supported:
47
48- [`grid_formula`][ComponentGraph::grid_formula]
49- [`producer_formula`][ComponentGraph::producer_formula]
50- [`consumer_formula`][ComponentGraph::consumer_formula]
51- [`pv_formula`][ComponentGraph::pv_formula]
52- [`battery_formula`][ComponentGraph::battery_formula]
53- [`ev_charger_formula`][ComponentGraph::ev_charger_formula]
54- [`chp_formula`][ComponentGraph::chp_formula]
55*/
56
57mod component_category;
58pub use component_category::{BatteryType, ComponentCategory, EvChargerType, InverterType};
59
60mod graph;
61pub use graph::{AggregationFormula, CoalesceFormula, ComponentGraph, Formula, iterators};
62
63mod graph_traits;
64pub use graph_traits::{Edge, Node};
65
66mod error;
67pub use error::Error;
68
69mod config;
70pub use config::ComponentGraphConfig;