I have a source and a variable. in the "on exit" source section there is "variable=source.count()". The source generates n agents by inject fuction, but the variable has value n-1. why? thanks for the help.
Asked
Active
Viewed 120 times
0
-
instead variable= source.countArrivals() give me 0 – Luigi Aurilio Aug 26 '21 at 20:51
1 Answers
0
so I assume you want to count the agents that have been generated on that source.
Using a variable is in the first place redundant since you can use source.count() everywhere in your model instead of the variable, and it will work.
Nevertheless if you insist in using a variable, you need to use the variable in the block AFTER the source since it seems that the count is made internally in anylogic after the "on exit" action.
so for instance if you have a delay block after the source, write variable=source.out.count(); in the "on enter" action of the delay block.

Felipe
- 8,311
- 2
- 15
- 31
-
i'm sorry but if i have to storage the number of agent generated by the source,it's necessary using a variable (so not redundant ).Am I wrong? – Luigi Aurilio Aug 27 '21 at 08:54
-
instead of using count() you can just do variable++; on the on exit and you get the result you need – Felipe Aug 27 '21 at 10:33
-