Skip to content

read_agent_file

Syntax

read_agent_file(filename)

Parameters

filename
The name of the input file containing agent IDs and any additional properties.

Returns

Optionally returns a list of agents that were updated.

Description

Read and internally store a list of agents and their properties from a file.

This is an action enables reading and assigning agent properties to individual agents based off of the contents of an input csv file.

The syntax of the input file is expected to have column headers matching existing agent variables so that the values in subsequent rows can be assigned. A column with an "ID" column header can be used to specify which specific agents these properties are to be applied.

If the "ID" header is omitted, the ID field will be generated. There are no guarantees that the generated ID will not collide with an existing ID.

An error occurs if the file is not found.

Examples

agents.txt

sex
0
1
1
0

main.fred

simulation {
    locations = none
    default_model = none
    start_date = 2020-Jan-01
    end_date = 2020-Jan-01
}

variables {
    agent numeric sex
}

condition TEST {
    start_state = Agent_Start
    meta_start_state = Meta_Start

    state Meta_Start {
        read_agent_file(agents.txt)
        wait()
        next()
    }

    state Agent_Start {
        print("ID: ", id(), "; SEX: ", sex)
        wait()
        next()
    }
}

Running the above will can produce the following output:

ID: 1000000000; SEX: 0
ID: 1000000001; SEX: 1
ID: 1000000002; SEX: 1
ID: 1000000003; SEX: 0

See Also