Go to the documentation of this file.00001
00002
00003 import min_dpa, os
00004
00005
00006 l = 100
00007
00008
00009 d0 = 1
00010
00011
00012 for N in [10,20,50,100]:
00013
00014 for d in range(6,7):
00015
00016 S,p,graph = min_dpa.min_dpa(N,d,l,d0)
00017
00018 if (len(S) == 0) & (len(p)==0) & (len(graph)==0):
00019 break
00020 else:
00021 print N, d
00022 print "Nodes:\n", S
00023 print "Node positions:\n", p
00024 print "Graph:\n", graph
00025
00026
00027
00028 directory = 'dot/'
00029 if not os.path.exists(directory):
00030 os.makedirs(directory)
00031
00032 filename = directory+'dotgraph_N'+str(N)+'_d'+str(d)+'.dot'
00033 f = open(filename,'w')
00034
00035 configure_graph_str = 'digraph G {\nnode [width=.3,height=.3,shape=octagon,style=filled,color=skyblue];\noverlap="false";\nrankdir="LR";\naspect="1";\n'
00036
00037 f.writelines(configure_graph_str)
00038
00039 f.writelines
00040 for n in range(0,len(S)):
00041 s= ''+S[n]+' [pos="'+str(p[n][0])+','+str(p[n][1])+'!"];\n'
00042 f.writelines(s)
00043
00044
00045 f.writelines
00046 for i in graph:
00047 for j in graph[i]:
00048 s= ' '+ i
00049 s+= ' -> ' + j + ' [label="' + str(graph[i][j]) + '"]'
00050 s+= ';\n'
00051 f.writelines(s)
00052
00053 f.writelines('}')
00054 f.close()
00055 print "done with ",filename,"!"
00056
00057
00058 directory = '../launch/graphs/'
00059 if not os.path.exists(directory):
00060 os.makedirs(directory)
00061
00062 filename = directory+'launch_dotgraph_N'+str(N)+'_d'+str(d)+'.launch'
00063 f = open(filename,'w')
00064
00065 f.writelines('<launch>\n')
00066
00067 f.writelines
00068 for n in range(0,len(S)):
00069
00070 s = '\t<node pkg="sap_pkg" type="node.py" name="'+S[n]+'" output="screen">\n'
00071 f.writelines(s)
00072
00073
00074 s = '\t\t<param name="position" value="[\''+str(p[n][0])+'\',\''+str(p[n][1])+'\',\'0\']"/>\n'
00075 f.writelines(s)
00076
00077 neighbours_list = graph[S[n]].keys()
00078 neighbours_str = ',/'.join(neighbours_list)
00079 s = '\t\t<param name="neighbour_nodes_list" value="/'+neighbours_str+'"/>\n'
00080 f.writelines(s)
00081
00082 f.writelines('\t</node>\n')
00083
00084 f.writelines('</launch>')
00085 f.close()
00086 print "done with ",filename,"!"
00087
00088 print "\nFinished creating all dot files and roslaunch files!"
00089
00090
00091
00092
00093
00094
00095
00096