From b177aeec472c3941b39b874a83883ff87a41919c Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 6 May 2005 19:27:57 +0000 Subject: [PATCH] compiles again --- node.cpp | 10 ++++++++++ node.h | 1 + planner.cpp | 32 ++++++++++++++++++++++++++++++++ planner.h | 1 + 4 files changed, 44 insertions(+) diff --git a/node.cpp b/node.cpp index 11fed08..4f81069 100644 --- a/node.cpp +++ b/node.cpp @@ -3,3 +3,13 @@ Node::Node(Action action){ _action = action; } + +Action Node::action(){ + return _action; +} + + +void Node::addChild(Node* node){ + _children.push_back(node); +} + diff --git a/node.h b/node.h index 55e34e6..31568fc 100644 --- a/node.h +++ b/node.h @@ -9,6 +9,7 @@ class Node { public: Node(Action action); void addChild(Node* node); + Action action(); protected: Action _action; diff --git a/planner.cpp b/planner.cpp index c5016a1..3e8d5de 100644 --- a/planner.cpp +++ b/planner.cpp @@ -1,6 +1,8 @@ #include "planner.h" #include "node.h" +#include using namespace std; +using namespace __gnu_cxx; Planner::Planner(std::vector actions, literals init, literals goal){ @@ -13,8 +15,38 @@ Planner::Planner(std::vector actions, literals init, literals goal){ _actions[*effect] = *action; } } + makePlan(finish); } void Planner::makePlan(Node* node){ + literals preconds = node->action().preconditions(); + + if (preconds.size() == 0){ + _start->addChild(node); + }else{ + for (literals::iterator precond = preconds.begin(); precond != preconds.end(); ++precond){ + hash_map::iterator addedNode = _addedNodes.find(*precond); + if(addedNode != _addedNodes.end()){ + addedNode->second->addChild(node); + }else { + hash_map::iterator action = _actions.find(*precond); + if (action != _actions.end()){ + Node* newnode = new Node(action->second); + newnode->addChild(node); + makePlan(newnode); + }else{ + cerr << "Action with effect: " << *precond << " not found!"; + } + } + } + } +} + +void Planner::addNode(Node* node){ + literals effects = node->action().effects(); + + for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){ + _addedNodes[*effect] = node; + } } diff --git a/planner.h b/planner.h index 7932eb9..c74d536 100644 --- a/planner.h +++ b/planner.h @@ -43,6 +43,7 @@ class Planner { protected: void makePlan(Node* node); + void addNode(Node* node); Node* _start; __gnu_cxx::hash_map _addedNodes; -- 2.39.2