5 using namespace __gnu_cxx;
7 Planner::Planner(std::vector<Action> actions, literals init, literals goal){
9 _start = new Node(Action("",init, literals()));
10 Node* finish = new Node(Action("",literals(),goal));
12 for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
13 literals preconds = action->preconditions();
14 for (literals::iterator effect = preconds.begin(); effect != preconds.end(); ++effect){
15 _actions[*effect] = *action;
22 void Planner::makePlan(Node* node){
23 literals preconds = node->action().preconditions();
25 if (preconds.size() == 0){
26 _start->addChild(node);
28 for (literals::iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
29 hash_map<string,Node*>::iterator addedNode = _addedNodes.find(*precond);
30 if(addedNode != _addedNodes.end()){
31 addedNode->second->addChild(node);
33 hash_map<string, Action>::iterator action = _actions.find(*precond);
34 if (action != _actions.end()){
35 Node* newnode = new Node(action->second);
36 newnode->addChild(node);
39 cerr << "Action with effect: " << *precond << " not found!";
46 void Planner::addNode(Node* node){
47 literals effects = node->action().effects();
49 for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
50 _addedNodes[*effect] = node;