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<const std::set<FluentClass>&,const 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 
00044 
00045 }
00046 
00047 #endif


bwi_kr_execution
Author(s): Matteo Leonetti, Piyush Khandelwal
autogenerated on Fri Aug 28 2015 10:14:46