iocchi / PetriNetPlans

Petri Net Plans library and applications
31 stars 15 forks source link

Only one fail and one goal place possible?! #18

Open cdondrup opened 8 years ago

cdondrup commented 8 years ago

Hi,

Assuming I create a linear plan where multiple sensing actions can end in a place called fail this should terminate the plan execution. However, this line of code prevents this. If I have two fail states in my plan, This will always return false because the p->currentMarking can only be 1 for one of the fail places which means the other triggers the if. Just replacing this line with a break; fixes the problem. Is there a specific reason why this check is in there? Otherwise, when applying the execution rule it would have to be ensured that every fail_plan creates an arc to the one and only fail place which currently is not the case.

The same is true for the goal because it has a similar check, therefore, there can only be one goal state.

cdondrup commented 8 years ago

Was a bit too quick with my solution but replacing this:

template<typename PnpPlaceClass, typename PnpTransitionClass>
bool PnpPlanTemplate<PnpPlaceClass, PnpTransitionClass>::isInFailState() const
{
    bool noFailMarking = 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->failMarking == -1) continue;
        else {
            noFailMarking = false;
            if (p->currentMarking!=(size_t)p->failMarking) return false;
        }
    }
    if (noFailMarking) return false;
    else return true;
}

with this

template<typename PnpPlaceClass, typename PnpTransitionClass>
bool PnpPlanTemplate<PnpPlaceClass, PnpTransitionClass>::isInFailState() const
{
    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->currentMarking) return p->failMarking == 1 ? true : false;
    }
    return false;
}

in pnp_plan.hpp fixes the problem for me. The same could be done for the goal. Again, I am not sure why the check was there in the first place and what implications it would have to remove it so I leave it to you if this should be changed or not.