Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef EXECPNGRAPH_HPP_
00035 #define EXECPNGRAPH_HPP_
00036 #include <navcon_msgs/RegisterController.h>
00037
00038 #include <boost/config.hpp>
00039 #include <boost/graph/adjacency_list.hpp>
00040
00041 #include <list>
00042 #include <string>
00043 #include <map>
00044 #include <iosfwd>
00045
00046 namespace labust
00047 {
00048 namespace control
00049 {
00053 class ExecPNGraph
00054 {
00055 struct VertexProperty
00056 {
00057 enum {p=0, t=1};
00058
00059 VertexProperty():
00060 name("uninitialized"),
00061 type(0),
00062 marked(false){};
00063
00064 VertexProperty(const std::string& name, int type):
00065 name(name),
00066 type(type),
00067 marked(false){};
00068
00069 std::string name;
00070 int type;
00071 bool marked;
00072 };
00073
00074 typedef boost::property < boost::edge_weight_t, int > EdgeProperty;
00075 typedef boost::adjacency_list<boost::vecS, boost::vecS,
00076 boost::directedS, VertexProperty,
00077 EdgeProperty > GraphType;
00078
00079 struct PlaceInfo
00080 {
00081 PlaceInfo():
00082 place_num(-1),
00083 enable_t(-1),
00084 disable_t(-1){};
00085
00086 GraphType::vertex_descriptor
00087 place_num,
00088 enable_t,
00089 disable_t;
00090 };
00091
00092 public:
00096 ExecPNGraph();
00097
00101 void addToGraph(const navcon_msgs::RegisterControllerRequest& info);
00105 void findPath(const std::string& start, const std::string& end,
00106 std::list<std::string>& path);
00110 void getDotDesc(std::string& desc);
00111
00112 private:
00116 inline GraphType::vertex_descriptor
00117 add_place(const std::string& name)
00118 {
00119 return boost::add_vertex(
00120 VertexProperty(name,VertexProperty::p),graph);
00121 }
00125 inline GraphType::vertex_descriptor
00126 add_transition(const std::string& name)
00127 {
00128 return boost::add_vertex(
00129 VertexProperty(name,VertexProperty::t),graph);
00130 }
00134 inline std::pair<GraphType::edge_descriptor, bool>
00135 add_edge(GraphType::vertex_descriptor from,
00136 GraphType::vertex_descriptor to, int weight = 1)
00137 {
00138 assert(((graph[from].type == VertexProperty::p) &&
00139 (graph[to].type == VertexProperty::t)) ||
00140 ((graph[from].type == VertexProperty::t)
00141 && (graph[to].type == VertexProperty::p)) &&
00142 "You can only connect places and transitions.");
00143 return boost::add_edge(from,to, weight, graph);
00144 }
00148 struct pn_writer {
00149 pn_writer(GraphType& graph):graph(graph){}
00150 template <class Vertex>
00151 void operator()(std::ostream &out, const Vertex& e) const
00152 {
00153
00154 out << "[label="<< graph[e].name;
00155 out << ((graph[e].type == GraphType::vertex_property_type::value_type::t)?", shape=rectangle":"") << "]";
00156 }
00157 GraphType& graph;
00158 };
00162 GraphType graph;
00166 std::map<std::string,
00167 PlaceInfo> nameMap;
00168 };
00169 }
00170 }
00171
00172
00173 #endif