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 PNCONTROLLER_HPP_
00035 #define PNCONTROLLER_HPP_
00036 #include <navcon_msgs/RegisterController.h>
00037
00038 #include <boost/config.hpp>
00039 #include <boost/graph/adjacency_list.hpp>
00040
00041 #include <Eigen/Dense>
00042
00043 #include <string>
00044 #include <map>
00045 #include <set>
00046
00047 namespace labust
00048 {
00049 namespace control
00050 {
00068 class PNController
00069 {
00070 struct PlaceInfo
00071 {
00072 PlaceInfo():
00073 place_num(-1),
00074 enable_t(-1),
00075 disable_t(-1){};
00076
00077 int place_num,
00078 enable_t,
00079 disable_t;
00080 };
00081
00082 public:
00086 PNController();
00087
00091 void addToGraph(const navcon_msgs::RegisterControllerRequest& info);
00095 void get_firing(const std::string& name);
00099 void get_firing_r(const std::string& name);
00103 void get_firing_pn(const std::string& name);
00107 void reachability();
00111 void addToRGraph(const std::string& name);
00115 void addToRGraph2(const std::string& name);
00119 void addToPNGraph(const navcon_msgs::RegisterControllerRequest& info);
00123 void getDotDesc(std::string& desc);
00127 void getDotDesc2(std::string& desc);
00128
00129 private:
00133 bool firing_rec(int des_place,
00134 std::set<int>& skip_transitions,
00135 std::set<int>& visited_places);
00136
00140 int pnum, tnum;
00144 Eigen::MatrixXi Dm,Dp,I;
00145
00146
00147
00148 Eigen::VectorXi marking;
00152 std::map<int, std::string> placeMap, transitionMap;
00156 std::map<std::string, PlaceInfo> nameMap;
00160 std::vector<int> firing_seq;
00164 std::vector<int> resourcePosition;
00165
00166
00167 struct VertexProperty
00168 {
00169 Eigen::VectorXi marking;
00170 };
00171
00172 struct EdgeProperty
00173 {
00174 typedef boost::edge_property_tag kind;
00175 EdgeProperty():
00176 t_num(-1),
00177 weight(1){};
00178 EdgeProperty(int t_num):
00179 t_num(t_num),
00180 weight(1){};
00181
00182 int t_num;
00183 int weight;
00184 };
00185
00186 typedef boost::adjacency_list<boost::vecS, boost::vecS,
00187 boost::directedS, VertexProperty,
00188 boost::property<boost::edge_name_t, int> > GraphType;
00189
00190 struct PNVertexProperty
00191 {
00192 enum {t =0, p=1};
00193 int type;
00194 int t_num;
00195 int p_num;
00196 bool marked;
00197 std::string name;
00198 std::set<int> dep_resource;
00199 };
00200
00201 struct PNEdgeProperty
00202 {
00203 int weight;
00204 };
00205
00206 typedef boost::adjacency_list<boost::vecS, boost::vecS,
00207 boost::bidirectionalS, PNVertexProperty,
00208 boost::property<boost::edge_name_t, int> > PNGraphType;
00209
00210 struct pn_writer
00211 {
00212 pn_writer(GraphType& graph):graph(graph){}
00213 template <class Vertex>
00214 void operator()(std::ostream &out, const Vertex& e) const
00215 {
00216 out << "[label= \"(";
00217 for(int i=0; i<graph[e].marking.size();++i)
00218 {
00219 out<<graph[e].marking[i]<<",";
00220 }
00221 out<< ")\"]";
00222 }
00223 GraphType& graph;
00224 };
00225
00229 struct pn_writer2 {
00230 pn_writer2(PNGraphType& graph):graph(graph){}
00231 template <class Vertex>
00232 void operator()(std::ostream &out, const Vertex& e) const
00233 {
00234 if (graph[e].type == PNVertexProperty::p)
00235 {
00236 out << "[label="<< graph[e].name<<"]";
00237 }
00238 else
00239 {
00240 out << "[height=0.05, style=filled, shape=rectangle, color=black, label=\"\"]";
00241 }
00242 }
00243 PNGraphType& graph;
00244 };
00245
00246 template<class PropertyMap, class NameMap>
00247 struct edge_writer {
00248 edge_writer(PropertyMap edge_map, NameMap map):
00249 edge_map(edge_map),
00250 map(map){};
00251 template <class Edge>
00252 void operator()(std::ostream &out, const Edge& e) const
00253 {
00254 out << "[label=\"" << map.at(edge_map[e]) << "\"]";
00255 }
00256 PropertyMap edge_map;
00257 NameMap map;
00258 };
00259
00260 template<class PropertyMap, class NameMap>
00261 edge_writer<PropertyMap, NameMap> make_edge_writer(PropertyMap pmap, NameMap map)
00262 {
00263 return edge_writer<PropertyMap, NameMap>(pmap,map);
00264 }
00265
00266 GraphType rgraph, rgraph2;
00267 PNGraphType pngraph;
00268
00269 std::map<int, int> placeToVertexMap;
00270
00271 std::vector<Eigen::VectorXi> all_markings;
00272 std::vector<GraphType::vertex_descriptor> all_idx;
00273 };
00274 }
00275 }
00276
00277
00278 #endif