]> ruin.nu Git - popboot.git/blobdiff - planner.cpp
references instead of copies
[popboot.git] / planner.cpp
index a15028e29a3175e8fa316e2e6e6a37e2dc41194f..cf7801520883ac9e94cf62b958884fc8d95f369b 100644 (file)
@@ -11,8 +11,8 @@ Planner::Planner(std::vector<Action> actions, literals init, literals goal){
        Node* finish = new Node(Action("finish",goal,literals()));
 
        for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
-               literals effects = action->effects();
-               for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
+               const literals& effects = action->effects();
+               for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
                        cerr << "Adding effect: " << *effect << endl;
                        _actions[*effect] = *action;
                }
@@ -22,13 +22,15 @@ Planner::Planner(std::vector<Action> actions, literals init, literals goal){
 
 
 void Planner::makePlan(Node* node){
-       literals preconds = node->action().preconditions();
+       cerr << "Fetching preconditions for action: " << node->action().executable() << ".. ";
+       const literals& preconds = node->action().preconditions();
+       cerr << "done" << endl;
 
        if (preconds.size() == 0){
                cerr << "Found no preconds" << endl;
                _start->addChild(node);
        }else{
-               for (literals::iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
+               for (literals::const_iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
                        cerr << "Looking for: " << *precond << endl;
                        hash_map<string,Node*>::iterator addedNode = _addedNodes.find(*precond);
                        if(addedNode != _addedNodes.end()){
@@ -51,9 +53,9 @@ void Planner::makePlan(Node* node){
 }
 
 void Planner::addNode(Node* node){
-       literals effects = node->action().effects();
+       const literals& effects = node->action().effects();
 
-       for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
+       for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
                cout << "Adding node for effect: " << *effect << endl;
                _addedNodes[*effect] = node;
        }