Example 3: Generating route plans and trajectories

As shown in the previous examples, SMARTS can create random vehicles during a simulation. By default, all these random vehicles are background vehicles, which can be of a large volume during a simulation. A simulation can also include foreground vehicles. The differentiation between foreground vehicles and background vehicles can provide a certain level of flexibility in setting up simulations for your research. A simulation can include the following three types of vehicles.

  1. Random background vehicles created during a simulation.
  2. User-defined background vehicles based on imported route plans.
  3. User-defined foreground vehicles based on imported route plans.

In this example, we first run a simulation that exports the route of a random background vehicle. We then run another simulation, which simulate a specific foreground vehicle based on the route created from the first simulation. In addition to the foreground vehicle, the second simulation will also include many random background vehicles, which may affect the movement of the foreground vehicle. The trajectory of the foreground vehicle will be exported from the second simulation. You can use the standalone version of SMARTS to replicate this example. The steps to run the simulations are detailed below.

First, we create the route plan of a random vehicle. You can create a small source area and a small destination area as shown in the following screenshot.

Next, set a few parameters as follows.

  • No. of random background private vehicles to 1
  • No. of random background trams to 0
  • No. of random background buses to 0
  • Max number of steps to 10
  • Output initial routes to BACKGROUND

Run the simulation. A random vehicle will be generated. Its route plan will be saved to a text file in the same directory of the simulator.

You need to check whether the route file actually contains a route plan. In certain situations, it is impossible to generate a route. For example, the simulator cannot generate a route if there was no node (an intersection or a road end) in source/destination areas. If there is no route in the route file, you need to re-define the source/destination area and try again.

Before running the next simulation, you should remove the source area and the destination area that are defined in the first simulation. This is because we want to include a number of random vehicles that are distributed across the whole area in the second simulation. To remove a source/destination area, move mouse pointer until the area is highlighted. Click the left mouse button to show a popup menu. Select Remove source/destination window from the menu.

After the source area and destination area are removed, import the route file into SMARTS. To do this, click the Change button on the right of Foreground route file and select the route file that was generated earlier. You can also set certain parameters as follows.

  • No. of random background private vehicles to 1000
  • Max number of steps to 500
  • Output initial routes to NONE
  • Output trajectories to FOREGROUND

Run the simulation until it ends. The trajectory of the foreground vehicles will be saved to a text file in the same directory of the simulator.

You can also output the travel time of foreground/background/all vehicles using the Output travel time option on the interface.