#include "action.h"
Action::Action(std::string executable, literals preconditions, literals effects){
- _execututable = executable;
+ _executable = executable;
_preconditions = preconditions;
_effects = effects;
}
+Action::Action(const Action& action){
+ _executable = action._executable;
+ _preconditions = action._preconditions;
+ _effects = action._effects;
+}
-const literals Action::effects(){
+literals Action::effects() const{
return _effects;
}
-const literals Action::preconditions(){
+literals Action::preconditions() const{
return _preconditions;
}
-int Action::execute(){
+int Action::execute() const{
return 0;
}
#ifndef __ACTION_H__
#define __ACTION_H__
-typedef literals std::vector<string>;
+#include <vector>
+#include <string>
+
+typedef std::vector<std::string> literals;
class Action {
public:
Action(std::string executable, literals preconditions, literals effects);
- const literals effects() const;
- const literals preconditions() const;
+ Action(const Action& action);
+ Action(){};
+ literals effects() const;
+ literals preconditions() const;
int execute() const;
protected:
#include "node.h"
-Node::Node(Action action, std::vector<Node&> children){
+Node::Node(Action action){
_action = action;
- _children = children;
}
class Node {
- Node(Action action, std::vector<Node&> children);
-
- addChild(Node& node);
+ public:
+ Node(Action action);
+ void addChild(Node* node);
protected:
Action _action;
- std::vector<Node&> _children;
+ std::vector<Node*> _children;
};
#endif
#include "planner.h"
+#include "node.h"
+using namespace std;
+Planner::Planner(std::vector<Action> actions, literals init, literals goal){
+ _start = new Node(Action("",init, literals()));
+ Node* finish = new Node(Action("",literals(),goal));
+
+ for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
+ literals preconds = action->preconditions();
+ for (literals::iterator effect = preconds.begin(); effect != preconds.end(); ++effect){
+ _actions[*effect] = *action;
+ }
+ }
+}
+
+
+void Planner::makePlan(Node* node){
+}
#ifndef __PLANNER_H__
#define __PLANNER_H__
-#include <hash_map>
-#include "node.h"
+#include <ext/hash_map>
+#include <vector>
+#include "action.h"
+
+class Node;
+
+
+
+namespace __gnu_cxx {
+
+ template< typename CharT, typename Traits, typename Alloc >
+ struct hash< std::basic_string<CharT, Traits, Alloc> > {
+ size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+
+ const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
+
+ return c.hash(s.c_str(), s.c_str() + s.size());
+
+}
+
+ };
+
+ template< typename CharT, typename Traits, typename Alloc >
+ struct hash< const std::basic_string<CharT, Traits, Alloc> > { //yes you need this version aswell!
+
+size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+
+ const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
+
+ return c.hash(s.c_str(), s.c_str() + s.size());
+ }
+
+ };
+};
class Planner {
public:
+ Planner(std::vector<Action> actions, literals init, literals goal);
protected:
- Node start;
- std::hash_map<string,Node*> addedNodes;
+
+ void makePlan(Node* node);
+
+ Node* _start;
+ __gnu_cxx::hash_map<std::string,Node*> _addedNodes;
+ __gnu_cxx::hash_map<std::string,Action> _actions;
};
#endif
--- /dev/null
+######################################################################
+# Automatically generated by qmake (1.07a) Fri May 6 20:04:49 2005
+######################################################################
+
+TEMPLATE = app
+INCLUDEPATH += .
+
+# Input
+HEADERS += action.h node.h planner.h
+SOURCES += action.cpp main.cpp node.cpp planner.cpp