如何建模两个并行动作 [英] how to model two parallel actions

查看:90
本文介绍了如何建模两个并行动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们需要创建一个模型来说明做A和做B同时进行。它们从相同的初始状态开始,可以并行发生。他们停在相同的结局状态。在下图中,A-> B和A-> C可以同时发生。
当他们到达最终状态D时,他们将同时拥有B和C的值。


我们应该怎么做?


解决方案

xyzBecca,


首先,我想了解您对此并行建模的要求。你说他们可以在同一时间发生,这是否意味着他们应该总是在同一时间发生?如果你不关心谁首先出现,一个典型的方式可能是你的图表显示:
没有关于谁首先发生的约束,但是一个动作只能发生一次。例如,您可以编写如下代码:




static bool NotExecutedA = true;

static bool NotExecutedB = true;


[规则]

静态无效A()

{

  Condition.IsTrue( NotExecutedA);

  NotExecutedA = false;

}


[规则]

静态无效A()

{

  Condition.IsTrue(NotExecutedB);

  NotExecutedB = false;

}


如果在测试运行时,它们确实需要并行发生,您还可以将A和B抽象为一个动作(例如ExecuteAandB),并让适配器处理并行调用。 / p>

让我知道它是否有效。


谢谢,



Hi,

we need to create a model to illustrate doing A and doing B at same time. They start from the same initial state, and can happen in parallel. And they stop at the same ending state. In the following figure, A->B and A->C can happen at the same time. When they go to the end state D, they will have both value from B and C.

How should we do this?

解决方案

Hi, xyzBecca,

First I want to know your requirement of this parallel modeling. You said they can happen at the same time, does that mean they should always happen at the same time? If you do not care who occurs first, a typical way can be what your graph shows: there is no constraint about who occurs first, but one action can only occur once. For example, you can write the code like this:


static bool NotExecutedA=true;
static bool NotExecutedB=true;

[Rule]
static void A()
{
 Condition.IsTrue(NotExecutedA);
 NotExecutedA=false;
}

[Rule]
static void A()
{
 Condition.IsTrue(NotExecutedB);
 NotExecutedB=false;
}

If at test runtime, they really need to happen in parallel, you can also abstract A and B to one action (e.g. ExecuteAandB), and let adapters to handle parallel invoking.

Let me know if it works.

Thanks,

Xiang


这篇关于如何建模两个并行动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