matthewryanscott / CarlAdam

Petri net modeling and simulation for Python using immutable data structures
MIT License
5 stars 1 forks source link

Expose effects of a transition occurrence, for direct inspection and enhanced simulation #10

Closed matthewryanscott closed 7 months ago

matthewryanscott commented 7 months ago

Current

You have a Petri net instance, and you can get a marking_after_transition based on a marking and a transition.

However, the mechanism of constructing the new marking is internal to this function and can only be tested as a black box. Its internal algorithm also cannot be exploited for any other purpose than to get a new marking.

This means that you have to infer what the function did by comparing the input and output markings.

Desired

You have a Petri net instance, and you can get the transition_effects for a given marking and transition. Those effects are a list of operations that can be applied

You can call apply_effects(marking, effects) and it will return a new marking with the effects applied.

Therefore, the implementation of marking_after_transition would be reduced to:

def marking_after_transition(self, marking, transition):
    effects = self.transition_effects(marking, transition)
    return apply_effects(marking, effects)

You can also directly inspect the effects in tests, and they could also be used as a basis for showing additional context & animations in a simulator.

matthewryanscott commented 7 months ago

After some playing around with this my current thought is to have a TransitionOccurrence class that will encapsulate this.

henriquebastos commented 7 months ago

The high-level concept makes sense.

But I would need to see a concrete example to reason about this.

Isn't it strange that we are talking about marking evolution and yet we would express it as a “transition occurrence”?