PNController.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2010, LABUST, UNIZG-FER
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the LABUST nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
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                          * The current marking.
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                         //Reachability graph stuff
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 /* PNCONTROLLER_HPP_ */
00278 #endif


labust_execution
Author(s): Gyula Nagy
autogenerated on Fri Aug 28 2015 11:23:25