Search code examples
anylogic

Unable to view update the parameters of Agent population


I have agents population as "MyAgents" and I am trying to update the parameters during the process flow. pic shows that I am updating parameter with value of 1 enter image description here

Then in the below simple function trying to sum it up but it is not giving any value.

enter image description here

I have traced the parameter value in the sink block and it can viewed there but when I am using function to sum up it is giving zero output.

My goal is to update parameters on the entry or exit of block. Is here a way to manage this?


Solution

  • The problem is that you're updating the parameter once the agent enters the sink. After an agent enters the sink, it will be removed from the population. So the population myAgents will not contain the agent with the updated parameter value and thus the sum will always be zero.

    Instead, I would suggest to create a global variable total_amount (e.g. in Main) and change the code "on enter" at the sink to (if the total_amount should be incremented by 1):

    total_amount++;
    

    Or if the total_amount should be incremented by a given value:

    total_amount += <parameter_value>;