15
15
import java .util .stream .Collectors ;
16
16
import java .util .stream .IntStream ;
17
17
18
+ // TODO: Delete
18
19
class SparseIntDWGEdgeRemovalCalculator {
19
20
private final Graph <String , DefaultWeightedEdge > graph ;
20
21
SparseIntDirectedWeightedGraph sparseGraph ;
@@ -35,7 +36,6 @@ class SparseIntDWGEdgeRemovalCalculator {
35
36
int vertexCount ,
36
37
Map <String , Integer > vertexToInt ,
37
38
Map <Integer , String > intToVertex ) {
38
- //TODO: Use concurrent types where possible
39
39
this .graph = graph ;
40
40
this .sparseGraph = sparseGraph ;
41
41
this .sparseEdges = new CopyOnWriteArrayList <>(sparseEdges );
@@ -83,7 +83,8 @@ private EdgeToRemoveInfo calculateSparseEdgeToRemoveInfo(Integer edgeToRemove) {
83
83
84
84
private List <Integer > orderVertices (SparseIntDirectedWeightedGraph sparseGraph ) {
85
85
List <Set <Integer >> sccs = new CopyOnWriteArrayList <>(findStronglyConnectedSparseGraphComponents (sparseGraph ));
86
- List <Integer > sparseIntSortedActivities = topologicalSortSparseGraph (sccs , sparseGraph );
86
+ // List<Integer> sparseIntSortedActivities = topologicalSortSparseGraph(sccs, sparseGraph);
87
+ List <Integer > sparseIntSortedActivities = topologicalParallelSortSparseGraph (sccs , sparseGraph );
87
88
// reversing corrects rendering of the DSM
88
89
// with sources as rows and targets as columns
89
90
// was needed after AI solution was generated and iterated
@@ -155,7 +156,7 @@ private List<Integer> topologicalParallelSortSparseGraph(List<Set<Integer>> sccs
155
156
ConcurrentLinkedQueue <Integer > sortedActivities = new ConcurrentLinkedQueue <>();
156
157
Set <Integer > visited = new ConcurrentSkipListSet <>();
157
158
158
- sccs .stream ()
159
+ sccs .parallelStream ()
159
160
.flatMap (Set ::parallelStream )
160
161
.filter (activity -> !visited .contains (activity ))
161
162
.forEach (activity -> topologicalSortUtilSparseGraph (activity , visited , sortedActivities , graph ));
@@ -169,11 +170,9 @@ private void topologicalSortUtilSparseGraph(
169
170
Integer activity , Set <Integer > visited , ConcurrentLinkedQueue <Integer > sortedActivities , Graph <Integer , Integer > graph ) {
170
171
visited .add (activity );
171
172
172
- for (Integer neighbor : Graphs .successorListOf (graph , activity )) {
173
- if (!visited .contains (neighbor )) {
174
- topologicalSortUtilSparseGraph (neighbor , visited , sortedActivities , graph );
175
- }
176
- }
173
+ Graphs .successorListOf (graph , activity ).parallelStream ()
174
+ .filter (neighbor -> !visited .contains (neighbor ))
175
+ .forEach (neighbor -> topologicalSortUtilSparseGraph (neighbor , visited , sortedActivities , graph ));
177
176
178
177
sortedActivities .add (activity );
179
178
}
0 commit comments