fpom / snakes

SNAKES is the Net Algebra Kit for Editors and Simulators
https://snakes.ibisc.univ-evry.fr
Other
89 stars 29 forks source link

Transition with Inhibitor arc is firing although token is in place #19

Closed maxhoerstr closed 4 years ago

maxhoerstr commented 4 years ago

I have a simple test scenario with 2 places and a transition. The first place is connected with the transition over an inhibitor arc. If I add a token to the first place and try to fire the transition it fires. It also fires if nothing is there which is what it should do. I cant figure out though why the transition fires when there is a token in place.

Here is the example code:

from snakes.nets import *

def main():
    net = PetriNet("net")
    net.add_place(Place("place1", [0]))
    net.add_place(Place("place2", [0]))
    net.add_transition(Transition("transition"))
    net.add_input("place1", "transition", Inhibitor(Value(1)))
    net.add_output("place2", "transition", Value(1))
    net.place("place1").add(Value(1))

    try:
        net.transition("transition").fire(Value(1))
        print("fired");
    except:
        print("error")

if __name__ == '__main__':
    main()

Is this the expected behavior and if so what can i do to realize a net that don't fire if a token is in a place.

Thanks in advance

fpom commented 4 years ago

There's several problems and bugs actually.

  1. Method fire() expects a Substitution object as its argument, because no arc as actually variables on it, object Value(1) is not used during the firing and fire works happily.
  2. You should not add Value(1) to the marking of a place: Value is for an arc annotation and is not supposed to be a token. Just use add(1) to add integer 1 to the place. Even if there would be no bug in fire() the transition would be enabled because Value(1) is not 1 and the inhibitor arc refuses the latter.
  3. fire() should not work indeed because the transition is not enabled, and indeed using net.transition("transition").modes() returns an empty list: no mode is available for this transition. So I need to perform additional checks in fire() to fix this bug.
maxhoerstr commented 4 years ago

Thank you very much for your quick response. Can you estimate how long it would take to fix the bug?

fpom commented 4 years ago

Fixed in 13f8c40. ;)

maxhoerstr commented 4 years ago

Can you also publish it to pypi? ;-) This would be also really nice! Merci!

fpom commented 4 years ago

Yep, that's done.