mcstarioni
mcstarioni

Reputation: 320

How to add to agent to presentation

I am trying to simulate self-sustaining population of cows, but when i dinamicly add new agents to main agent's population newly created agent does not appear. How to fix it? I create agents from mother agent with

this.main.add_cows();

first generation population

pupulation without presentation

Upvotes: 2

Views: 850

Answers (2)

Felipe
Felipe

Reputation: 9421

First go to the agent where the animation will exist (which is also where your agent is defined). In most cases this is the main agent, so you probably want to go to "main" and click on the cow agent to see the "initial location" in the properties of the cow agent.

When a new agent is created, the default position is at the agent animation location, which is probably somewhere out of the visible area since we generally position our defined agents out of the canvas, and in your case it's the same position for all cows. enter image description here

Now you have other options: you can select for instance a random coordinate in the space (assuming you have a 600x600 pixels square): enter image description here

Or you can select a node (as long as a node is defined in your animation canvas: enter image description here

So, to summarize, when you create a new agent in your population, you have to tell AnyLogic where you want to locate it... Otherwise, how can the software know what you want?

Upvotes: 2

Benjamin
Benjamin

Reputation: 12803

ensure to set the initial location correct, otherwise it might appear at a default location you do not expect. Something like:

Cow myNewCow = this.main.add_cows();
myNewCow.setXY(uniform(0,600), uniform(0,400));

Upvotes: 1

Related Questions