admin管理员组文章数量:1279214
I want to create an agent component "Event" that will trigger when two conditions are met simultaneously:
- Variable
alarm == true
- The value of the function
getPeopleInsideCount() == 0
The construction is as follows: alarm && getPeopleInsideCount() == 0
I have a button that, when pressed, sets alarm to true, and the value of the function getPeopleInsideCount() gradually decreases to 0. But when both conditions become true, the event still does not trigger.
I saw this construction in an example from Anylogic. In their example, everything works correctly.
Firstly, here is the link to my model.
I tried using a variable instead of the dynamically changing function value.
I created a variable peopleCount
of type int
, initially set to 0.
At the output of all pedSource
, I added peopleCount++;
.
At the input of all pedSink
, I added peopleCount--;
.
Then I changed the condition for triggering the event to alarm && peopleCount == 0
, but this also did not yield any results.
I want to create an agent component "Event" that will trigger when two conditions are met simultaneously:
- Variable
alarm == true
- The value of the function
getPeopleInsideCount() == 0
The construction is as follows: alarm && getPeopleInsideCount() == 0
I have a button that, when pressed, sets alarm to true, and the value of the function getPeopleInsideCount() gradually decreases to 0. But when both conditions become true, the event still does not trigger.
I saw this construction in an example from Anylogic. In their example, everything works correctly.
Firstly, here is the link to my model.
I tried using a variable instead of the dynamically changing function value.
I created a variable peopleCount
of type int
, initially set to 0.
At the output of all pedSource
, I added peopleCount++;
.
At the input of all pedSink
, I added peopleCount--;
.
Then I changed the condition for triggering the event to alarm && peopleCount == 0
, but this also did not yield any results.
1 Answer
Reset to default 1Fair question. AnyLogic does not constantly re-evaluate all possible conditions (else your model would run extremely slow).
So it is your responsibility to manually check.
In your case:
- delete the event
- replace with a function
shouldItTrigger
- in the function, check both required conditions. If both are
true
, execute what you want to see - call the function from both places where the conditon could change. So when you change 1 condition, also call the function. Same for the other condition
This is clean OOP design, btw.
PS: Do not get tempted by statecharts and conditional transitions. They promise you this capability but can easily fail if you do not know exactly how they work :)
版权声明:本文标题:anylogic - How to create an "on condition" event with a double condition like &&? - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741221704a2361080.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论