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