-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraphGen.py
More file actions
76 lines (70 loc) · 2.36 KB
/
Copy pathgraphGen.py
File metadata and controls
76 lines (70 loc) · 2.36 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Cuda Graph Layout Tool
#
# Copyright (C) 2013 Roman Klapaukh and Michael Homer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import sys
import math
def pow(a, b):
total = 1
for i in range(b):
total *= a
return total
def circle(nnodes):
for i in range(nnodes):
print(' <node id="n{0}" />'.format(i))
print(' <edge id="e{0}" source="n{0}" target="n{1}" />'.format(
i, (i+1)%nnodes))
def k(n):
for i in range(n):
print(' <node id="n{0}" />'.format(i))
for j in range(i+1,n):
print(' <edge id="e{0}-{1}" source="n{0}" target="n{1}" />'.format(
i, j))
def grid(n):
for i in range(n):
for j in range(n):
print(' <node id="n{0}n{1}" />'.format(i,j))
if i < n-1:
print(' <edge id="e{0}n{1}--{2}n{1}" source="n{0}n{1}" target="n{2}n{1}" />'.format(i,j,i+1))
if j < n-1:
print(' <edge id="e{0}n{1}--{0}n{2}" source="n{0}n{1}" target="n{0}n{2}" />'.format(i,j,j+1))
def binaryTree(n):
for i in range(n):
print(' <node id="n{0}" />'.format(i))
parent = int(math.floor((i-1)/2))
if parent >=0:
print(' <edge id="e{0}--{1}" source="n{0}" target="n{1}" />'.format(i,parent))
nnodes = 5
gen = circle
if len(sys.argv) > 1:
nnodes = int(sys.argv[2])
if sys.argv[1] == '-c':
gen = circle
elif sys.argv[1] == '-k':
gen = k
elif sys.argv[1] == '-g':
gen = grid
elif sys.argv[1] == '-b':
gen = binaryTree
elif sys.argv[1] == '-bf':
gen = binaryTree
nnodes = int(pow(2,nnodes+1) - 1)
print('<?xml version="1.0"?>')
print('<graphml>')
print(' <graph id="g">')
gen(nnodes)
print(' </graph>')
print('</graphml>')