graphstream / gs-core

Graphstream core
http://graphstream-project.org/
Other
399 stars 108 forks source link

Adding weight to an edge. #312

Open ghost opened 5 years ago

ghost commented 5 years ago
import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;

public class Tutorial1 {
    public static void main(String args[]) {
        Graph graph = new SingleGraph("Tutorial 1");

        graph.addNode("A");
        graph.addNode("B");
        graph.addNode("C");
        graph.addEdge("AB", "A", "B");
        graph.addEdge("BC", "B", "C");
        graph.addEdge("CA", "C", "A");

        graph.display();
    }
}

I want to add weights to these edges, so I can test my algorithm for shortest path between nodes. I don't see a option to add weight in graph.addEdge(), is there a way to add weights to the graph and display them?

hichbra commented 5 years ago

Use the method setAttribute() You can see an example here : https://github.com/graphstream/gs-algo/blob/master/src-test/org/graphstream/algorithm/test/TestDijkstra.java

ghost commented 5 years ago

@hichbra Thanks. I saw that and ended up using it, but was just wondering- why doesn't the AddEdge() method have an option for weight initself? Rather then having to use an attribute for it.