1

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:

  1. Create a graph
  2. Create a random number generator, in my case, generates any number from 3 to 1000
  3. 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.

Erik Godard
  • 5,930
  • 6
  • 30
  • 33
george24
  • 331
  • 1
  • 3
  • 11

1 Answers1

0

I think I solve it:
Node A[] = new Node[numNodes]; for (int i = 1; i<=numNodes-1; i++) { A[i] = graph.addNode(String.valueOf(i)); }

george24
  • 331
  • 1
  • 3
  • 11