Skip to content

get_role

Syntax

get_role(<group-name>)

Parameters

<group-name>
The name of a declared group.

Description

Returns the role id of the agent in the given group. If the agent is not a member of any group of the given type, the action returns -1.

The names of the roles are defined in the file role_metadata.txt in the synthetic population's metadata directory.

A compile-time error occurs if the named group is not declared in the model.

Examples

Say the roles defined in the default synthetic popluation are:

GROUP,ROLE_0,ROLE_1
Household,child,adult
School,student,teacher
Grade,student,teacher
Workplace,worker,manager
Prison,resident,staff
Nursing_Home,resident,staff
College_Dorm,resident,resident
Barracks,resident,resident
State,resident,resident
County,resident,resident
Census_Tract,resident,resident
Block_Group,resident,resident

This model could be used to print if an agent is a teacher.

if (get_role(School) == teacher) {
    print("agent ", id(), " is a teacher in school")
}

See Also