The Multi-Agent Transport Simulation

The MATSim (Multi-Agent Transport Simulation) software project was started around 2006 with the goal of generating traffic and congestion patterns by following individual synthetic travelers through their daily or weekly activity programme. It has since then evolved from a collection of stand-alone C++ programs to an integrated Java-based framework which is publicly hosted, open-source available, automatically regression tested. It is currently used by about 40 groups throughout the world. This book takes stock of the current status. The first part of the book gives an introduction to the most important concepts, with the intention of enabling a potential user to set up and run basic simulations. The second part of the book describes how the basic functionality can be extended, for example by adding schedule-based public transit, electric or autonomous cars, paratransit, or within-day replanning. For each extension, the text provides pointers to the additional documentation and to the code base. It is also discussed how people with appropriate Java programming skills can write their own extensions, and plug them into the MATSim core. The project has started from the basic idea that traffic is a consequence of human behavior, and thus humans and their behavior should be the starting point of all modelling, and with the intuition that when simulations with 100 million particles are possible in computational physics, then behavior-oriented simulations with 10 million travelers should be possible in travel behavior research. The initial implementations thus combined concepts from computational physics and complex adaptive systems with concepts from travel behavior research. The third part of the book looks at theoretical concepts that are able to describe important aspects of the simulation system; for example, under certain conditions the code becomes a Monte Carlo engine sampling from a discrete choice model. Another important aspect is the interpretation of the MATSim score as utility in the microeconomic sense, opening up a connection to benefit cost analysis. Finally, the book collects use cases as they have been undertaken with MATSim. All current users of MATSim were invited to submit their work, and many followed with sometimes crisp and short and sometimes longer contributions, always with pointers to additional references. We hope that the book will become an invitation to explore, to build and to extend agent-based modeling of travel behavior from the stable and well tested core of MATSim documented here.

and regions, as well as (social) disasters (Rodríguez et al., 2006).Another factor is the availability of large-scale, fast simulation models and tools.Lämmel (2011) discusses such a model employed as a contribution to MATSim.Basically, this model implements the same iterative learning approach as that applied to "regular" transport scenarios.In the rst instance, the cost function comprises only travel times, albeit a combination of travel time and travel distance; as a cost function has been investigated as well (Lämmel et al., 2009).Articial agents represent evacuees trying to improve their evacuation plans from iteration to iteration, by creating new evacuation plans more responsive to the evolving situation.A typical simulation run comprises 500-1 000 iterations.The model is applied to a tsunami-related evacuation of the City of Padang in Indonesia (e.g., Taubenböck et al., 2013;Goseberg et al., 2013); some scenario details are discussed in Chapter 76.
Additional evacuation simulation related work in MATSim is presented by Dobler (2013).The main dierence to this chapter's approach is that agents are allowed to adapt their plans spontaneously, using MATSim's within-day replanning framework (Dobler et al., 2012) (Chapter 30).
Based on a behavioral model, agents coordinate their actions on a household level.If a household is, e.g., not complete when the evacuation starts, each member estimates time needed to return home, as well as the time required to leave the actual evacuation area.Then, the household decides whether meeting at home and leaving together is preferable to each member leaving on its own.Since the behavioral model is implemented on an agent, respectively household level, individual attributes such as children present in the household, or availability of a car, can be taken into account.In contrast to regular MATSim simulations, only a single iteration is performed.Since the agents can optimize their plans continuously using real time information, no further replanning is necessary.As a result, agents do not foresee future events like trac jams caused by people leaving the threatened area.
An independent evacuation scenario, not using the evacuation, is presented in Chapter 60.The remainder of this chapter is organized as follows: Section 41.3 gives a brief description on how to set up and run evacuation.A short start guide for evacuation is presented in Section 41.4.Obtaining the required input data is discussed in Section 41.5.Detailed instructions on how to use evacuation's ScenarioManager, running simulations and analysis is given in Section 41.6.This chapter concludes with a brief outlook in Section 41.7.

Download MATSim and Evacuation
Although the MATSim version 0.6.0-SNAPSHOT is referred to here, the package should also work with later versions of MATSim.

Test conguration by invoking
java -cp evacuation -0.6.0 -SNAPSHOT .jar ; MATSim_rxxxxx .jar org .matsim .contrib .evacuation .scenariomanager .ScenarioManager (It is advisable to copy that command to a le evacuation.bat-orevacuation.sh,if using a Unixlike operation system.One can then run that le instead of typing the command.)

