Skip to content
Visal .In edited this page Aug 8, 2018 · 1 revision

Methods

Method Description
create_node(obj) Create new node
connect(u, v, cost = 1) Create edge that connect u and v
nodes() Returns all the nodes
edges(u = null) Return edges of u or return all the edges of the graph if u is not specified
path(src, dst, algorithm = 'dfs') Return the path from src to dst. There are two available algorithms: dfs (Depth-first search) or bfs (Breadth-first search)
mst(algorithm = 'prim') Return the minimum spanning tree of the graph. There are two available algorithms: prim (Prim's algorithm) and kruskal (Kruskal's algorithm)
color() Coloring the graph

Construct the Graph

var { Graph } = noobjs;
var g = new Graph();

// Create the nodes
var a = g.create_node("Cambodia");
var b = g.create_node("Thailand");
var c = g.create_node("Vietnam");

// Create the edges
g.connect(a, b, 751.5);
g.connect(a, c, 578.8);