-1

I am currently writing a generic statemachine. But I have a couple of understanding problems.

Say I have a state A. A transitions to B if a condition is met. A also has a substate A1. A1 transitions to state C if a condition is met.

Do I transition to B or C if both conditions are met and the active state is A1? Also do I have to run the repetitive running task of A since A is technically also active?

Yamira
  • 15
  • 7
  • What is substate versus state here? Generally there is only state. – Gerhard Apr 04 '22 at 12:11
  • @Gerhard I'd guess it's about nested states in UML terminology. – Wolf Apr 04 '22 at 12:14
  • 1
    The only answer I can think of is “it depends”. It depends on the rules required by the state machine being interpreted. There is no single answer that's universally correct. If a single input event triggers two different state transitions, the design of the state machine is suspect. – Jonathan Leffler Apr 04 '22 at 12:15
  • It is a UML statemachine. – Yamira Apr 04 '22 at 12:17
  • For the conditions, think of an timeout for state A and for example an event for A1. Both are valid conditions that are sensible. – Yamira Apr 04 '22 at 12:19
  • 3
    For a *generic* solution, we need a way to specify a state machine, including inputs, transitions and transition side effects. – Wolf Apr 04 '22 at 12:19
  • 1
    You should translate *conditions* into *inputs* (or you may call it *events*). After that, you'll see that different inputs (probably) cannot be read simultaneously. BTW: while you name states in your example, you should also name inputs. It would really help to update (i.e. [edit](https://stackoverflow.com/posts/71736448/edit)) your question for clarification. – Wolf Apr 04 '22 at 12:39
  • Related questions are: https://stackoverflow.com/q/133214/2932052 and https://stackoverflow.com/q/1647631/2932052 – Wolf Apr 04 '22 at 14:05
  • Both related questions have nothing to do with my problem. The whole solution contains ways to specify states, events and transitions but it is not relevant to my question. – Yamira Apr 04 '22 at 14:15

2 Answers2

1

In order for a state machine to be Deterministic, all the transitions out of a given state (including it's 'substates' which is really just a shorthand for defining states with similar transitions) must be mutually exclusive. If they are not mutually exclusive, you have a Non-Deterministic state machine. Such machines are perfectly reasonable, but harder to evaluate -- at any given time it can be in any set of states (rather than just a single state), and every transition that is possible from any of states in the current set of states is relevant for finding the next set of states. So in your example, you would go from being in states {A1} to states {B,C}

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
0

After some more research I found this article that answers my question in chapter 2.10.

Crashcourse UML Statemachines

Shortly it depends which event occurs first, the timeout or the second event.

Yamira
  • 15
  • 7
  • That's what I suggested: turn “conditions” into “events” aka “inputs” and then see what happens first. Your question is very vague about this specific problem. If one already knows your actual question, the title and text seem understandable. But this one-way street points in the wrong direction. I would really recommend putting your hand on the question again; also, the answer looks a bit too much like “note to self”. – Wolf Apr 05 '22 at 08:00
  • Two aspects are still open with this answer: generalization (*“generic statemachine”*) and how to do it in C. – Wolf Apr 05 '22 at 08:06