Community

I am new to AnyLogic and am developing an agent based simulation. My agents are being dynamically created and destroyed over time but for some reason my graph that plots the number of agents over time does not seem to be accounting for the additions and removals. The additions and removals occur at the same rate so the total number of agents should always be the same however, the number of agents on my graph just keeps getting larger (although the animation of the simulation is correct). I am obviously missing something but I am unsure of a solution even after reading the help files. Does anyone have any suggestions for fixing this problem?
to Amy: Could you tell me how you create and destroy agents? Also, let me know how you count them?
Thanks Victor, Right now I have implemented an event that creates additional agents and an event that destroys a specific number of agents (randomly chosen). I have variables for each of the different states of the agents statechart that collect the number of agents of each state and a dataset for each of these variables (that is graphed in a timeplot). So the number of agents is 256 at the beginning, the agents that are created get added to this number (which is correct) however, it does not subtract the number of agents that were destroyed at the same time. So the number of agents of the initial state continues to grow even though there are not actually that many agents (due to the removal if individuals). Any input would be really appreciated Victor.
to Amy: How do you decrease values of the variables which are used to count agents in the different states?
Victor, The statechart keeps track of the "counting" of individuals of each state type by using ++ and -- notation in the entry action and exit action fields (e.g. get_Main().Infected++;)
Amy, is it possible that some of the agents are destroyed before they leave the last state?
Victor, Yes it is possible. The agents that are destroyed are randomly chosen from the environment regardless of which state they are currently in.
Amy, when an agent is destroyed, the code placed in the Exit Action of a Statechart is not executed, so a counter could be not decreased.
Victor, Thank you so much! I really appreciate your help with this. I have made some adjustments to the way that the agents are destroyed and the variables now appear to be showing the correct number of agents during the simulation. Thanks again. Amy.