* @return labelled graph that is a tree
*/
public SimpleTree generateRandomTree(int numOfNodes,
int approxNumberOfChildren) {
SimpleTree tree = new SimpleTree(numOfNodes);
tree.turnTreeCheckOff();
int actualNodeNum = 1;
double randomNumber = 0.0;
ArrayList<Integer> nodesOnLevel = new ArrayList<>();
nodesOnLevel.add(0);
while (actualNodeNum < numOfNodes && nodesOnLevel.size() > 0) {
ArrayList<Integer> oldLevel = nodesOnLevel;
nodesOnLevel = new ArrayList<>();
int randomParent =
((Double) (Math.floor(rand.nextDouble() * (oldLevel.size()))))
.intValue();
addEdge(tree, actualNodeNum, oldLevel.get(randomParent));
nodesOnLevel.add(actualNodeNum);
actualNodeNum++;
AbstractNormalDistribution normDist =
new NormalDistribution(rand, 0., 1.);
for (int i : oldLevel) {
randomNumber =
approxNumberOfChildren + 0.25 * approxNumberOfChildren
* normDist.getRandomNumber();
while (randomNumber > 0.5 && actualNodeNum < numOfNodes) {
addEdge(tree, actualNodeNum, i);
nodesOnLevel.add(actualNodeNum);
actualNodeNum++;
randomNumber--;
}
}
}
for (int i = 0; i < numOfNodes; i++) {
tree.setLabel(i, rand.nextDouble() * 10);
}
if (!tree.turnTreeCheckOn()) {
throw new IllegalStateException("Problem with random tree creation");
}
tree.setTreeRoot(0);
return tree;
}