admin管理员组

文章数量:1279214

I want to create an agent component "Event" that will trigger when two conditions are met simultaneously:

  1. Variable alarm == true
  2. 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:

  1. Variable alarm == true
  2. 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.

Share Improve this question edited Feb 25 at 8:10 Benjamin 12.6k3 gold badges18 silver badges33 bronze badges asked Feb 25 at 7:51 Boris ZhdanovBoris Zhdanov 31 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Fair 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 :)

本文标签: anylogicHow to create an quoton conditionquot event with a double condition like ampampStack Overflow