# Copyright 2026 Paul Griffioen # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import petri_net; include net_behavior; # ------------------------------------------------------------------------------ # Simple net # # A test net with three places and three transitions: # # ____ # +---------->/ p1 \----------+ # | \____/ | # | | # | +---------+ | # | | t0 | | # | +---------+ | # | | v # +--------+ _v__ +--------+ # | t1 |<---->/ p0 \<---->| t2 | # +--------+ \____/ +--------+ # ^ | | # | ____ | | # +-----------/ p2 \<--------+---+ # \____/ # # # - Initially only t0 is enabled # - If p0 contains no tokens then t1 and t2 cannot run # - If p0 contains one token then t1 and t2 cannot run in parallel # - If p0 contains n tokens then t1 and t2 can run in parallel. The sum of # their frequencies is bounded by n. # # ------------------------------------------------------------------------------ defunit token "tkn"; defindex Place = {p0, p1, p2}; defindex Transition = {t0, t1, t2}; defmatrix pre :: token * Place! per Transition! = { p0, t1 -> 1, p2, t1 -> 1, p0, t2 -> 1, p1, t2 -> 1 }; defmatrix post :: token * Place! per Transition! = { p0, t0 -> 1, p0, t1 -> 1, p1, t1 -> 1, p0, t2 -> 1, p2, t2 -> 2 }; defmatrix initial_state :: token * Place! = { p1 -> 1, p2 -> 1 }; declare test_net :: PetriNet(token, Place!, Transition!); define test_net = make_petri_net(pre, post, initial_state); # ------------------------------------------------------------------------------ # A test run # ------------------------------------------------------------------------------ define my_trace = parallel_trace([ [tuple(Transition@t0, 2)], [tuple(Transition@t1, 1), tuple(Transition@t2, 1)], [tuple(Transition@t1, 2)] ]); print_summary(run_petri_net_trace_verbose(test_net, my_trace));