TimeReward.h
Go to the documentation of this file.
00001 #ifndef bwi_krexec_TimeReward_h__guard
00002 #define bwi_krexec_TimeReward_h__guard
00003 
00004 #include "actasp/ExecutionObserver.h"
00005 #include "actasp/AspFluent.h"
00006 
00007 #include "RewardFunction.h"
00008 
00009 #include <map>
00010 
00011 #include <ros/time.h>
00012 
00013 namespace actasp {
00014   class PartialPolicy;
00015 }
00016 
00017 namespace bwi_krexec {
00018 
00019 template <typename State>
00020 class TimeReward : public RewardFunction<State>, public actasp::ExecutionObserver {
00021 public:
00022   double r(const State &, const actasp::AspFluent &action, const State &) const throw() {
00023         
00024     std::map<actasp::AspFluent, ros::Time>::const_iterator element = startingTimes.find(action);
00025     
00026     if(element == startingTimes.end())
00027       return 0;
00028     
00029     double reward = ros::Duration(ros::Time::now() -  element->second).toSec();
00030     
00031     return -reward ;
00032     
00033   }
00034   
00035   void actionStarted(const actasp::AspFluent& action) throw() {
00036     
00037     if( startingTimes.find(action) != startingTimes.end())
00038       startingTimes.erase(action);
00039     
00040     startingTimes.insert(std::make_pair(action,ros::Time::now()));
00041     
00042   }
00043   
00044   void actionTerminated(const actasp::AspFluent& action) throw() {
00045     
00046   }
00047   
00048   void goalChanged(std::vector<actasp::AspRule> newGoalRules) throw() {}
00049   
00050   void policyChanged(actasp::PartialPolicy* policy) throw() {}
00051 
00052   
00053   virtual ~TimeReward() {}  
00054 private:
00055   std::map<actasp::AspFluent, ros::Time, actasp::ActionComparator> startingTimes;
00056 };
00057 
00058 }
00059 
00060 #endif


bwi_kr_execution
Author(s): Matteo Leonetti, Piyush Khandelwal
autogenerated on Thu Jun 6 2019 17:57:37