Search code examples
anylogic

AnyLogic batch and unbatch seems to lose the agent's parameter?


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:

Simple model

Here the:

  • Source makes a MyAgent every 55 seconds
  • Delay has a delay time of agent.timeNeeded

This runs no problem. E.g. after about 3000 seconds (model time) we have this: Model running.

Next, I make a simple addition of a batch and unbatch:

Simple model with 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:

Batch settings

Now it runs until it has to delay and then errors as follows:

Error for running model 2

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.

Model working

It's strange because the context menu of that delay shows agent.timeNeeded as a valid entry:

Context menu

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?


Solution

  • 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:

    MWE - unbatch settings

    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.