Renier
Renier

Reputation: 540

AnyLogic Agent Initialization of variables

I am an AnyLogic newbie. When I define an agent type and add parameters to it, I can call a constructor

MyAgentType agent1 = new MyAgentType(param1, param2, ..., paramn)

The parameters are set on the new instance and can be used in workflow and other functions - fine.

Now I want to define some variables on the same agent type, but as it is a variable, it is not included in the constructor and needs to be explicitly set after instantiation. However, if I now try to inject this new instance into a flow diagram using enter.take(agent1) the agent in the flow diagram seems to "loose" the variable value (breakpoint show it to be null).

What am I missing?

Upvotes: 0

Views: 1043

Answers (1)

Felipe
Felipe

Reputation: 9376

The enter block should be used to insert agents that already exist in the model as part of a population... When this population exists (for example called myAgents) you can do MyAgentType agent1 = add_myAgents(param1,param2, ...,paramn) instead, which includes the agent in your model as part of that population, and then you can safely do agent1.variable=x; and then enter.take(agent1);

It seems that when you generate a new agent that doesn't belong to a population with an enter block, it just resets the variables into their initial values, and probably resets everything else within the agent (except the parameters)... I don't know why though.

Upvotes: 1

Related Questions