I have been coding a little with GraphStream library for a while now, and I want to create a random graph. Here is how I proceeded:
- Create a graph
- Create a random number generator, in my case, generates any number from 3 to 1000
- Create a node and add it to the graph
My code is as follows:
public class Cluster1 {
public static void main(String args[]) {
//create a graph
Graph graph = new SingleGraph("Cluster1");
// generate a random number of nodes from 3-1000
int numNodes = 3 + ((int) Math.floor(Math.random() * 998));
System.out.println("No of Nodes: " + numNodes + "\n");
// add each to node to the graph
for (int i = 1; i <= numNodes; i++) {
Node (String.valueOf(i)) = graph.addNode(String.valueOf(i));
}
graph.display();
}
}
It seems the error is from this line
Node (String.valueOf(i)) = graph.addNode(String.valueOf(i));
I used to create nodes and add them to a graph as follows:
Node A = graph.addNode("A");
I need to make the node variable name dynamic. This is where I'm stuck.