Go to the documentation of this file.
9 #ifndef MRPT_DIRECTEDGRAPH_H
10 #define MRPT_DIRECTEDGRAPH_H
54 template<
class TYPE_EDGES,
class EDGE_ANNOTATIONS = detail::edge_annotations_empty>
59 struct edge_t :
public TYPE_EDGES,
public EDGE_ANNOTATIONS
63 template <
typename ARG1>
inline edge_t (
const ARG1 &
a1) : TYPE_EDGES(
a1) { }
64 template <
typename ARG1,
typename ARG2>
inline edge_t (
const ARG1 &
a1,
const ARG2 &
a2) : TYPE_EDGES(
a1,
a2) { }
95 std::make_pair(from_nodeID,to_nodeID),
104 std::make_pair(from_nodeID,to_nodeID),
111 {
return edges.find(std::make_pair(from_nodeID,to_nodeID))!=
edges.end(); }
120 iterator it =
edges.find(std::make_pair(from_nodeID,to_nodeID));
123 else return it->second;
136 else return it->second;
141 return edges.equal_range( std::make_pair(from_nodeID,to_nodeID) );
145 return edges.equal_range( std::make_pair(from_nodeID,to_nodeID) );
151 edges.erase(std::make_pair(from_nodeID,to_nodeID));
161 lstNode_IDs.insert(it->first.first);
162 lstNode_IDs.insert(it->first.second);
173 std::set<TNodeID> aux;
176 aux.insert(it->first.first);
177 aux.insert(it->first.second);
188 if (it->first.first==nodeID)
189 neighborIDs.insert(it->first.second);
190 else if (it->first.second==nodeID)
191 neighborIDs.insert(it->first.first);
202 template <
class MAP_NODEID_SET_NODEIDS>
205 outAdjacency.clear();
208 outAdjacency[it->first.first].insert(it->first.second);
209 outAdjacency[it->first.second].insert(it->first.first);
215 template <
class MAP_NODEID_SET_NODEIDS,
class SET_NODEIDS>
216 void getAdjacencyMatrix( MAP_NODEID_SET_NODEIDS &outAdjacency,
const SET_NODEIDS &onlyForTheseNodes )
const
218 outAdjacency.clear();
222 if (onlyForTheseNodes.find(it->first.first)==setEnd || onlyForTheseNodes.find(it->first.second)==setEnd)
224 outAdjacency[it->first.first].insert(it->first.second);
225 outAdjacency[it->first.second].insert(it->first.first);
239 o <<
"digraph G {\n";
242 const TNodeID id1 = it->first.first;
243 const TNodeID id2 = it->first.second;
245 if (!p.node_names.empty())
248 if (itNam1!=p.node_names.end()) s1 =itNam1->second;
250 if (itNam2!=p.node_names.end()) s2 =itNam2->second;
252 if (s1.empty()) s1 =
mrpt::format(
"%u",static_cast<unsigned int>(id1));
253 if (s2.empty()) s2 =
mrpt::format(
"%u",static_cast<unsigned int>(id2));
254 if (p.node_props.empty())
257 if (itP1!=p.node_props.end()) o <<
"\""<<s1<<
"\""<<
" [" << itP1->second <<
"];\n";
259 if (itP2!=p.node_props.end()) o <<
"\""<<s2<<
"\""<<
" [" << itP2->second <<
"];\n";
261 o <<
" \"" << s1 <<
"\" -> \"" << s2 <<
"\"";
262 if (p.mark_edges_as_not_constraint) o <<
" [constraint=false]";
265 return !((o <<
"}\n").fail());
271 std::ofstream f(fileName.c_str());
272 if (!f.is_open())
return false;
#define THROW_EXCEPTION(msg)
#define MRPT_DECLARE_TTYPENAME(_TYPE)
std::pair< const_iterator, const_iterator > getEdges(TNodeID from_nodeID, TNodeID to_nodeID) const
Return a pair<first,last> of const iterators to the range of edges between two given nodes.
A directed graph with the argument of the template specifying the type of the annotations in the edge...
void insertEdgeAtEnd(TNodeID from_nodeID, TNodeID to_nodeID, const edge_t &edge_value)
Insert an edge (from -> to) with the given edge value (more efficient version to be called if you kno...
edge_t & getEdge(TNodeID from_nodeID, TNodeID to_nodeID)
Return a reference to the content of a given edge.
void insertEdge(TNodeID from_nodeID, TNodeID to_nodeID, const edge_t &edge_value)
Insert an edge (from -> to) with the given edge value.
std::pair< TNodeID, TNodeID > TPairNodeIDs
A pair of node IDs.
std::set< TNodeID > getAllNodes() const
Less efficient way to get all nodes that returns a copy of the set object.
bool edgeExists(TNodeID from_nodeID, TNodeID to_nodeID) const
Test is the given directed edge exists.
const edge_t & getEdge(TNodeID from_nodeID, TNodeID to_nodeID) const
Return a reference to the content of a given edge.
The type of each global pose in nodes: an extension of the TYPE_EDGES pose with any optional user-def...
CDirectedGraph()
Default constructor.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void clearEdges()
Erase all edges.
edges_map_t edges
The public member with the directed edges in the graph.
const typedef Scalar * const_iterator
void getAdjacencyMatrix(MAP_NODEID_SET_NODEIDS &outAdjacency, const SET_NODEIDS &onlyForTheseNodes) const
Just like getAdjacencyMatrix but return only the adjacency for those node_ids in the set onlyForThese...
void getNeighborsOf(const TNodeID nodeID, std::set< TNodeID > &neighborIDs) const
Return the list of all neighbors of "nodeID", by creating a list of their node IDs.
bool mark_edges_as_not_constraint
If true (default=false), an "[constraint=false]" will be added to all edges (see Graphviz docs).
const_iterator begin() const
size_t edgeCount() const
The number of edges in the graph.
edges_map_t::iterator iterator
CDirectedGraph(const edges_map_t &obj)
Copy constructor from a multimap<pair< >, >
edge_t(const ARG1 &a1, const ARG2 &a2)
size_t countDifferentNodesInEdges() const
Count how many different node IDs appear in the graph edges.
std::pair< iterator, iterator > getEdges(TNodeID from_nodeID, TNodeID to_nodeID)
Return a pair<first,last> of iterators to the range of edges between two given nodes.
bool saveAsDot(const std::string &fileName, const TGraphvizExportParams &p=TGraphvizExportParams()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_iterator end() const
void getAdjacencyMatrix(MAP_NODEID_SET_NODEIDS &outAdjacency) const
Return a map from node IDs to all its neighbors (that is, connected nodes, regardless of the edge dir...
std::map< TNodeID, std::string > node_names
If provided, these textual names will be used for naming the nodes instead of their numeric IDs given...
Used in mrpt::graphs export functions to .dot files.
mrpt::aligned_containers< TPairNodeIDs, edge_t >::multimap_t edges_map_t
The type of the member edges.
uint64_t TNodeID
The type for node IDs in graphs of different types.
std::map< TNodeID, std::string > node_props
If provided, an extra line will be added setting Graphviz properties for each node,...
void eraseEdge(TNodeID from_nodeID, TNodeID to_nodeID)
Erase all edges between the given nodes (it has no effect if no edge existed)
std::multimap< TYPE1, TYPE2, std::less< TYPE1 >, Eigen::aligned_allocator< std::pair< const TYPE1, TYPE2 > > > multimap_t
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
edges_map_t::const_iterator const_iterator
void getAllNodes(std::set< TNodeID > &lstNode_IDs) const
Return a list of all the node_ID's of the graph, generated from all the nodes that appear in the list...
bool saveAsDot(std::ostream &o, const TGraphvizExportParams &p=TGraphvizExportParams()) const
Save the graph in a Graphviz (.dot files) text format; useful for quickly rendering the graph with "d...
Page generated by Doxygen 1.8.16 for MRPT 1.4.0 SVN: at Mon Oct 14 23:08:25 UTC 2019 | | |