41 CPose2D p = real_poses.find(to)->second - real_poses.find(from)->second;
69 const size_t N_VERTEX = 20;
70 const double DIST_THRES = 10;
71 const double NODES_XY_MAX = 15;
75 for (
size_t j = 0; j < N_VERTEX; j++)
89 for (
size_t i = 0; i < N_VERTEX; i++)
91 for (
size_t j = 0; j < N_VERTEX; j++)
94 if (real_poses[i].distanceTo(real_poses[j]) < DIST_THRES)
95 addEdge(i, j, real_poses, graph_links);
103 const size_t SOURCE_NODE = 0;
107 cout <<
"Dijkstra took " << tictac.
Tac() * 1e3 <<
" ms for " 108 << graph_links.
edges.size() <<
" edges." << endl;
114 myDijkstra.getTreeGraph(graphAsTree);
119 struct CMyVisitor :
public CMyDijkstra::tree_graph_t::Visitor
121 virtual void OnVisitNode(
123 const CMyDijkstra::tree_graph_t::TEdgeInfo& edge_to_child,
124 const size_t depth_level)
override 126 cout <<
string(depth_level * 3,
' ');
127 cout << edge_to_child.id << endl;
131 CMyVisitor myVisitor;
133 cout <<
"Depth-first traverse of graph:\n";
134 cout << SOURCE_NODE << endl;
137 cout << endl <<
"Breadth-first traverse of graph:\n";
138 cout << SOURCE_NODE << endl;
149 for (
TNodeID i = 0; i < N_VERTEX &&
win.isOpen(); i++)
151 if (i == SOURCE_NODE)
continue;
155 myDijkstra.getShortestPathTo(i, path);
157 cout <<
"to " << i <<
" -> #steps= " << path.size() << endl;
161 "Dijkstra path %u->%u", static_cast<unsigned int>(SOURCE_NODE),
162 static_cast<unsigned int>(i)));
168 e != graph_links.
end(); ++e)
170 const CPose2D& p1 = real_poses[e->first.first];
171 const CPose2D& p2 = real_poses[e->first.second];
179 win.plot(X, Y,
"k1");
184 a != path.end(); ++
a)
186 const CPose2D& p1 = real_poses[
a->first];
187 const CPose2D& p2 = real_poses[
a->second];
195 win.plot(X, Y,
"g3");
199 win.plot(xs, ys,
".b7");
202 cout <<
"Press any key to show next shortest path, close window to " 219 cout <<
"MRPT exception caught: " << e.what() << endl;
224 printf(
"Another exception!!");
A namespace of pseudo-random numbers generators of diferent distributions.
CDijkstra< CNetworkOfPoses2D > CMyDijkstra
double Tac() noexcept
Stops the stopwatch.
double x() const
Common members of all points & poses classes.
A special kind of graph in the form of a tree with directed edges and optional edge annotations of te...
void addEdge(TNodeID from, TNodeID to, const mrpt::aligned_std_map< TNodeID, CPose2D > &real_poses, CNetworkOfPoses2D &graph_links)
Create a GUI window and display plots with MATLAB-like interfaces and commands.
edges_map_t edges
The public member with the directed edges in the graph.
typename graph_t::edge_t edge_t
The type of edge data in graph_t.
Abstract graph and tree data structures, plus generic graph algorithms.
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
A high-performance stopwatch, with typical resolution of nanoseconds.
std::map< KEY, VALUE, std::less< KEY >, mrpt::aligned_allocator_cpp11< std::pair< const KEY, VALUE > >> aligned_std_map
A directed graph of pose constraints, with edges being the relative poses between pairs of nodes iden...
std::list< TPairNodeIDs > edge_list_t
A list of edges used to describe a path on the graph.
This base provides a set of functions for maths stuff.
void visitDepthFirst(const TNodeID vroot, Visitor &user_visitor, const size_t root_depth_level=0) const
Depth-first visit of all children nodes of a given root (itself excluded from the visit)...
void insertEdge(TNodeID from_nodeID, TNodeID to_nodeID, const edge_t &edge_value)
Insert an edge (from -> to) with the given edge value.
typename MAPS_IMPLEMENTATION::template map< mrpt::graphs::TNodeID, global_pose_t > global_poses_t
A map from pose IDs to their global coordinate estimates, without uncertainty (the "most-likely value...
mrpt::gui::CDisplayWindow3D::Ptr win
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TYPE_GRAPH graph_t
The type of the graph, typically a mrpt::graphs::CDirectedGraph<> or any other derived class...
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
uint64_t TNodeID
A generic numeric type for unique IDs of nodes or entities.
The Dijkstra algorithm for finding the shortest path between a given source node in a (weighted) dire...
Classes for creating GUI windows for 2D and 3D visualization.
void Tic() noexcept
Starts the stopwatch.
double myDijkstraWeight(const CMyDijkstra::graph_t &g, const TNodeID from, const TNodeID to, const CMyDijkstra::edge_t &edge)
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
GLubyte GLubyte GLubyte a
std::string getAsTextDescription() const
Return a text representation of the tree spanned in a depth-first view, as in this example: ...
const Scalar * const_iterator
void visitBreadthFirst(const TNodeID vroot, Visitor &user_visitor, const size_t root_depth_level=0) const
Breadth-first visit of all children nodes of a given root (itself excluded from the visit)...
typename edges_map_t::iterator iterator