Person - smart-fm/simmobility-prod GitHub Wiki
Person agents are simmobility agents designed to encapsulate the behaviour of individual travellers who make trips and perform activities in the simulation time period. A person object represents an individual in the population data. The activity schedule of the person is generated by preday. His activity schedule is realized, executed and modified (if necessary) in the withinday of mid-term and short-term.
The behavior of a person agent varies considerably based on whether they are operating in a mid-term or a short-term simulation. For this reason, there are specializations to the Person class specifically for short and mid-term as shown in the diagram below.

Trip chain
Every person agent in the simulation has a trip chain. The trip chain is a conceptual representation of the person's plans during the simulation time period. It is simply a sequence of trips and activities along with pertinent information. The actions and behavior of every person is in accordance to his trip chain.
A trip chain consists of trips and activities.
- a trip is a journey from one simmobility node to another. A trip specifies the origin, destination, start time of the trip and primary mode of travel.
- trips are further broken down into sub-trips. A sub-trip represents a leg of its parent trip which is covered by a single mode of travel. For example, a Public Transport (PT) bus trip would have at least four sub-trips representing access walk, waiting at bus stop, in-vehicle bus travel and finally the egress walk. A sub-trip specifies the origin location, destination location, mode of travel and other pertinent information.
- an activity represents any non-commuting task performed by a person. For instance, a person working at his office is conceptualized as an activity. An activity is specified by the activity duration and the location of the activity.
- The trips, sub-trips and activities are generically referred to as trip chain items
For a trip chain to make sense, the sequence of trips and activities must be connected. The destination of a trip must be the location of the subsequent activity and the origin of any subsequent trip after the activity.
The trip chain of a person in the population is built at a high level from his activity schedule predicted by preday. Some specific details of sub-trips like the boarding stop, bus or train line, alighting point etc. are determined from the pre-trip route choice. The trip chain may sometimes be modified when the person is already in the simulation due to activity rescheduling or en-route route choice.
Persons driving the PT buses and trains are not represented in the population. They are created solely for the purpose of driving PT vehicles. For such persons, the respective controllers provide customized trip chains. The bus controller provides the sequence of bus trips to persons responsible for driving a PT bus line trip. Similarly, the train controller provides a sequence of train trips to persons responsible for doing train line trips.
Every person in the simulation systematically goes through his trip chain and takes pertinent actions during the course of the simulation. The person enters the simulation at the start time of the first sub-trip of the first trip. The person is killed when his entire trip chain is complete.
Roles
In withinday simulations, every person, at any given point during the simulation, has a role. The role of a person defines what the person will do in each time step of the simulation. The role assigned to the person is aligned with his current trip chain item.
The following roles are supported in SimMobility.
- driver (car driver)
- biker (motorcycle rider)
- trucker (freight vehicle driver)
- bus passenger
- private bus passenger
- train passenger
- bus driver
- train driver
- wait bus activity (role to await buses at stops)
- wait train activity (role to await trains at station platforms)
- activity performer (role to perform any activity like work, shopping etc. at one location)
- pedestrian
Every trip chain typically starts with a trip. The person is initialized with a role that corresponds to the mode of the first subtrip of the trip. Subsequently as each sub-trip is completed, the person keeps switching to different roles as required per the trip chain.
For example, if the person walks to a bus stop from an origin node as per his first sub-trip, he is assigned a pedestrian role. When the person is on the pedestrian role, he moves along the network from his origin node to the bus stop through each time step until he reaches the stop. The subtrip ends when the person has reached the bus stop. The person then enters the next sub-trip which may correspond to waiting for the bus. At this point, the pedestrian role is discarded and a wait bus activity role is assigned to the person. In this role, the person has one or more bus lines that serve the stop in mind and he waits for a bus in any of those lines to arrive at the stop. When the bus arrives, the person switches to the next subtrip which will require him to assume a bus passenger role.
A role change happens whenever the person changes from one subtrip to the next or from a subtrip to an activity and vice versa. The role assignment for a sub-trip is correlated to its mode of travel. A generic activity performer role is assigned for activity trip chain items. Simmobility does not differentiate the type of activities within the simulation.
The diagram below shows the possible role changes that can happen during the course of the simulation.

Each ellipse in this diagram represents a role. The possible roles to which a person can switch from a specific role is given by the outgoing arrows from the respective ellipse. Persons with train driver and bus driver roles do not change roles. This is because a person agent driving a PT vehicle are not represented in the population data and these persons are created in the simulation just for the purpose of driving the PT vehicle.
Mid-term person life cycle
In mid-term a Person is instantiated for every complete activity schedule that is loaded from the database (you can find here more details about how the activity schedule is generated). A trip chain is constructed out of each activity schedule and passed to the person object. The person agent takes ownership of the constructed trip chain and all actions that the agent does during the course of the simulation are aligned to the sequence of trips and activities defined in the trip chain.
When the person agent has been instantiated and given a trip chain, he is dispatched to a loading conflux. The sole purpose of a loader conflux is to initialize the first role of the person as per the trip chain and deliver the person to his appropriate starting conflux for the person to enter the simulation. The starting conflux is determined based on where the person is starting his first sub-trip.
After this, the confluxes take full control of storing and managing the person agents until either their trip chain is completed or the simulation ends. In every time step, the conflux that manages the person takes a snapshot of the person's current position and pertinent details, allows the person to update for that time step, captures a similar snapshot of the person's position and other details and does housekeeping based on the differences between the two snapshots.
If the person has moved out of the links of the current conflux, he is handed over to the next conflux. If the person finishes his current trip chain item (sub-trip or activity) he is allowed to switch to the next one and perform corresponding role changes. When the person has finished his entire trip chain for the day, the conflux that manages the person at that point kills the person agent.
Short-term person life cycle
In short-term, once the trips are loaded from the database (or an XML file), a Person is instantiated for every unique person id associated with the trips. Trips belonging to the same Person are linked together to form a trip-chain and it is passed to the person object. The person agent takes ownership of the constructed trip chain and all actions that the agent does during the course of the simulation is aligned to the sequence of trips and activities defined in the trip chain.
When the person agent has been instantiated and given a trip chain, it is allocated to a worker thread. Unlike the mid-term, each person in short-term manages itself. The person switches to the appropriate role based on the current mode of transport and the role governs the behaviour of the person.
If the person finishes its current trip chain item (sub-trip or activity) it switches to the next one and performs the corresponding role changes. When the person has finished its entire trip chain, the person leaves the simulation.