state_utils.h
Go to the documentation of this file.
00001 
00002 
00003 #ifndef actasp_state_util_h__guard
00004 #define actasp_state_util_h__guard
00005 
00006 #include <actasp/AspFluent.h>
00007 
00008 #include <functional>
00009 #include <set>
00010 
00011 namespace actasp {
00012 
00013 template<typename FluentClass> //typically AspFluent, possibly AspFluentRef
00014 struct StateComparator : public std::binary_function<std::set<FluentClass>,std::set<FluentClass>, bool> {
00015     
00016   bool operator()(const std::set<FluentClass> &first,const std::set<FluentClass> &second) const {
00017 
00018 
00019     if (first.size() != second.size())
00020       return first.size() < second.size();
00021 
00022     //they have the same number of fluents
00023     typename std::set<FluentClass>::const_iterator thisV = first.begin();
00024     typename std::set<FluentClass>::const_iterator otherV = second.begin();
00025 
00026     ActionComparator lessThen; //ignores the time steps!
00027 
00028     for (; thisV != first.end(); ++thisV, ++otherV) {
00029       //this comparison is costly, so I'm using this unelegant expression to minimize the calls to it.
00030       if (lessThen(*thisV , *otherV))
00031         return true;
00032       if (lessThen(*otherV , *thisV))
00033         return false;
00034     }
00035 
00036     //they are the same
00037     return false;
00038 
00039   }
00040     
00041 };
00042 
00043 //assumes fluents are in the same order. 
00044 //equals if everything else than timestep is equal.
00045 struct stateEquals {
00046 
00047   stateEquals(const std::set<AspFluent>& state) : state(state) {}
00048 
00049   bool operator()(const std::set<AspFluent>& otherstate) const;
00050 
00051   std::set<AspFluent> state;
00052 };  
00053 
00054 
00055 }
00056 
00057 #endif


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