44 import graph_tool.all
as gt
47 print(
'Failed to import graph-tool. PlannerData will not be analyzed or plotted')
51 from ompl
import base
as ob
52 from ompl
import geometric
as og
56 from os.path
import abspath, dirname, join
58 sys.path.insert(0, join(dirname(dirname(abspath(__file__))),
'py-bindings'))
59 from ompl
import base
as ob
60 from ompl
import geometric
as og
64 def isStateValid(state):
65 if state.getY() >= -3
and state.getY() <= 3:
66 return state.getX() >= -3
and state.getX() <= 3
and \
67 state.getZ() >= -3
and state.getZ() <= 3
72 graphml = pd.printGraphML()
73 f = open(
"graph.graphml",
'w')
78 graph = gt.load_graph(
"graph.graphml", fmt=
"xml")
79 edgeweights = graph.edge_properties[
"weight"]
82 avgdeg, stddevdeg = gt.vertex_average(graph,
"total")
83 avgwt, stddevwt = gt.edge_average(graph, edgeweights)
85 print(
"---- PLANNER DATA STATISTICS ----")
86 print(str(graph.num_vertices()) +
" vertices and " + str(graph.num_edges()) +
" edges")
87 print(
"Average vertex degree (in+out) = " + str(avgdeg) +
" St. Dev = " + str(stddevdeg))
88 print(
"Average edge weight = " + str(avgwt) +
" St. Dev = " + str(stddevwt))
90 _, hist = gt.label_components(graph)
91 print(
"Strongly connected components: " + str(len(hist)))
94 graph.set_directed(
False)
95 _, hist = gt.label_components(graph)
96 print(
"Weakly connected components: " + str(len(hist)))
99 gt.remove_parallel_edges(graph)
101 edgeweights = graph.edge_properties[
"weight"]
102 colorprops = graph.new_vertex_property(
"string")
103 vertexsize = graph.new_vertex_property(
"double")
108 for v
in range(graph.num_vertices()):
111 if pd.isStartVertex(v):
113 colorprops[graph.vertex(v)] =
"cyan"
114 vertexsize[graph.vertex(v)] = 10
115 elif pd.isGoalVertex(v):
117 colorprops[graph.vertex(v)] =
"green"
118 vertexsize[graph.vertex(v)] = 10
120 colorprops[graph.vertex(v)] =
"yellow"
121 vertexsize[graph.vertex(v)] = 5
124 edgecolor = graph.new_edge_property(
"string")
125 edgesize = graph.new_edge_property(
"double")
126 for e
in graph.edges():
127 edgecolor[e] =
"black"
131 if start != -1
and goal != -1:
132 _, pred = gt.astar_search(graph, graph.vertex(start), edgeweights)
135 v = graph.vertex(goal)
136 while v != graph.vertex(start):
137 p = graph.vertex(pred[v])
138 for e
in p.out_edges():
147 gt.graph_draw(graph, vertex_size=vertexsize, vertex_fill_color=colorprops,
148 edge_pen_width=edgesize, edge_color=edgecolor,
150 print(
'\nGraph written to graph.png')
160 space.setBounds(bounds)
170 start().rotation().setIdentity()
177 goal().rotation().setIdentity()
182 ss.setStartAndGoalStates(start, goal, 0.05)
185 planner =
og.PRM(ss.getSpaceInformation())
186 ss.setPlanner(planner)
190 solved = ss.solve(20.0)
194 print(
"Found solution:\n%s" % ss.getSolutionPath())
198 ss.getPlannerData(pd)
201 pd.computeEdgeWeights()
206 if __name__ ==
"__main__":