Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
quick guide
Note: this guide is for the Graphast version that is in the Develop branch
First of all, we must know that there are three basic structures in Graphast: Node, Edge and Graph.
So let's create a graph, in this case, one with 5 nodes and 7 edges:
Graphg = newGraph();
Noden0 = newNode(0);
Noden1 = newNode(1);
Noden2 = newNode(2);
Noden3 = newNode(3);
Noden4 = newNode(4);
Edgee0 = newEdge(0, 1, 3, true);
Edgee1 = newEdge(1, 2, 3, true);
Edgee2 = newEdge(2, 3, 3, true);
Edgee3 = newEdge(0, 4, 5, true);
Edgee4 = newEdge(4, 3, 5, true);
Edgee5 = newEdge(0, 2, 15, true);
Edgee6 = newEdge(3, 0, 11, true);
g.addNodes(n0, n1, n2, n3, n4);
g.addEdges(e0, e2, e4, e1, e6, e5, e3);Note: the Node's argument is an ID, the Edge's arguments are Node IDs, weight and a flag to say that is bidirectional
We have our graph g with some nodes, edges and weights. Now we want to do queries in g.
Graphast uses the so called strategies to do so. In this example we'll use the DijkstraStrategy. The strategy argument is a Graph.
The strategy run method do the query, in this case, a shortest path between the 2 nodes passed(by Node ID) as arguments, if the second Node is null, then the run method will return the shortest paths between the first Node and all graph's Nodes. The return is a DistanceVector.
Example:
ShortestPathStrategystrategy = newDijkstraStrategy(g);
DistanceVectorvector = strategy.run(1, 3);