Go to the documentation of this file.
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!!");
void addEdge(TNodeID from, TNodeID to, const mrpt::aligned_std_map< TNodeID, CPose2D > &real_poses, CNetworkOfPoses2D &graph_links)
const Scalar * const_iterator
void insertEdge(TNodeID from_nodeID, TNodeID to_nodeID, const edge_t &edge_value)
Insert an edge (from -> to) with the given edge value.
A high-performance stopwatch, with typical resolution of nanoseconds.
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),...
uint64_t TNodeID
A generic numeric type for unique IDs of nodes or entities.
std::map< KEY, VALUE, std::less< KEY >, mrpt::aligned_allocator_cpp11< std::pair< const KEY, VALUE > >> aligned_std_map
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
edges_map_t edges
The public member with the directed edges in the graph.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
std::string getAsTextDescription() const
Return a text representation of the tree spanned in a depth-first view, as in this example:
TYPE_GRAPH graph_t
The type of the graph, typically a mrpt::graphs::CDirectedGraph<> or any other derived class.
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),...
A special kind of graph in the form of a tree with directed edges and optional edge annotations of te...
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
double Tac() noexcept
Stops the stopwatch.
typename graph_t::edge_t edge_t
The type of edge data in graph_t.
std::list< TPairNodeIDs > edge_list_t
A list of edges used to describe a path on the graph.
mrpt::gui::CDisplayWindow3D::Ptr win
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
double x() const
Common members of all points & poses classes.
typename edges_map_t::iterator iterator
Abstract graph and tree data structures, plus generic graph algorithms.
void Tic() noexcept
Starts the stopwatch.
Classes for creating GUI windows for 2D and 3D visualization.
Create a GUI window and display plots with MATLAB-like interfaces and commands.
A directed graph of pose constraints, with edges being the relative poses between pairs of nodes iden...
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
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...
This base provides a set of functions for maths stuff.
GLsizei const GLchar ** string
The Dijkstra algorithm for finding the shortest path between a given source node in a (weighted) dire...
A namespace of pseudo-random numbers generators of diferent distributions.
double myDijkstraWeight(const CMyDijkstra::graph_t &g, const TNodeID from, const TNodeID to, const CMyDijkstra::edge_t &edge)
CDijkstra< CNetworkOfPoses2D > CMyDijkstra
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
GLubyte GLubyte GLubyte a
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |