}
// add edges as good as possible (better more than wished to make graph
// connected)
// last node must be touched to test if it is connected
IRandom rnd = SimSystem.getRNGGenerator().getNextRNG();
for (int i = 0; i < nodeList.size(); i++) {
// get a list of possible partners by getting all 'right' of i and sort
// out the ones with max degree
ArrayList<Integer> possibleNeighbourIndices = new ArrayList<>();
for (int j = i + 1; j < nodeList.size(); j++) {
if (nodeHasDeg.get(j) < nodeShouldDeg.get(j)) {
possibleNeighbourIndices.add(j);
}
}
/*
* if (nodeList.get(i).equals(18)) { i=i; }
*/
while (nodeHasDeg.get(i) < nodeShouldDeg.get(i)) {
if (possibleNeighbourIndices.isEmpty()) {
// we want more edges but no more partners are there
if (nodeHasDeg.get(i) == 0) {
// but we are not connected at all, so we try to force an edge
// to predecessor or successor
if (i > 0) {
graph.addEdge(new AnnotatedEdge<>(nodeList.get(i), nodeList
.get(i - 1), elDistri.getRandomNumber()));
System.out.println("Force edge from " + nodeList.get(i) + " to "
+ nodeList.get(i - 1));
nodeHasDeg.set(i - 1, nodeHasDeg.get(i - 1) + 1);
nodeHasDeg.set(i, 1);
}
if (i < nodeList.size() - 1) {
graph.addEdge(new AnnotatedEdge<>(nodeList.get(i), nodeList
.get(i + 1), elDistri.getRandomNumber()));
System.out.println("Force edge from " + nodeList.get(i) + " to "
+ nodeList.get(i + 1));
nodeHasDeg.set(i + 1, nodeHasDeg.get(i + 1) + 1);
nodeHasDeg.set(i, 1);
} else {
// we are connected, so we give up
break;
}
}
// no success - we are one node only and therefore also connected by
// definition
break;
}
// ok, we have possible partners, lets make an edge
// pick one randomly
int partnerIndex = rnd.nextInt(possibleNeighbourIndices.size());
graph.addEdge(new AnnotatedEdge<>(nodeList.get(i), nodeList
.get(possibleNeighbourIndices.get(partnerIndex)), elDistri
.getRandomNumber()));
// update degrees