0

What happens in an UML state machine if the transition selection algorithm (TSA) finds two transitions that should both fire and the following holds true:

  • transition #1 ends directly in a state
  • transition #2 ends (intermediately) in a choice pseudostate

As both the transitions fire, they cannot be in conflict. Else they would not have been chosen by the TSA in the first place.

Now the following occurs: As the choice is evaluated (after transition #2), it takes a path (transition) that would lead to the exit of an ancestor state of the source state of transition #2. Due to this exit of an ancestor state, a conflict with transition #1 occurs.

UML diagram showing such a situation

(improved according to the discussion with Thomas Kilian in comments to his (now deleted) answer)

... if Event_1 occurs and x < 0.

Example UML diagram

Questions

  • Is the state machine ill-formed or what is supposed to happen now?
  • Is it illegal for a transtions after a choice to exit a state? At least it doesn't play together well with the "transition execution sequence" (exit(s), transition behavior(s), enter(s)). As it would be exit, behavior, exit, behavior, enter(s) in that case. I could not find anything about that in the UML Superstructure Specification (chapter 15). But then everything about orthogonal regions is very vaguely described in that document...

Motivation

I am asking the question out of the perspective of a library implementer. So my focus is not on how to design this situation in a nicer manner. I need to figure out how to deal with this situation correctly (or I need to know that it is an illegal situation).

DrP3pp3r
  • 803
  • 9
  • 33

1 Answers1

2

This is one reason why there is a "Precise Semantics of UML State Machine" at the OMG...

First, it is legal for most transitions to exit a state. There are a few restrictions in the UML spec, but none that would concern your design.

You should always have a single state that is potentially active within any state machine region. As it stand, you have an implicit region in your "StateMachine1" that contains both the "X" and"Y" states. This would mean that your state machine could be in both "StateMachine1::X" and "StateMachine1::Y" states at the same time! As you probalby already know, orthogonal states are there do deal with such a situation. Perhaps you need to bring "X" and "Y" within state StateMachine1::S' regions?

Also a warning that by default in UML, states have shallow history. This means that, as it stands, the initial transitons within StateMachine1::S' regions will only be taken once. If you try to get back into "S" (I know, you don't have a transition for that - just speculating), it will go back to the last states (one per region) before if left the state, which, after event1, would be "A" and "E".

It would be difficult to comment more without knowing what you are trying to model, but I hope this helps.

CharlesRivet
  • 542
  • 2
  • 7
  • What is the "Precise Semantics of UML State Machine"? Is that a document that I should be able to find at the OMG web site? – DrP3pp3r Jun 22 '15 at 13:24
  • 1. "This would mean that your state machine could be in both [...] states at the same time!" Are you saying that this is possible in the example or that it is possible according to the UML spec? In my interpreation of the UML Superstructure Specification this is illegal. 2. "Also a warning that by default in UML, states have shallow history." I don't think this is true. The UML Spec states "A transition to the enclosing state represents a transition to the initial pseudostate in each region." – DrP3pp3r Jun 22 '15 at 13:25
  • continued... 3. "knowing what you are trying to model" The thing is: I am not trying to model anything myself right now. I am writing a state machine library. And I want to know how to handle designs of other people correctly. So my question basically is: What do I do if somebody throws at model like this at my framework? – DrP3pp3r Jun 22 '15 at 13:25
  • 1
    The Precise Semantics of UML State Machine is a request for proposals at the OMG. This means that it could eventually become an OMG standard.The goal is to formalise the semantics of state machine so the the rules for their execution is clear to everyone. – CharlesRivet Jun 25 '15 at 22:31
  • You (1): I could not find an actual constraint in the spec that specifies this. However, that construct is meaningless outside of orthogonal states. Some tools will let you draw it even though, as you state, it should be illegal and some won't. If you had transitions out of these states that would react to the same triggers, which would be executed would be undefined, and according to the UML rules, only one could be taken. This undeterministic behavior is bad form. – CharlesRivet Jun 25 '15 at 22:36
  • Regarding (2), the initial transition is only taken when no states have been taken, i.e., the first time a transition enters the state. After this, shallow history takes effect. Look at the history states. – CharlesRivet Jun 25 '15 at 22:38
  • Regarding your (3), I would then think that this is an abstract state machine (is it marked as such?) that would have to be redefined to have proper behavior. As it stands, it does contain ambiguous behavior that could cause both comprehension and runtime issues if it were to be compiles. – CharlesRivet Jun 25 '15 at 22:40
  • Not really clear if there was an answer. Should one implement some manner of constraint where an event can only be associated with one transition? Should there be a more complicated constraint where you can use an event in multiple ortho regions without exiting one? Is there some manner of timing on which transitions occur first? – Christopher Pisz May 28 '22 at 00:21