Skip to content
tjiagoM edited this page Apr 28, 2016 · 2 revisions

TraSMAPI-SUMO

This is a TraSMAPI specialisation for SUMO simulator.

TraSMAPI is a generic API used as bridge for microscopic traffic simulators (what is a microscopic simulator?) that allows real-time communication between agents in the urban traffic context (such as vehicles, traffic lights and pedestrians) and the environment created by various simulators. This tool was developed at LIACC (Artificial Intelligence and Computer Science Laboratory), University of Porto.

SUMO is an open-source program (licenced under GPL) for microscopic traffic simulation. It is mainly developed by Institute of Transportation Systems, located at German Aerospace Center.

Table of Contents

Usage

TraSMAPI is written in Java. To use this extension you first need to include TraSMAPI into your project. That can simply be done by creating a trasmapi package and by cloning the genApi folder into there. Then, you have to include in that same trasmapi package the sumo folder that is in this repository.

Basics and Ad-hoc Systems

As TraSMAPI was developed with object oriented design at its core, both the simulation objects and the simulator itself are objects of the language.

Initialisation and Configuration

Any system developed based on this tool will have an instance of the class TraSMAPI. Inside the application, it represents the simulator and any communication with the simulator in general will be made through this instance. A typical setup of the system would be the following code (utility class SumoConfig can be seen here):

TraSMAPI api = new TraSMAPI("guisim"); 
List<String> params = new ArrayList<String>();
params.add("-c=TlMap/map.sumo.cfg");

try
{
   SumoConfig conf = SumoConfig.load("TlMap/map.sumo.cfg");
   sumo.addParameters(params);
   sumo.addConnections("localhost", conf.getLocalPort());
} catch (Exception e) 
{
   e.printStackTrace();
}

// TraSMAPI initialization.
final TraSMAPI api = new TraSMAPI(); 
api.addSimulator(sumo);
api.launch();
api.connect();
api.start(); 

In this example, TraSMAPI was setup to work with the graphical version of the SUMO simulator. Subsequently, the simulator is executed with parameters corresponding to a given road network. The parameters in particular change from simulator to simulator and won't be analysed in this tutorial. After being executed, we request TraSMAPI to connect via sockets to the simulator using the method connect.

Basic Simulation Controls

The basic operation in simulation control is the request to execute a new simulation step. That is achieved though the simulationStep method. A typical execution cycle would look like this:

while(true)
{
   int currentStep = SumoCom.getCurrentSimStep();
   if(!api.simulationStep(0))
      break;
}
api.close();

The close method is called with the objective of closing the connection to the simulator. If the simulator was launched though the framework, then it will also be closed.

Interaction with simulation elements

The majority of the simulation elements can be manipulated by associating them with objects of the language. Please look into the documentation of each supported simulator in order to understand how to achieve this. The majority of the simulation elements can be manipulated by associating them with objects of the language. Examples include induction loops, traffic lights and vehicles. In the rest of the section, we will use a traffic light to illustrate this interaction.

Relating an object with a simulation element is a simple task, as long as the programmer knows the associated identifier.

TrafficLight tl = new SumoTrafficLight("tl0"); 

This shows how to associate an object, tl, a TrafficLight, with a Sumo traffic light whose identifier is tl0. Some simulators offer the possibility of listing the elements of given type. Whenever that is possible, static methods have been implemented in the corresponding classes. This methods are considered an extra to the basic functionality and should be avoided as they compromise portability. For reference, this would be the aspect of an invocation of this kind:

String[] tlIdList = SumoTrafficLight.getTrafficLightsIDList();

Modifying the state of a traffic light implies the definition of its colour for each of its lanes. The instantiation of the class Lane is made similarly to that of other objects, and will not be detailed.

The TrafficLight object has a method dedicated to change its colour for a given set of lanes. This method receives a vector of the lanes and the corresponding colour, for example:

Lane[] horLanes = {new SumoLane("1i_0"),new SumoLane("2i_0")};
tl.changeTrafficLightLanes(horLanes, 'G');

Contributing

We appreciate any help you could give by improving our code, documention, or by simpling creating an issue. If you wish you can contact us at stems.group@gmail.com

Submitting a Pull Request

  1. Fork it.
  2. Create a branch (git checkout -b my_trasmapi)
  3. Commit your changes (git commit -am "Added message type")
  4. Push to the branch (git push origin my_trasmapi)
  5. Open a Pull Request
  6. Enjoy a refreshing Diet Coke and wait

Published papers

License

Copyright 2016 STEMS-group

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.