Introduction to TraCI#

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

Using TraCI#

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: --remote-port <INT> where <INT> is the port SUMO will listen on for incoming connections.

When started with the --remote-port <INT> option, SUMO only prepares the simulation and waits for all external applications to connect and take over the control. Please note, that the --end <TIME> option is ignored when SUMO runs as a TraCI server, SUMO runs until the client demands a simulation end.

When using SUMO-GUI as a server, the simulation must either be started by using the play button or by setting the option --start before TraCI commands will be processed.

Multiple clients#

The number of clients which can connect can be given as an additional option --num-clients <INT>, where 1 is the default. Please note that in multi client scenarios you must explicity specify the execution order of the clients using the SetOrder-command. Each client must specify a unique (but otherwise arbitrar) integer value and the client commands will be handled in the order from the lowest to the highest value.


The simulation will only start once all clients have connected. To advance the simulation, all clients must sent the simulationStep command.

Protocol specification#

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

TraCI Commands#

For the following APIs, the ID is equal to the ID defined in SUMO's input files. Here, you find their general structure.


When using TraCI, the --end option of SUMO is ignored. Instead the simulation is closed by issuing the close command. To detect whether all route files have been exhausted and all vehicles have left the simulation, one can check whether the command getMinExpectedNumber returns 0. The simulation will end as soon as all clients have sent the close command.

It is also possible to reload the simulation with a new list of arguments by using the load-command.

Using SUMO as a library#

Normally, TraCI is used to couple multiple processes: A SUMO server process and one or more TraCI client processes. Alternatively, Libsumo can be used to embed SUMO as a library into the client process. This allows using the same method signatures as in the client libraries but avoids the overhead of socket communication. Libsumo supports generating client libraries using SWIG and can therefore be used with a large number of programming languages. C++, Java and Python bindings are included when downloading a sumo-build.

Example use#


Interfaces by Programming Language#

  • Python: the package tools/traci allows to interact with SUMO using Python (This library is tested daily and supports all TraCI commands)
  • C++: The C++ TraCIAPI is client library that is part of the SUMO-source tree (API coverage is almost complete).
  • C++: The Veins project provides a middle-ware for coupling SUMO with OMNET++. As part of the infrastructure it provides a C++ client library for the TraCI API (API completeness is a bit behind the python client).
  • .NET: TraCI.NET is a client library with almost complete API coverage.
  • Matlab TraCI4Matlab. The client is included as part of each SUMO release in <SUMO_HOME>/tools/contributed/traci4matlab Not all TraCI commands have been implemented
  • Java: TraaS provides a client library that is part of the SUMO-source tree (API coverage is almost complete)
  • Others: Any language that can access webservies using SOAP can access SUMO using the TraaS Webservice. A Java webservice client is also included with TraaS. API lags behind the python client

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 src/traci-server.



Using TraCI slows down the simulation speed. The amount of slow-down depends on many factors:

  • number of TraCI function calls per simulation step
  • types of TraCI functions being called (some being more expensive than others)
  • computation within the TraCI script
  • client language


As an example use-case consider retrieving the x,y position of each vehicle during every simulation step (using the python client):

   while traci.simulation.getMinExpectedNumber() > 0:
       for veh_id in traci.vehicle.getIDList():
            position = traci.vehicle.getSpeed(veh_id)
  • This script is able to process about 25000 vehicles per second.
  • Using embedded python increases this to about 50000 vehicles per second
  • The same value retrieval can also be sped up to 50000 vehicles per second by using subscriptions:
   while traci.simulation.getMinExpectedNumber() > 0: 
       for veh_id in traci.simulation.getDepartedIDList():
           traci.vehicle.subscribe(veh_id, [traci.constants.VAR_POSITION])
       positions = traci.vehicle.getAllSubscriptionResults()

When using this script on the Bologna scenario (9000 vehicles, 5000 simulation steps) the following running times were recorded:

  • without TraCI 8s
  • plain position retrieval 90s
  • retrieval using subscriptions 42s
  • retrieval using embedded python 46s
  • retrieval using subscriptions and embedded python 34s

The C++ client performance is higher:

  • plain position retrieval 80s
  • retrieval using subscriptions 28s

Future Development#

Currently TraCI uses a different (single byte) command IDs for every domain (induction loops, vehicle etc.) where the more significant half of the byte denotes the command (get, set, subscribe, ...) and the lesser significant the domain itself. This limits the number of domains to 16 which are almost used up. Although it may decrease readability of the constants in the future five bits will be used for the domain and only three for the command. Furthermore after the invention of libsumo some parts of the TraCI interface are so generic that it may be not so hard to invent a wrapper with protocal buffers which could in the long run replace the need for all the byte fiddling and the different hand crafted clients.


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 #524

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.