# Integrating Knowledge Graphs into Distribution Grid Decision Support Systems +
## 5 GridKG--Graph-Based Representation of Distribution Grid
### Electrical Paths  
One of the most interesting examples of processing the data included in GridKG and enhancing them at the same time is the identification of electrical paths in a system. This allows determination of upstream and downstream elements and, as a consequence, analysis of the graph from additional perspectives.  
In the graph-based representation of a grid, an electrical path is considered to be a sequence of tuples  
\[\langle\textit{cNode}_{x}{\rightarrow}c{\rightarrow}\textit{Element-Asset}_{p}{ \rightarrow}c{\rightarrow}c{\rightarrow}\textit{Node}_{y}\rangle,\]  
where \(c\) represents _Connection_ relation. This tuple is composed of two triples connected via the same _Element-Asset\({}_{p}\)_, i.e., \(\langle\textit{cNode}_{x}{\rightarrow}c{\rightarrow}\textit{Element-Asset}_{p}\rangle\) and \(\langle\textit{Element-Asset}_{p}{\rightarrow}c{\rightarrow}c{\rightarrow} \textit{Node}_{y}\rangle\). An example of an electrical path is shown in Figure 2 where nodes representing _Element-Assets_ are connected via thick gray links. The proposed process for identifying paths is equivalent to \"stitching\" together a number of tuples in a way that _cNode\({}_{y}\)_ of the predecessor tuple matches _cNode\({}_{x}\)_ of the successor tuple.  
Algorithm 1 shows the process in the form of a pseudocode. The input to the algorithm is queue Q of triples (_Element-Asset_-c_-_cNode_), where _Element-Asset_ is of type _Breaker_. Based on the triples from the queue, the breadth-first search algorithm finds a sequence of adjacent _Element-Assets_. If the encountered _Element-Asset_ is of type _Switch_, then its _ConnectionStatusType_ must be _Connected_. If it is _Open_, it is not considered part of the continuous electrical path.  
Next, a special attribute of the _Element-Asset_ class is defined, called _level_. It is used to keep track of the elements' positions on the path. For each _Element-Asset_, the algorithm modifies a direction of connections from an element of a lower value of _level_ to the adjacent element with a higher value of _level_. The algorithm terminates when the queue is empty.  
```
1:Input:
2:\(\mathbf{Q}\leftarrow\text{list of triples }\langle cNode-c-Braker\rangle\)
3:Initialization:
4:\(level=0\)
5:setnextElements = |,\(\triangleright\) Elements to visit
6:setS = |,\(\triangleright\) visited Elements
7:whileQ is not empty do
8:\(size\leftarrow\)numberOfTriples(\(\mathbf{Q}\))
9:for\(\mathbf{l}\) to sizedo
10:\(\langle cNode-c-Element\rangle\leftarrow\text{getTriple}(\mathbf{Q})\)
11:if\(\mathbf{id}(Element)\in\mathbf{S}\)then\(\triangleright\) Element visited
12:continue
13:level of \(Element\gets level\)
14:\(\mathbf{S}\gets Element\)
15:\(cNode\_next\leftarrow\text{getNextNode}(Element)\)
16:nextElements \(\leftarrow\)getNextElement(\(Node\_next\))
17:for each\(Element\_next\in\)nextElements do
18:setDirection(\(Element\_cNode\_next\), \(Element\_next\))
19:if not(type(\(Element\_next\)) == Switch &
20:state(\(Element\_next\)) == Opened) then
21:\(\mathbf{Q}\leftarrow\langle cNode\_next-c-Element\_next\rangle\)
22:end_if
23:end_for
24:end_for
25:\(level\gets level+1\)
26:end_while
27:return
```  
**Algorithm 1** Multi-Source Path Search  
Figure 2: A fragment of the distribution grid with a transformer, three electrical lines and a fuse: electrical connections are shown as thick grey lines.  
The process of establishing electrical paths allows easy identification of upstream and downstream elements. It can be used, for example, to determine the number of customers that \"depend\" on a specific element. A single application of the simple algorithm augments each element with additional information that indicates how many customers are located downstream of the element, stored in a new attribute _numCustomer_.