_effects = action._effects;
}
-literals Action::effects() const{
+const literals& Action::effects() const{
return _effects;
}
-literals Action::preconditions() const{
+const literals& Action::preconditions() const{
return _preconditions;
}
cout << "Executing: " << _executable << endl;
return 0;
}
+
+const string& Action::executable() const{
+ return _executable;
+}
Action(std::string executable, literals preconditions, literals effects);
Action(const Action& action);
Action(){};
- literals effects() const;
- literals preconditions() const;
+ const literals& effects() const;
+ const literals& preconditions() const;
+ const std::string& executable() const;
int execute() const;
protected:
getline(file,effects);
getline(file,precond);
cout << exec << ":" << effects << ":" << precond << endl;
+ if (effects == "") continue;
actions.push_back(Action(exec, stringToVector(precond), stringToVector(effects)));
}
Planner p(actions, stringToVector(argv[2]), stringToVector(argv[3]));
_preconditions = _action.preconditions();
}
-Action Node::action(){
+const Action& Node::action() const{
return _action;
}
}
-void Node::execute(literals effects){
- for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
+void Node::execute(const literals& effects){
+ for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
_preconditions.erase(find(_preconditions.begin(),_preconditions.end(), *effect));
}
if (_preconditions.size() != 0)
public:
Node(Action action);
void addChild(Node* node);
- Action action();
- void execute(literals effects);
+ const Action& action() const;
+ void execute(const literals& effects);
protected:
Action _action;
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;
}
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()){
}
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;
}
CONFIG += debug
INCLUDEPATH += .
TARGET = planner
+#LIBS += -lpthread
# Input
HEADERS += action.h node.h planner.h