5 using namespace __gnu_cxx;
7 Planner::Planner(std::vector<Action> actions, literals init, literals goal){
9 _start = new Node(Action("",literals(), init));
10 Node* finish = new Node(Action("",goal,literals()));
12 for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
13 literals effects = action->effects();
14 for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
15 cerr << "Adding effect: " << *effect << endl;
16 _actions[*effect] = *action;
23 void Planner::makePlan(Node* node){
24 literals preconds = node->action().preconditions();
26 if (preconds.size() == 0){
27 cerr << "Found no preconds" << endl;
28 _start->addChild(node);
30 for (literals::iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
31 cerr << "Looking for: " << *precond << endl;
32 hash_map<string,Node*>::iterator addedNode = _addedNodes.find(*precond);
33 if(addedNode != _addedNodes.end()){
34 cerr << "Using already added node" << endl;
35 addedNode->second->addChild(node);
37 hash_map<string, Action>::iterator action = _actions.find(*precond);
38 if (action != _actions.end()){
39 cerr << "Adding new node" << endl;
40 Node* newnode = new Node(action->second);
41 newnode->addChild(node);
45 cerr << "Action with effect: " << *precond << " not found!" << endl;
52 void Planner::addNode(Node* node){
53 literals effects = node->action().effects();
55 for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
56 cout << "Adding node for effect: " << *effect << endl;
57 _addedNodes[*effect] = node;