2016-08-30 12:31:41 +00:00
|
|
|
|
|
|
|
|
import * as graphlib from 'graphlib';
|
|
|
|
|
|
|
|
|
|
function test_graph() {
|
2017-01-19 21:15:14 +00:00
|
|
|
var g = new graphlib.Graph({
|
|
|
|
|
compound: true,
|
|
|
|
|
directed: true,
|
|
|
|
|
multigraph: true
|
|
|
|
|
});
|
2020-08-20 11:18:30 +00:00
|
|
|
g.setGraph({});
|
2016-08-30 12:31:41 +00:00
|
|
|
g.setEdge('a', 'b');
|
2017-01-19 21:15:14 +00:00
|
|
|
g.setEdge('a', 'b', 1.023, 'test');
|
|
|
|
|
g.setEdge({ v: 'a', w: 'b', name: 'test' }, 1.023);
|
|
|
|
|
g.hasEdge('a', 'b', 'test');
|
|
|
|
|
g.hasEdge({ v: 'a', w: 'b', name: 'test' });
|
|
|
|
|
g.removeEdge('a', 'b', 'test');
|
|
|
|
|
g.removeEdge({ v: 'a', w: 'b', name: 'test' });
|
2016-08-30 12:31:41 +00:00
|
|
|
|
2017-01-19 21:15:14 +00:00
|
|
|
g.edge('a', 'b', 'test');
|
|
|
|
|
g.edge({v: 'a', w: 'b', name: 'test'});
|
|
|
|
|
g.setDefaultNodeLabel({});
|
|
|
|
|
g.setDefaultNodeLabel(() => 42);
|
|
|
|
|
g.setDefaultEdgeLabel({});
|
|
|
|
|
g.setDefaultEdgeLabel(() => 'e42');
|
|
|
|
|
g.setNodes(['a', 'b', 'c'], 42);
|
|
|
|
|
g.setParent('d', 'a');
|
2017-04-06 16:03:05 +00:00
|
|
|
g.setParent('d');
|
2017-01-19 21:15:14 +00:00
|
|
|
g.parent('d');
|
|
|
|
|
g.children('a');
|
|
|
|
|
g.filterNodes(v => true);
|
|
|
|
|
g.setPath(['a', 'b', 'c'], 42);
|
2016-08-30 12:31:41 +00:00
|
|
|
|
|
|
|
|
graphlib.json.read(graphlib.json.write(g));
|
|
|
|
|
|
|
|
|
|
graphlib.alg.dijkstra(g, 'a', e => g.edge(e));
|
|
|
|
|
graphlib.alg.dijkstraAll(g, e => g.edge(e));
|
|
|
|
|
graphlib.alg.dijkstraAll(g);
|
|
|
|
|
|
|
|
|
|
graphlib.alg.findCycles(g);
|
|
|
|
|
graphlib.alg.isAcyclic(g);
|
|
|
|
|
graphlib.alg.prim(g, e => g.edge(e));
|
|
|
|
|
graphlib.alg.tarjan(g);
|
|
|
|
|
graphlib.alg.topsort(g);
|
2017-01-19 21:15:14 +00:00
|
|
|
graphlib.alg.preorder(g, g.nodes());
|
|
|
|
|
graphlib.alg.postorder(g, g.nodes());
|
2016-08-30 12:31:41 +00:00
|
|
|
}
|