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 reachability();
00107                         void getDotDesc(std::string& desc);
00108 
00109                 private:
00113                         bool firing_rec(int des_place,
00114                                         std::set<int>& skip_transitions,
00115                                         std::set<int>& visited_places);
00116 
00120                         int pnum, tnum;
00124                         Eigen::MatrixXi Dm,Dp,I;
00125                         /*
00126                          * The current marking.
00127                          */
00128                         Eigen::VectorXi marking;
00132                         std::map<int, std::string> placeMap, transitionMap;
00136                         std::map<std::string, PlaceInfo> nameMap;
00140                         std::vector<int> firing_seq;
00141 
00142                         //Reachability graph stuff
00143                         struct VertexProperty
00144                         {
00145                                 Eigen::VectorXi marking;
00146                         };
00147 
00148                         struct EdgeProperty
00149                         {
00150                           typedef boost::edge_property_tag kind;
00151                                 EdgeProperty():
00152                                         t_num(-1),
00153                                         weight(1){};
00154                                 EdgeProperty(int t_num):
00155                                         t_num(t_num),
00156                                         weight(1){};
00157 
00158                                 int t_num;
00159                                 int weight;
00160                         };
00161 
00162                         typedef boost::adjacency_list<boost::vecS, boost::vecS,
00163                                 boost::directedS, VertexProperty,
00164                                 boost::property<boost::edge_name_t, int> > GraphType;
00165 
00166                         struct pn_writer
00167                         {
00168                                 pn_writer(GraphType& graph):graph(graph){}
00169                                 template <class Vertex>
00170                                 void operator()(std::ostream &out, const Vertex& e) const
00171                                 {
00172                                         out << "[label= \"(";
00173                                         for(int i=0; i<graph[e].marking.size();++i)
00174                                         {
00175                                                 out<<graph[e].marking[i]<<",";
00176                                         }
00177                                         out<< ")\"]";
00178                                 }
00179                                 GraphType& graph;
00180                         };
00181 
00182                         template<class PropertyMap, class NameMap>
00183                         struct edge_writer {
00184                           edge_writer(PropertyMap edge_map, NameMap map):
00185                                 edge_map(edge_map),
00186                                 map(map){};
00187                           template <class Edge>
00188                           void operator()(std::ostream &out, const Edge& e) const
00189                           {
00190                             out << "[label=\"" << map.at(edge_map[e]) << "\"]";
00191                           }
00192                           PropertyMap edge_map;
00193                           NameMap map;
00194                         };
00195 
00196                         template<class PropertyMap, class NameMap>
00197                         edge_writer<PropertyMap, NameMap> make_edge_writer(PropertyMap pmap, NameMap map)
00198                         {
00199                                 return edge_writer<PropertyMap, NameMap>(pmap,map);
00200                         }
00201 
00202                         GraphType rgraph;
00203 
00204                         std::vector<Eigen::VectorXi> all_markings;
00205                         std::vector<GraphType::vertex_descriptor> all_idx;
00206                 };
00207         }
00208 }
00209 
00210 /* PNCONTROLLER_HPP_ */
00211 #endif


labust_execution
Author(s): Gyula Nagy
autogenerated on Fri Feb 7 2014 11:36:24