6 using namespace __gnu_cxx;
8 Planner::Planner(std::vector<Action> actions, literals init, literals goal){
11 _start = new StartNode(_init);
12 Node* finish = new EndNode(_goal);
14 for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
15 Action* act = new Action(*action);
16 const literals& effects = act->effects(0);
17 for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
18 cerr << "Adding effect: " << *effect << endl;
19 _actions[*effect] = act;
26 for (hash_map<string,Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
27 cerr << "Deleting node " << node->second->action().name() << endl;
33 void Planner::makePlan(Node* node){
36 cerr << "Fetching preconditions for action: " << node->action().name() << ".. ";
37 const literals& preconds = node->action().preconditions();
38 cerr << "done" << endl;
41 if (preconds.size() == 0){
42 cerr << "Found no preconds" << endl;
43 _start->addChild(node);
45 for (literals::const_iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
46 cerr << "Looking for: " << *precond << endl;
47 hash_map<string,Node*>::iterator addedNode = _addedNodes.find(*precond);
48 if(addedNode != _addedNodes.end()){
49 cerr << "Using already added node" << endl;
50 addedNode->second->addChild(node);
52 hash_map<string, Action*>::iterator action = _actions.find(*precond);
53 if (action != _actions.end()){
54 cerr << "Adding new node" << endl;
55 Node* newnode = new Node(*action->second);
56 newnode->addChild(node);
59 cerr << "Action with effect: " << *precond << " not found!" << endl;
66 void Planner::addNode(Node* node){
67 const literals& effects = node->action().effects(0);
69 for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
70 cout << "Adding node for effect: " << *effect << endl;
71 _addedNodes[*effect] = node;
76 void Planner::execute(){
77 _start->execute(literals());
78 for (hash_map<string,Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){