具有自转换但不同进入动作的状态机
我有一个状态机,其中
S1--->inp X,保护条件 = Y---->S1 (执行后自动转换到 S1,action1()
S1--->inp X,保护条件 = !Y---->S1(执行后自我转换S1,action2()
所以两个输入之间的唯一区别是它正在执行不同的操作,
我觉得这里出了问题,我应该做一些不同的事情吗?
I have a state machine, where
S1--->inp X, guard condition = Y---->S1 (self transition to S1 after executing, action1()
S1--->inp X, guard condition = !Y---->S1 (self transition S1 after executing, action2()
So the only difference between the two inputs is that it is executing a different action,
I feel something is wrong here, should I be doing something different ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同一状态下不能有两个替代输入操作。重点是该州与您到达那里的路线无关。您有两个选择:
action1()
&action2()
。状态 S1 将有两个退出转换,每个新状态一个。转换 1 将标记为X[Y]
并导致包含action1()
的状态。与action2()
类似。每个新状态都会转换回 S1,该状态在操作完成后立即执行。如果图表是概念性的,那么您的选择很大程度上取决于风格。如果您直接翻译为代码,那么您需要考虑语义。选项(1)在视觉上更简洁,但这意味着转换不会是“瞬时的”。对于某些环境 - 特别是实时/嵌入式 - 这可能很重要。
嗯。
You can't have two alternate entry actions in the same state. Whole point is the state is independent of the route you got there. You have two options:
action1()
&action2()
. State S1 would have two exiting transitions, one to each of the new states. Transition 1 would be labelledX[Y]
and lead to state containingaction1()
. Similar foraction2()
. Each new state would have a transition back to S1 which was executed as soon as the action was complete.Which you choose is largely stylistic if the diagram is conceptual. If you're translating directly to code then you'll need to consider semantics. Option (1) is more concise visually, however it means the transition will not be 'instantaneous'. For some environments - especially real-time / embedded - that may be significant.
hth.