I have an AnyLogic model working, and it seems that batch and unbatch causes the agent to lose its parameters.
I've created a MWE:
I have an agent, called MyAgent, with a parameter called timeNeeded
. On startup it runs this: timeNeeded = uniform_discr(1,100);
.
I then set up a very simple model like this:
Here the:
MyAgent
every 55 secondsagent.timeNeeded
This runs no problem. E.g. after about 3000 seconds (model time) we have this:
.
Next, I make a simple addition of a batch and unbatch:
where the only change is the addition of a batch and an unbatch. Obviously, the batch is not permanent. It's the default setting of 10 agents begin batched. Here's the settings:
Now it runs until it has to delay and then errors as follows:
The error in the console says:
Exception during discrete event execution:
Unresolved compilation problem:
timeNeeded cannot be resolved or is not a field
java.lang.Error: Unresolved compilation problem:
timeNeeded cannot be resolved or is not a field
at mwe.Main._delay_delayTime_xjal(Main.java:382)
at mwe.Main$2.delayTime(Main.java:246)
at com.anylogic.libraries.processmodeling.Delay.delayTime(Unknown Source)
If I change the delay time to 50 (instead of agent.timeNeeded
), then it runs without issues.
It's strange because the context menu of that delay shows agent.timeNeeded
as a valid entry:
Am I missing something obvious? And, if not, what is the work around to save the parameters of the agents coming through a batch-unbatch step?
For any future person coming across this simple thing (probably me!), you need to make sure that the unbatch outputs to an element agent of the same time that was originally batched. So in the MWE, the element agent needs to be MyAgent:
It will then recover the original parameters. If that is the default agent
type, that it can't have a parameter because the parameter is not defined for that agent type.