TraCI

Introduction to TraCI
TraCI is the short term for "Traffic Control Interface". Giving the access to a running road traffic simulation, it allows to retrieve values of simulated objects and to manipulate their behaviour "on-line".

SUMO startup
TraCI uses a TCP based client/server architecture to provide access to SUMO. Thereby, SUMO acts as server that is started with additional command-line options: where  is the port SUMO will listen on for incoming connections.

When started with the option, SUMO only prepares the simulation and waits for an external application, that takes over the control. Please note, that the option is ignored when SUMO runs as a TraCI server, SUMO runs until the client demands a simulation end.

Protocol specification
Please see the TraCI Protocol Specification (including Basic Flow, Messages, Data Types).

TraCI Commands

 * Control-related commands: perform a simulation step, close the connection

For the following APIs, the ID is equal to the ID defined in SUMO's input files. Here, you find their general structure.
 * Value Retrieval
 * Induction Loop Value Retrieval retrieve information about induction loops
 * Lane Area Detector Value Retrieval retrieve information about lane area detectors
 * Multi-Entry/Multi-Exit Detectors Value Retrieval retrieve information about multi-entry/multi-exit detectors
 * Traffic Lights Value Retrieval retrieve information about traffic lights
 * Lane Value Retrieval retrieve information about lanes
 * Vehicle Value Retrieval retrieve information about vehicles
 * Vehicle Type Value Retrieval retrieve information about vehicle types
 * Route Value Retrieval retrieve information about routes
 * PoI Value Retrieval retrieve information about points-of-interest
 * Polygon Value Retrieval retrieve information about polygons
 * Junction Value Retrieval retrieve information about junctions
 * Edge Value Retrieval retrieve information about edges
 * Simulation Value Retrieval retrieve information about the simulation
 * GUI Value Retrieval retrieve information about the simulation visualization
 * State Changing
 * Change Lane State change a lane's state
 * Change Traffic Lights State change a traffic lights' state
 * Change Vehicle State change a vehicle's state
 * Change Vehicle Type State change a vehicle type's state
 * Change Route State change a route's state
 * Change PoI State change a point-of-interest's state (or add/remove one)
 * Change Polygon State change a polygon's state (or add/remove one)
 * Change Edge State change an edge's state
 * Change GUI State change the simulation visualization
 * Subscriptions
 * TraCI/Object Variable Subscription
 * TraCI/Object Context Subscription

Example use

 * There is a tutorial on using TraCI for adaptive traffic lights (using Python).
 * The Tutorials/CityMobil tutorial uses TraCI for assigning new routes to vehicles (using Python).

Interfaces by Programming Language

 * Python: the package tools/traci allows to interact with SUMO using Python
 * Java: TraCI4J is a Java API implementation; documentation is under work
 * Java, .NET, ... anything that can do SOAP TraaS is a web-service adapter for TraCI which allows automatic API generation for multiple languanges.
 * Matlab TraCI4Matlab

V2X simulation
TraCI allows to use SUMO in combination with communication network simulators vor simulating vehicular communication. See Topics/V2X for a list of available solutions.

Other Resources

 * SUMO's TraCI Server is a part of the plain distribution. The source code is located in the folder.

Output files are not closed.

 * This problem occures if the client tries to access the output while the simulation is still closing down. This can be solved by letting the client wait for the simulation to shut down. The bug report was ticket524

Obsolete APIs

 * There used to be two "generations" of TraCI commands. The first one mainly uses an internal mapping between the string-typed IDs used in SUMO and an external representation of these which is int-based. The mapping was done internally (within TraCI).
 * The second "generation", the current one uses string-IDs equal to those SUMO reads. If you are bound to the first generation API (for instance if you want to use TraNS) you can only use SUMO up to version 0.12.3. See FAQ about obtaining an old version.