0
votes

I have a model as shown below with two situations, I am running it for two situations.

In the first run (for situation1), I write traceln function as "traceln(productDemand)" in the "event-generateDemand" placed in "Main". At the end of simulation, I get the values in the first column below. 2)In the second run (for situation2), for once I write traceln function as "traceln(main.productDemand)" in the "event" placed in "Producer" agent.At the end of the second simulation, I get the values in the second column below.

Normally, these two values are always same , it expected that at the every simulation time they have to be same, but they are not same as shown in the Fig.1. what's the problem? Why the "productDemand" variable is different when we try to access from another agent at the same time?

I hope I was able to explain my problem.

Fig.1- The obtained results as table format Fig.2- The screenshot of Event placed in Main Fig.3- The screenshot of Event placed in Producer agent Fig.4- The obtained results for both traceln functions on the running Fig.5- Simulation experiment screenshot.

fig.1

fig.2

fig.3

fig.4

fig.5

1
Welcome to SOF @Ali . Can you share model screenshots instead of sharing model files? Most of us do not have the time to open and study your model :) . Make our lives as easy as possible. Also refer to benjamin-schumann.com/blog/2021/4/1/… - Benjamin
Re your problem: Likely, you run with random seeds that produces different results each time, have you checked? - Benjamin
Thanks for your reply. I was glad for your response. Now I am editing the post and I will add screenshots from the model. - Ali

1 Answers

0
votes

There is no bug in the model it is just a simple case of timing. Not all events occur at exactly the same "time" although they all occur at the same timestep. One will always execute before the other.

See the simple example below:

I have eventA that increases the variable value and then traces the value (similar to your event on main)

enter image description here

Then I have another event that traces the variable as well, similar to yours in the agent.

enter image description here

Yet when I run the model at the same time the variable appears to be different from the different locations of tracing

enter image description here

If you click on the Events tab in the console you will see that event B is scheduled to run before event A

enter image description here

Even though both will run at the same timestep in the model they don't run "at the same time"

If you want to be in total control of what happens on a specific time step, it is advised to have one event that runs at the time interval you want, e.g daily, and have it sit on main and then call all the functions in the order you want them executed.

If you don't do this then AnyLogic will schedule the events as they get created, which most of the time is the order in which you placed them on the canvas.