in the agent I'm trying to build, I have a Dynamic Variable that could be changed from outside and I would like to link this change to trigger an event or a statechart transition. I tried the condition "variable != 0" but it has 2 errors: It doesn't consider the 0 in the case it happens to appear and it locks my agent because that's an always true condition. Do you know if this is something that could be done with Anylogic? Or should I try a different approach? Thanks a lot for your help, P
This is a lengthy solution, but I use it when nothing else works. Create dummy source and sink blocks inside the agent that flowchart lives. Be sure to select "calls of inject() function" inside the source.
And in the main, whenever that condition occurs, inject a dummy agent into that source block.
There you can control the transitions whenever the agent is created in the dummy source block with the variables that you have inside that agent.
The technical correct solution would be:
private
(so it cannot actually be changed at all from external sources)public
function named setMyVariable
that accepts a double argument named newValue
myVariable = newValue;
. Below that line, you can now execute any additional code that should be triggered whenever your variable is updatedThis is the OOP way of doing things :)
To add just one more type of solution for completeness: for these kind of situation I prefer to use message passing. The first part is similar to OOP method - make the variable
private so it can't be directly changed from outside the agent. Then to change the variable send agent a message using AnyLogic's agent communication functions. Once the message that value has changed is received, it changes the value and then forwards it to the statechart to trigger a transition. This addresses your issues:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.