samedi 11 juillet 2015

Creating random graphs using GraphStream Library

Ok I need help guys! Already spent several hours on this. I have been coding a little with GraphStream library for a while now. I must say it is very interesting to use for those who like to model anything using graph. Ok, my issue is 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 codes are 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....". I used to create nodes and add them to a graph as follows: Node A = graph.addNode("A"); Now if think I need to make the node variable name dynamic. This is where I stuck. Any suggestion to overcome this issue is welcome.




Aucun commentaire:

Enregistrer un commentaire