00001 // Copyright (C) 2010-2011 Institut de Robotica i Informatica Industrial, CSIC-UPC. 00002 // Author 00003 // All rights reserved. 00004 // 00005 // This file is part of iri-ros-pkg 00006 // iri-ros-pkg is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation, either version 3 of the License, or 00009 // at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 // 00019 // IMPORTANT NOTE: This code has been generated through a script from the 00020 // iri_ros_scripts. Please do NOT delete any comments to guarantee the correctness 00021 // of the scripts. ROS topics can be easly add by using those scripts. Please 00022 // refer to the IRI wiki page for more information: 00023 // http://wikiri.upc.es/index.php/Robotics_Lab 00024 00025 #ifndef _rule_learner_alg_h_ 00026 #define _rule_learner_alg_h_ 00027 00028 #include <iri_rule_learner/RuleLearnerConfig.h> 00029 #include "mutex.h" 00030 00031 //include rule_learner_alg main library 00032 #include <rules.h> 00033 #include <predicates.h> 00034 #include <symbols.h> 00035 #include <transitions.h> 00036 00037 #include <estirabot_msgs/DirtyArea.h> 00038 #include <estirabot_msgs/PointsDistanceMsg.h> 00039 00045 class RuleLearnerAlgorithm 00046 { 00047 protected: 00054 CMutex alg_mutex_; 00055 00056 // private attributes and methods 00057 00058 // dyanmic parameters 00059 int learning_m_; 00060 std::string rules_path_, updated_rules_path_, debugging_rules_path_, pasula_rules_path_; 00061 std::string transitions_path_, backup_transitions_path_, restore_transitions_path_; 00062 00063 Symbol last_action_; 00064 std::string last_state_; 00065 bool needs_learning_; 00066 00067 TransitionList transitions_, new_transitions_; 00068 RuleSet rules_; 00069 00070 00071 00072 public: 00079 typedef iri_rule_learner::RuleLearnerConfig Config; 00080 00087 Config config_; 00088 00097 RuleLearnerAlgorithm(void); 00098 00104 void lock(void) { alg_mutex_.enter(); }; 00105 00111 void unlock(void) { alg_mutex_.exit(); }; 00112 00120 bool try_enter(void) { return alg_mutex_.try_enter(); }; 00121 00133 void config_update(Config& new_cfg, uint32_t level=0); 00134 00135 // here define all rule_learner_alg interface methods to retrieve and set 00136 // the driver parameters 00137 00144 ~RuleLearnerAlgorithm(void); 00145 00146 bool add_state(std::string state); 00147 00148 bool add_action(std::string action_name, std::vector<uint> params); 00149 00150 void add_execution(std::string state); 00151 00152 std::vector<std::string> actions_needing_pasula_learning(); 00153 00154 std::vector<int> update_with_pasula_rules(std::vector<std::string> actions, TransitionList transitions); 00155 00156 inline TransitionList get_transitions() { return transitions_; } 00157 00158 TransitionList get_transitions_with_actions(std::vector<std::string> actions); 00159 00160 void write_transitions(TransitionList transitions); 00161 00162 void reset_new_transitions(); 00163 00164 }; 00165 00166 #endif