The Fieen-Minute Tour
For just a quick impression, the following steps can be performed within a few minutes: OSM Go to http://www.openstreetmap.org,search for the desired place and download a (small) OSM le.Please choose a small area, e.g., 500 meters by 500 meters; this is sucient to begin and size of the exported area is limited.For larger areas, a direct download from sites like http://www.geofabrik.de is preferable (see next section).Run the ScenarioManager as described in the previous section.Create a scenario by clicking the lemost button rst and then New.Go to the directory where the designated project should be saved and name the project le (e.g., london.xmlor scenario. xml).
Specify the path of the OSM le (by clicking Set next to network) and the output directory.Leave area and population le as it is, evacuation will handle this.This step must be performed only once.Aer the scenario-le has been saved, one can open it in the ScenarioManager.Sample size Set the sample size to 0.1, using the mouse or the cursor buttons on your keyboard.Departure Specify the departure time distribution.Plausible values are: normal distribution, µ and 600 seconds (10 minutes), earliest 300 seconds, latest 1200 seconds (20 minutes).Save the scenario le.Area Switch to the area tab.One can dene the circular evacuation area by keeping the le mouse button pressed and dening the center and radius.Do not forget to save changes.Population Switch to the population tab and dene the population (handling is similar to area).
Do not forget to save changes.Convert Switch to the next tab and convert the scenario to MATSim input les by clicking the run button.The MATSim les will be stored in the output directory specied in the beginning.Run the MATSim simulation by skipping the next two tabs/buttons (road closures and buses) and switching to the simulation tab (with the "M" for MATSim on the computer screen).Click run.This will take a while.If an output directory (e.g., from a previous run) already exists, it will be renamed.Analyze your simulation results by switching to the nal tab aer the simulation is nished.

Input Data (any Place and any Size)
The only external input necessary for performing an evacuation analysis with org.matsim.contrib.evacuation is an OSM le.In this tutorial, we will use the le for Hamburg, Germany.Please go to http://download.geofabrik.de/europe/germany/hamburg.html and download the hamburg-latest.osm.bz2le.This is the only initial preparation needed.Everything else can be done with the ScenarioManager of the GUI.

Scenario Manager
The scenario setup, evacuation simulation, and analysis are handled by the ScenarioManager from the MATSim contribution package org.matsim.contrib.evacuation.

Scenario Conguration
At startup, the ScenarioManager oers the option to either: dene a new scenario conguration or open an existing one from a XML le, which then can be modied.Figure 41.1 shows a screenshot of a scenario conguration in the ScenarioManager and the corresponding XML le, respectively.The evacuation scenario is specied by the following parameters: • The path to the network le covering the evacuation area: Currently, OSM XML les are supported (*.osm).• The main trac type for the simulation: This can either be: VEHICULAR or PEDESTRIAN.
Depending on the choice, a vehicular specic (the MATSim default) or a pedestrian-specic (as discussed in Lämmel et al. (2009); Lämmel (2011)) simulation network will be generated by setting free speed, number of lanes and ow capacity for all links in the network.• The path to a ESRI shape le describing the extent of the evacuation area, depicted by a simple polygon.This le does not have to be in place right from the beginning; it can be produced manually by the ScenarioManager itself, as discussed later.• The path to an ESRI shape le detailing the size and distribution of the aected population.
This le comprises a set of simple polygons; each polygon has an additional attribute for the number of persons residing at a location inside that polygon.The evacuation area le can be produced with help of the ScenarioManager.• The path to the output directory where the simulation output and MATSim scenario les will be stored.• The sample size for the MATSim simulation.A smaller sample size increases the simulation performance, while a larger size might increase accuracy of the results.Typical values are 1.0, 0.1, or 0.01, depending on the scenario and available computing resources.• Departure time distribution denes the distribution from which departure times for the simulation will be drawn, based on the premise that, in real evacuation situations, all participants probably do not start evacuation simultaneously.People tend to perform pre-evacuation activities before they start, including: picking up relatives, packing food, clothes, valuable belongings, etc.Since number and duration of these activities diers by individual, population departure times are unknown quantities.The ScenarioManager supports three dierent distributions: (Dirac-delta, normal, and log-normal).If the user chooses the Dirac-delta distribution, then all evacuees will start simultaneously, which might be the worst case (Lämmel and Klüpfel, 2012).By choosing the normal distribution, departure times for individuals are drawn from a normal distribution with mean µ and standard deviation , where the parameters µ and are given in seconds.As an example, setting µ = 1800 and = 900 will result in a departure time distribution where, on average, aer 30 minutes 50 % of the population has departed and 68.3 % of the population departs in time intervals of 30 minutes ± 15 minutes.If the user chooses log-normal as the distribution, departure times are drawn from a log-normal distribution, where µ and are the parameters of the associated normal distribution (a discussion on this matter is given below).The parameters earliest and latest determine the earliest and latest possible departure time.The normal and log-normal departure time distribution are truncated accordingly.
The departure time distribution is perhaps the most tenuous parameter to set; the authors found no holistic research into this matter.In general, it seems reasonable to assume that many people start evacuating at the same time, or soon aer the evacuation order has been issued and as time proceeds, fewer and fewer people are le to depart.This requires a departure time distribution that has a probability density function beginning with a steep positive gradient, leveling out slowly aer a peak.The probability density function of a log-normal distribution produces this kind of curve; log-normal and normal distributions are closely related.If the random variable Y is normal distributed, then X = exp(Y) is log-normal distributed.The expected value E[X] and the variance Var[X] are and Conversely, if the expected value and variance is given, µ and of the associated normal distribution can be obtained as follows: (41.4) If users wish to generate a population with departure times following a log-normal distribution, it is hard to see how and µ will determine the outcome.It is much more convenient to consider expected value and variance.Given Equation (41.3) and Equation (41.4), a conversion from expected value and variance to and µ is straightforward.

