File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
src/main/java/com/powsybl/openloadflow/graph Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 77 */
88package com .powsybl .openloadflow .graph ;
99
10+ import com .powsybl .math .graph .GraphUtil ;
1011import gnu .trove .list .array .TIntArrayList ;
1112
1213import java .util .*;
@@ -108,4 +109,25 @@ public List<V> getNeighborVerticesOf(V v) {
108109 public Map <V , TIntArrayList > getAdjacencyList () {
109110 return adjacencyList ;
110111 }
112+
113+ @ Override
114+ public List <Set <V >> calculateConnectedSets () {
115+ TIntArrayList [] adjacencyListArray = new TIntArrayList [adjacencyList .size ()];
116+ for (Map .Entry <V , TIntArrayList > entry : this .adjacencyList .entrySet ()) {
117+ V vertex = entry .getKey ();
118+ TIntArrayList adj = entry .getValue ();
119+ adjacencyListArray [numGetter .applyAsInt (vertex )] = adj ;
120+ }
121+ GraphUtil .ConnectedComponentsComputationResult result = GraphUtil .computeConnectedComponents (adjacencyListArray );
122+ List <Set <V >> connectedSets = new ArrayList <>();
123+ for (int size : result .getComponentSize ()) {
124+ connectedSets .add (HashSet .newHashSet (size ));
125+ }
126+ int [] componentNum = result .getComponentNumber ();
127+ for (V vertex : this .adjacencyList .keySet ()) {
128+ int v = numGetter .applyAsInt (vertex );
129+ connectedSets .get (componentNum [v ]).add (vertex );
130+ }
131+ return connectedSets ;
132+ }
111133}
You can’t perform that action at this time.
0 commit comments