If you are creating a new agent population, and have attribute values for all agents stored in a database, you can easily create a population based on the existing data.
Assume you have the following Excel spreadsheet, and you want to create a population of five cities:
Data in Excel spreadsheet should meet the following formatting requirement:
The following video demonstrates how to create an agent population and provide agents with attributes that are read from the MS Excel spreadsheet:
How-To video: Reading agent attributes from a database
The following video shows how to read agents' addresses/coordinates from the database and locate agents in the given points on the GIS map:
How-To video: Placing agents on the GIS map
To create a population
of agents based on the existing data
In the right pane, you will see the list of database tables (if not, click the Show list of tables button). In this list, select the table that contains the data for the agent population, and click Next.
On the next page of the wizard, you can set up the parameters of the new agent type. In the Agent parameters mapping table, you will see the list of parameters that will be created. By default AnyLogic proposes to create one parameter for each database table column that contains data. You can change the name of the parameter in the Parameter column. If you do not need some parameter to be created, select the corresponding row in the table, and click the Remove button below. Click Next when finished.
On the next page of the wizard, specify the animation for the agent. If you want the agents to be animated both in 2D and 3D, choose 3D and select the animation shape from the list below. If you need the shape that is shown only in 2D, choose 2D and select the shape from the list. If no shapes satisfy your needs, just choose None. You can draw animation on the agent type diagram later on. Finished with choosing the animation, click Next to proceed to the next step.
On the last page of the wizard you have to
configure the environment where these agents
live. Choose the type of the space (Continuous,
and configure it using
the controls below. If you choose Continuous space, define the
dimensions, width and height, in the Size fields, and
specify how the network
of agent contacts should be created (in the Network type list). We will
space, and will finally show you how to locate our agents at the
coordinates read from the database.
When finished, you will see the
element on the Main
diagram - it is agent population.
population contains the number of agents equal to the number of records
in the database table we've used. In the Projects tree, you
see the created agent type ( City). Since we have chosen
GIS space, GIS map was also created automatically.
Now let's show you how to locate our agents at the coordinates read from the database. Click the cities element on the Main diagram. In the Properties, open the Initial location section, choose the option Place agent(s): in the latitude/longitude, and write the following code lines:
Here we refer to the individual agent in a population by the keyword self.
Now if you run the model, you will see that the agents are placed according to the coordinates we have read from the database:
Now you can develop the City agent logic further. Open the agent's diagram by double-clicking City item in the Projects view, and add any other elements you need on the diagram.