Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_old.lua « test - github.com/torch/graph.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 003234cd02a0b220e5f38303f4e176c9b82e124f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'graph'
dofile 'graphviz.lua'

g=graph.Graph()
root=graph.Node(10)
n1=graph.Node(1)
n2=graph.Node(2)
g:add(graph.Edge(root,n1))
g:add(graph.Edge(root,n2))
nend = graph.Node(20)
g:add(graph.Edge(n1,nend))
g:add(graph.Edge(n2,nend))
g:add(graph.Edge(nend,root))

local i = 0
print('======= BFS ==========')
root:bfs(function(node) i=i+1;print('i='..i);print(node:label())end)
print('======= DFS ==========')
i = 0
root:dfs(function(node) i=i+1;print('i='..i);print(node:label())end)

print('======= topsort ==========')
s,rg,rn = g:topsort()

graph.dot(g)