Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / traffic_navigation / map_gen.py @ 1978

History | View | Annotate | Download (1.53 KB)

1
#!/usr/bin/env python2
2
#
3
#Colony Graph Drawing
4
#Pipe stdin in the form
5
# <SOURCE NODE> <CONNECTED NODE 1> <CONNECTED NODE 2> ... <CONNECTED NODE N>
6
# (space separated)
7

    
8
######
9
######
10
#USES GRAPHVIZ LIBRARY
11
#USES PYTHON-GRAPH LIBRARY
12
#IF YOU DON'T HAVE THOSE, THIS WILL DIE
13
######
14
######
15

    
16

    
17
# Import graphviz
18
import sys
19
sys.path.append('..')
20
sys.path.append('/usr/lib/graphviz/python/')
21
sys.path.append('/usr/lib64/graphviz/python/')
22
import gv
23

    
24
# Import pygraph
25
from pygraph.classes.graph import graph
26
from pygraph.classes.digraph import digraph
27
from pygraph.algorithms.searching import breadth_first_search
28
from pygraph.readwrite.dot import write
29

    
30
# Graph creation
31
gr = digraph()
32
nodes = [];
33

    
34
def addNode(x):
35
        if(not(x in nodes)):
36
                nodes.append(x);
37
                gr.add_nodes([x]);
38
def drawGraph():
39
        dot = write(gr)
40
        gvv = gv.readstring(dot)
41
        gv.setv(gvv, 'overlap', 'none')
42
        gv.setv(gvv, 'splines', 'true')
43
        gv.setv(gvv, 'sep', '0.25')
44
        gv.setv(gvv, 'mode', 'maxent')
45
        gv.layout(gvv,'sfdp')
46
        gv.render(gvv,'png','colony.png')
47

    
48
print "Colony Graph Generator\n==================\n"
49
print "Pipe in space separated <node a> <node b> <node c> ... <node n>"
50
print "Where a connects to nodes b, c, ..., n"
51
print "Outputs as colony.png\n\n"
52
print "Everything is space-separated"
53
print "And newlines denote a new source node"
54
print "This code uses the python-graph library and is based on example code from that library's website"
55
print "\n"
56
l="asdf"
57
while(not(l=="")):
58
        l=sys.stdin.readline()
59
        l_s = l.split()
60
        map(addNode, l_s)
61
        for y in l_s[1:]:
62
                gr.add_edge((l_s[0],y))
63
        drawGraph()
64