Evacuation Area
The ScenarioManager integrates modules for the evacuation area denition and distribution of the aected population.The so-called evacuation area selection module allows the user to dene the evacuation area by drawing either a simple polygon or circle on a map.The application can make use of either a WMS-provider or a tile map provider (e.g., OSM) as background map renderer.Zooming and panning is restricted to the bounding box of the OSM network le provided in the scenario conguration.An illustration of the evacuation area selector is given in Figure 41.2.In addition to dening a new evacuation area, a pre-existing one can also be loaded into the ScenarioManager.The requirements for a pre-existing evacuation area le are: • It has to be provided as a ESRI shape le.
• The evacuation area must be dened as a simple polygon or a multi-polygon containing one, and only one, simple polygon.• The coordinate reference system for polygon in the ESRI shape le must be set correctly.
Due to the high likelihood of error, this approach is recommended for experienced users only.Later in the process, the ScenarioManager takes the evacuation area to cut out an evacuation network.However, aer cutting out the evacuation net, there is no particular node as a target for the route calculation, as evacuees have more than one safe place as a destination.Instead, in the underlying domain, every node outside the evacuation area is a possible destination for an evacuee seeking an escape route.Thus, the evacuation problem is, in general, a multi-destination problem.To resolve this, the standard approach (e.g., Ford and Fulkerson (1962);Lu et al. (2005)) is to extend the network in the following way: All exit links (i.e., links that originate inside the evacuation area and terminate outside the evacuation area) are connected, using virtual links with very high (essentially innite) ow capacity and equal length, to a super-node; all evacuation routes are routed to the super-node.This way, the problem is reduced to a multi-source single-destination problem.And thus, nding the shortest path from any node inside the evacuation area to this super-node and, in consequence, to safety, can eciently be solved.For technical reasons, a superlink is added to the super-node and the evacuees are routed to that link (see the image at the beginning of this chapter).

Evacuation Demand
The process of dening the population distribution is similar to that of the evacuation area, diering because population is distributed over circles drawn on the map.The user can draw  an arbitrary number of those circles and dene population gures individually for each circle.Figure 41.2 illustrates the population editor.The population editor oers only basic functionality to dene a population distribution.For every circular area, the ScenarioManager produces as many agents as required and assigns each agent a random coordinate inside the circular area.However, in MATSim agents depart on links, so the ScenarioManager calls the getNearestLink() method dened in NetworkImpl.Thus, agents will depart on links inside and possibly near the circular areas.
In the current version, it is impossible to use a predened demand for the simulation.Extending the simulation package in this way would be straightforward, but is out of this work's scope.

Road Closures
In real situations, some evacuation roads might not be available for the evacuation, because: • They might be impassable due to the event (oen the case in ooding-related evacuations).
• The authorities might want to keep roads open only for action/help trac.
• In some situations, like hurricane evacuations, lane direction on motorways might be reversed to increase ow capacity in one direction.• The authorities have detailed evacuation plans in place, with pre-planned evacuation routes; road closures might be necessary to force evacuees onto certain routes.
The actual planning of road closures can be a complex undertaking; not all attributes can be integrated into a simple tool for rapid evacuation planning.Nevertheless, the ScenarioManager oers a tool to create time-dependent road closures.An illustration of the road closures editor is given in Figure 41.3(a).Road closures are stored as NetworkChangeEvents and handled as time-dependent network attributes in MATSim (Lämmel et al., 2010).

