symbolicState.h
Go to the documentation of this file.
00001 #ifndef SYMBOLIC_STATE_H
00002 #define SYMBOLIC_STATE_H
00003 
00004 #include <boost/foreach.hpp>
00005 #ifdef __CDT_PARSER__
00006 #define forEach(a, b) for(a : b)
00007 #else
00008 #define forEach BOOST_FOREACH
00009 #endif
00010 #include <math.h>
00011 
00012 #include <stdarg.h>
00013 #include <string>
00014 #include <deque>
00015 #include <vector>
00016 #include <map>
00017 #include <utility>
00018 using std::string;
00019 using std::deque;
00020 using std::vector;
00021 using std::map;
00022 using std::multimap;
00023 using std::pair;
00024 using std::make_pair;
00025 #include <ostream>
00026 
00027 inline bool double_equals(double d1, double d2)
00028 {
00029     return fabs(d1 - d2) < 0.0001;
00030 }
00031 
00033 
00034 class Predicate
00035 {
00036     public:
00037         string name;
00038         vector<string> parameters;
00039 
00040         bool operator<(const Predicate & p) const;
00041 };
00042 std::ostream & operator<<(std::ostream & os, const Predicate & p);
00043 
00045 
00050 class SymbolicState
00051 {
00052     public:
00053         friend std::ostream & operator<<(std::ostream & os, const SymbolicState & ss);
00054         class OStreamMode {
00055             public:
00056                 static bool forceNewlines;
00057         };
00058 
00059         SymbolicState();
00060         virtual ~SymbolicState();
00061 
00062         typedef multimap<string,string>::iterator TypedObjectIterator;
00063         typedef multimap<string,string>::const_iterator TypedObjectConstIterator;
00064 
00065         void clear() {
00066             _typedObjects.clear();
00067             _booleanPredicates.clear();
00068             _numericalFluents.clear();
00069             _objectFluents.clear();
00070         }
00071 
00072         // Setter/Getter
00073 
00075 
00079         void addObject(string obj, string type);
00080 
00082         void addSuperType(string type, string supertype);
00083 
00085         void printSuperTypes() const;
00086 
00088 
00091         void removeObject(string obj, bool removePredicates = true);
00092 
00094         const multimap<string, string> & getTypedObjects() const { return _typedObjects; }
00095 
00096 
00098         void setBooleanPredicate(string name, vector<string> parameters, bool value);
00100 
00104         void setBooleanPredicate(string name, string parameters, bool value);
00106         void setAllBooleanPredicates(string name, bool value);
00107 
00109         void setNumericalFluent(string name, vector<string> parameters, double value);
00111         void setNumericalFluent(string name, string parameters, double value);
00113         void setAllNumericalFluents(string name, double value);
00114 
00116         void setObjectFluent(string name, vector<string> parameters, string value);
00118         void setObjectFluent(string name, string parameters, string value);
00120         void setAllObjectFluents(string name, string value);
00121 
00124         void setForEachGoalStatement(string objectType, string predicateName, bool value);
00125 
00127 
00130         bool hasBooleanPredicate(const Predicate & p, bool* value) const;
00131         bool hasNumericalFluent(const Predicate & p, double* value) const;
00132         bool hasObjectFluent(const Predicate & p, string* value) const;
00133 
00134         // state matching
00135 
00137 
00147         bool isFulfilledBy(const SymbolicState & other) const;
00148 
00150         bool booleanEquals(const SymbolicState & other) const;
00152         bool numericalEquals(const SymbolicState & other) const;
00154         bool objectFluentsEquals(const SymbolicState & other) const;
00156         bool equals(const SymbolicState & other) const;
00157 
00158         // conversion/writing
00159 
00161         virtual void toPDDLProblem(std::ostream & ss) const;
00163         virtual void toPDDLGoal(std::ostream & ss) const;
00164 
00165     protected:
00167         vector<string> buildParameterList(string params) const;
00168 
00170 
00176         bool isMostSpecificType(string obj, string type) const;
00177 
00178     protected:
00180 
00184         multimap<string, string> _typedObjects;
00185 
00186         multimap<string, string> _superTypes;      
00187 
00188         // The only possible parameters for the following predicates should be those in the _typedObjects list.
00189         // matched strings in _objectFluents should also only be from _typedObjects and of the correct type
00190         map<Predicate, bool> _booleanPredicates;
00191         map<Predicate, double> _numericalFluents;
00192         map<Predicate, string> _objectFluents;
00193         // foreach statements
00194         typedef multimap<string, pair<string, bool> > ForEachGoalStatements;
00195         ForEachGoalStatements _forEachGoalStatements;
00196 
00197         typedef map<Predicate, bool>::value_type BooleanPredicateEntry;
00198         typedef map<Predicate, double>::value_type NumericalFluentEntry;
00199         typedef map<Predicate, string>::value_type ObjectFluentEntry;
00200 };
00201 
00202 std::ostream & operator<<(std::ostream & os, const SymbolicState & ss);
00203 
00204 #endif
00205 


continual_planning_executive
Author(s): Christian Dornhege
autogenerated on Mon Oct 6 2014 07:51:56