void PnpPlanTemplate<PnpPlaceClass, PnpTransitionClass>::executeStep() { PNP_OUT("\nEXECUTESTEP of plan '"<<getPlanName()<<"'"); if (isInGoalState()) { std::map<std::string,std::string>::iterator it = activePlaces.find(getPlanName()); if (it != activePlaces.end()) activePlaces.erase(it); PNP_OUT("Goal reached!"); return; } else if (isInFailState()) { std::map<std::string,std::string>::iterator it = activePlaces.find(getPlanName()); if (it != activePlaces.end()) activePlaces.erase(it); PNP_OUT("Plan failed"); return; } std::map<std::string,std::string>::iterator it = activePlaces.find(getPlanName()); if (it != activePlaces.end()) activePlaces.erase(it); std::set<PnpPlace*> nepForTest = this->getNonEmptyPlaces(); std::string places; places = ""; for (std::set<PnpPlace*>::iterator it = nepForTest.begin(); it != nepForTest.end(); ++it) { places += (*it)->pnmlString + ";"; } activePlaces.insert(make_pair(getPlanName(),places)); #if PNP_OUTPUT_ENABLED std::set<PnpPlace*> nepForTest2 = this->getNonEmptyPlaces(); PNP_OUT("Current active places:"); for (std::set<PnpPlace*>::iterator it = nepForTest2.begin(); it != nepForTest2.end(); ++it) { PNP_OUT(" " << (*it)->nodeId << " \"" << (*it)->pnmlString << "\""); } #endif executeAllActiveActions(); fireAllEnabledTransitions(); if(this->observer != NULL) this->observer->markingChanged(this->currentMarking()); }
void PnpPlanTemplate<PnpPlaceClass, PnpTransitionClass>::fail() { std::map<std::string,std::string>::iterator it = activePlaces.find(getPlanName()); if (it != activePlaces.end()) activePlaces.erase(it); //call end() on each active executable MapSecondArgument<std::string, PnpExecutable, void> callEnd(std::mem_fun(&PnpExecutable::end)); for_each(activeExecutables.begin(), activeExecutables.end(), callEnd); //move them to the inactive map inactiveExecutables.insert(activeExecutables.begin(), activeExecutables.end()); activeExecutables.clear(); }
PnpPlanTemplate<PnpPlaceClass, PnpTransitionClass>::~PnpPlanTemplate() { PNP_OUT("Destroying plan '"<<getPlanName()<<"'"); for (std::map<std::string, PnpExecutable*>::iterator it = inactiveExecutables.begin(); it != inactiveExecutables.end(); ++it) { PNP_OUT(" Destroying sub-executable '"<<it->first<<"'"); delete it->second; } for (std::map<std::string, PnpExecutable*>::iterator it = activeExecutables.begin(); it != activeExecutables.end(); ++it) { PNP_OUT(" Destroying sub-executable '"<<it->first<<"'"); delete it->second; } }
bool PnpPlanTemplate<PnpPlaceClass, PnpTransitionClass>::isInGoalState() const { bool noGoalMarking = true; std::set<PnpPlace*>::iterator p_iter=PetriNet<PnpPlaceClass, PnpTransitionClass>::places.begin(); for(;p_iter!=PetriNet<PnpPlaceClass, PnpTransitionClass>::places.end();p_iter++) { PnpPlace* p = *p_iter; if (p->goalMarking == -1) continue; else { noGoalMarking = false; if (p->currentMarking!=(size_t)p->goalMarking) return false; } } if (noGoalMarking) return false; else { std::map<std::string,std::string>::iterator it = activePlaces.find(getPlanName()); if (it != activePlaces.end()) activePlaces.erase(it); return true; } }