Commit 4a67aeff authored by Alexander Diewald's avatar Alexander Diewald

DSE-TCgen: Fix the CA graph gen in to avoid bad bound errors

Issue-Ref: 4008
Issue-Url: https://af3-developer.fortiss.org/issues/4008Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 7d21b778
......@@ -2,7 +2,7 @@ AnnotationGenerationUtils.java 7fdab0a64ce72636bc59262b889b62eed54980ee YELLOW
CompArchGeneratonUtil.java d8c6db8002cc003f3681d6afd5fff3742c5fa437 RED
DseUtils.java d81af0b7f649d2453aada362fc50572fce31ebc8 YELLOW
FileWriterUtil.java 4a95559f571d41fa44e6236fc055ab5baac7c384 YELLOW
GraphGenerationUtilities.java 3be2143bf23befd2c9103c621ce31accf65b7cc6 YELLOW
GraphGenerationUtilities.java 40213f344dec1f62a0bb965739cb967f367803d4 YELLOW
GraphMetricUtils.java 99a398d4ff9b15b3eeb35748e32aa34a9b197f07 YELLOW
GraphUtils.java d11a2a067b343a2639f495c3417328f268f57127 YELLOW
ProjectUtils.java fe0009a32f6aaa58fb3330e2b9e383e217afc0dd YELLOW
......@@ -9,7 +9,6 @@ import static org.eclipse.core.runtime.Assert.isTrue;
import static org.jgrapht.Graphs.addAllVertices;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.function.Function;
......@@ -80,20 +79,28 @@ public class GraphGenerationUtilities {
// Ensure that every vertex is connected. Therefore, connect the remaining unconnected
// vertices with connected ones.
Collection<V> unconnectedVertices = graph.vertexSet().stream()
List<V> unconnectedVertices = graph.vertexSet().stream()
.filter(v -> (graph.inDegreeOf(v) == 0) && (graph.outDegreeOf(v) == 0))
.collect(toList());
List<V> connectedVertices = new ArrayList<>();
connectedVertices.removeAll(unconnectedVertices);
Random rnd = new Random();
for(V unconnectedV : unconnectedVertices) {
int index = rnd.nextInt(connectedVertices.size());
// There may be no already connected vertices from the upper algorithm. In that case
// randomly pick and connect two unconnected vertices, first. Only effective after
// during the first iteration.
V vertexToConnect = (connectedVertices.size() > 0)
? connectedVertices.get(rnd.nextInt(connectedVertices.size()))
: unconnectedVertices.get(unconnectedVertices.size() - 1);
boolean direction = rnd.nextBoolean();
if(direction) {
graph.addEdge(unconnectedV, connectedVertices.get(index));
graph.addEdge(unconnectedV, vertexToConnect);
} else {
graph.addEdge(connectedVertices.get(index), unconnectedV);
graph.addEdge(vertexToConnect, unconnectedV);
}
connectedVertices.add(unconnectedV);
}
return graph;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment