5 using namespace __gnu_cxx;
7 Planner::Planner(std::vector<Action> actions, literals init, literals goal){
9 _start = new Node(Action("start",literals(), init));
11 Node* finish = new Node(Action("finish",goal,literals()));
13 for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
14 const literals& effects = action->effects();
15 for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
16 cerr << "Adding effect: " << *effect << endl;
17 _actions[*effect] = *action;
24 for (hash_map<string,Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
25 cerr << "Deleting node " << node->second->action().executable() << endl;
31 void Planner::makePlan(Node* node){
32 cerr << "Fetching preconditions for action: " << node->action().executable() << ".. ";
33 const literals& preconds = node->action().preconditions();
34 cerr << "done" << endl;
36 if (preconds.size() == 0){
37 cerr << "Found no preconds" << endl;
38 _start->addChild(node);
40 for (literals::const_iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
41 cerr << "Looking for: " << *precond << endl;
42 hash_map<string,Node*>::iterator addedNode = _addedNodes.find(*precond);
43 if(addedNode != _addedNodes.end()){
44 cerr << "Using already added node" << endl;
45 addedNode->second->addChild(node);
47 hash_map<string, Action>::iterator action = _actions.find(*precond);
48 if (action != _actions.end()){
49 cerr << "Adding new node" << endl;
50 Node* newnode = new Node(action->second);
51 newnode->addChild(node);
55 cerr << "Action with effect: " << *precond << " not found!" << endl;
62 void Planner::addNode(Node* node){
63 const literals& effects = node->action().effects();
65 for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
66 cout << "Adding node for effect: " << *effect << endl;
67 _addedNodes[*effect] = node;
72 void Planner::execute(){
73 _start->execute(literals());