Bus Stop Editor
Usually, not everyone has access to a private car.In the event of an evacuation, those people oen rely on public transport.In regions prone to natural disasters, local authorities normally have detailed evacuation plans in place, probably including evacuation by public transport.Consequently, it is important to have a tool available to help integrate public transport into to the simulation scenario.The ScenarioManger oers this possibility by dening bus stops and bus schedules in the interactive GUI. Figure 41.3(b) gives an example of the bus stop editor.In addition to location, the user can dene when the rst bus will serve a bus stop, how many buses overall will serve this particular bus stop and these buses' capacity.The ScenarioManager transforms the inputs made into the GUI into a MATSim compatible transport schedule, enriching the scenario while using the same simulation model.Details about public transport simulations with MATSim are given in Chapter 16.A tutorial can be found on the MATSim webpage http: //matsim.org/docs/tutorials/transit.
Limitations of the public transport evacuation approach in this project are: • Each bus serves one and only one bus stop, perhaps a realistic assumption.
• Buses always take the shortest path from their designated bus stops to the safe area.As the shortest path is not necessarily the fastest, this approach might lead to avoidable delays.Some newer research investigates optimization of bus lines with respect to trac demand and trac conditions (Neumann, 2014).Implementing such optimization techniques in the evacuation context is a topic of future research.

Running the Scenario
The ScenarioManager runs the evacuation simulation in a way similar to other transport simulation studies with MATSim.At the beginning, an evacuation plan is assigned to each evacuee.An evacuation plan describes how the evacuee intends to reach the safe area.If the evacuee leaves by car or on foot, the plan is essentially comprised of a route (typically the shortest) from home to the safe area.For evacuees who are depart by public transportation, the plan can be much more complex.All these evacuation plans will be executed in the mobility simulation; aer this terminates, all plans are scored by travel time.The shorter a plan's travel time is, the higher is the score it receives.Aer this step, evacuees' plans are revised; some will receive new plans, while others continue with the current ones.This step is called re-planning.Mobility simulation, scoring, and re-planning are repeated in a loop for a predened number of iterations; evacuees' individual performance improves over the iterations.In general transport studies, this approach emulates real-world travelers' behavior when they perform their daily commutes and try to nd better travel alternatives.Evacuations, however, are singular events where such day-to-day re-planning would not occur.We argue here that the chosen iterative learning approach could be seen as the evacuees' anticipation of the conditions expected during an evacuation.People familiar with their surroundings would probably avoid roads that obviously constitute bottlenecks during an evacuation.Nevertheless, far more research is needed to denitively answer how people choose evacuation routes, or how many learning iterations are required to realistically reect assumed anticipation skills adequately.As a rule of thumb, running 100 learning iterations are usually sucient to achieve results constituting a lower evacuation times boundary.

Analysis
Aer the last iteration has nished, the ScenrioManager enables the analysis module.The analysis model evaluates the performed simulation run, using a number of dierent methods.
• The cumulative arrival curve tells the user the number of persons evacuated over time.From this curve, the user can, for example, learn at what time 50 % of the population has reached a safe destination.• The GIS-based evacuation time analysis draws a grid over the evacuation area and computes, for every grid cell, average evacuation time.The evacuation times are indicated by dierent colors; the analysis modules run a quantiles-based clustering analysis for each cell.The size of cells can be varied by the user.• The GIS-based clearance time analysis is performed in the same way as the evacuation time analysis.The clearance time of a cell is the time when the last evacuee leaves that cell.This evacuee is not necessarily the one who also started his/her evacuation inside the corresponding cell, but might also be one who crosses that cell somewhen during the evacuation.• A similar quantiles-based clustering approach is used for the link utilization analysis.The link utilization analysis results help the user to identify the major evacuation routes.
The analyses can be run for every single iteration for which the MATSim Controler has dumped an events le (every 10th iteration by default).An overview of the analysis module is given in Figure 41.4

Conclusion
This chapter demonstrates how rapid evacuation planning can be performed with help of the evacuation contribution.The evacuation contribution provides an interactive GUI to perform this task.The only required external input is a network le extracted from OSM, thus a simple scenario can be setup, simulated, and analyzed in less than an hour.Obviously, for an in-depth evacuation analysis of a certain area, a sort of expert knowledge is needed that a simple GUI can not supply.Still, for a rapid appraisal and for demonstration purposes, evacuation oers a powerful and easy-to-use tool.In the future, we plan to integrate a more advanced public transport planning tool based on Neumann (2014).Work is also ongoing to develop a more sophisticated pedestrian simulation model based on the theoretical framework given in Flötteröd and Lämmel (2015).

Figure 41 . 1 :
Figure 41.1:Illustration of a conguration opened in the ScenarioManager and as XML le.

Figure 41 . 2 :
Figure 41.2:The evacuation area and the population distribution can be dened with an integrated GIS application.
Bus stop locations and schedules.

Figure 41 . 3 :
Figure 41.3:Top: Road closures can be edited by an integrated GIS application.For every link the direction and the time of closure can be dened.Bottom: Tool that let the user dene bus stop locations and schedules.

Figure 41 . 4 :
Figure 41.4:Screenshot of the analysis module showing GIS-based evacuation time analysis and the evacuation curve.