Skip to content
Yuri Barbosa Bittencourt edited this page Dec 22, 2017 · 4 revisions

Quick Guide

Note: this guide is for the Graphast version that is in the Develop branch

Creating a graph

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:

Graph g = new Graph();

Node n0 = new Node(0);
Node n1 = new Node(1);
Node n2 = new Node(2);
Node n3 = new Node(3);
Node n4 = new Node(4);

Edge e0 = new Edge(0, 1, 3, true);
Edge e1 = new Edge(1, 2, 3, true);
Edge e2 = new Edge(2, 3, 3, true);
Edge e3 = new Edge(0, 4, 5, true);
Edge e4 = new Edge(4, 3, 5, true);
Edge e5 = new Edge(0, 2, 15, true);
Edge e6 = new Edge(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

Doing queries

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:

ShortestPathStrategy strategy = new DijkstraStrategy(g);
DistanceVector vector = strategy.run(1, 3);
Clone this wiki locally