Skip to content

Commit efa2a22

Browse files
fix
Signed-off-by: Sylvestre Prabakaran <sylvestre.prabakaran@rte-france.com>
1 parent 63555ae commit efa2a22

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/main/java/com/powsybl/openloadflow/graph/JGraphTModelWithAdjacencyList.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
package com.powsybl.openloadflow.graph;
99

10+
import com.powsybl.math.graph.GraphUtil;
1011
import gnu.trove.list.array.TIntArrayList;
1112

1213
import 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
}

0 commit comments

Comments
 (0)