具有自转换但不同进入动作的状态机

发布于 2024-11-04 08:26:46 字数 212 浏览 0 评论 0原文

我有一个状态机,其中

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕烟庭风 2024-11-11 08:26:46

同一状态下不能有两个替代输入操作。重点是该州与您到达那里的路线无关。您有两个选择:

  1. 将操作放在转换上。 UML 允许转换由 3 部分组成:
    • 触发事件
    • 守卫条件
    • 如果事件发生且守卫为 true 则执行的操作。该操作在转换到目标状态之前完成。
  2. 创建另外 2 个状态,每个状态对应 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:

  1. Put the actions on the transitions. UML allows a transition to have 3 parts:
    • a triggering event
    • a guard condition
    • an action executed if the event occurs and the guard is true. The action is completed before the transition to the target state occurs.
  2. Create 2 further states, one for each of action1() & action2(). State S1 would have two exiting transitions, one to each of the new states. Transition 1 would be labelled X[Y] and lead to state containing action1(). Similar for action2(). 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文