sumo builds a grid city and simulates it

1. Demand

Construct a grid signal city, and then collect three indicators of traffic, speed, and density every 5 minutes of each lane in the grid city.

2. Tools

It is implemented using the open source traffic simulation software sumo. My computer is windows10, and then I downloaded the latest version of Eclipse SUMO sumo Version 1.12.0 from the official website.

3. Process

The sumo simulation requires a total of 3 files: 1. Supply, that is, the road network file, and the signal lights are also included in this file; 2. Demand, that is, individual travel routes. Because it is a microscopic simulation, it is detailed to each vehicle 3. The sumo simulation configuration file is used to set the input and output of the simulation. Next, we will introduce in detail how to build these three files from 0.

3.1 Supply

There are many ways to build a road network, such as importing shapefiles, crawling from osm, sumo provides a lot of scripts to help users build road networks, but since my requirement is to build a grid city, it can be used directly The command netgenerate given by sumo can generate the required network with one click , such as grid, spyder, and random network, and the number of lanes and signal lights can be specified during the generation process, but it seems that the signal light settings can only be set simply. Cannot be highly customized. I simply use the following command to generate the raster network. Here I only want a single lane, so the number of lanes is the default. Of course, double lanes can be generated, just add the lane parameters, and then you can specify the number of left-turn lanes. For example, if a double lane is generated, the number of left turns is 1, just add The above parameters –turn-lanes=1 and -L=2 are enough, and the intersection will be automatically channeled into three lanes, one left-turn lane, one through lane, and one through right lane.

netgenerate --grid --grid.x-number=8 --grid.length=200 -j=traffic_light --tls.cycle.time=60 --output-file=grid_network.net.xml

The above code sets each intersection as a signal intersection, and the period is 60s, but it may not be the signal scheme I need, so the following settings are also required.
First open the netedit of sumo, manually configure a certain signal, save the configuration to the local xml file, open the xml file, and copy the same intersection as the signal intersection, for example, I put the B0-G0 intersection All are set to the same scheme. After modifying the xml file, execute the following command to configure the signals at the B0-G0 intersection in .net.xml to the specified signal scheme.
Then repeat this operation to set up all the signals. Of course, you can also configure the xml file of the signal scheme at one time, just execute one command, or configure it separately, and execute the command multiple times to generate the required road network files.
insert image description here

<additional xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/additional_file.xsd">
    <tlLogic id="B0" type="static" programID="0" offset="0">
        <phase duration="27" state="GGGGrrrrr"/>
        <phase duration="3" state="GyyGrrrrr"/>
        <phase duration="27" state="GrrGGGGGG"/>
        <phase duration="3" state="GrrGyyyyy"/>
    </tlLogic>
    <tlLogic id="C0" type="static" programID="0" offset="0">
        <phase duration="27" state="GGGGrrrrr"/>
        <phase duration="3" state="GyyGrrrrr"/>
        <phase duration="27" state="GrrGGGGGG"/>
        <phase duration="3" state="GrrGyyyyy"/>
    </tlLogic>
    <tlLogic id="D0" type="static" programID="0" offset="0">
        <phase duration="27" state="GGGGrrrrr"/>
        <phase duration="3" state="GyyGrrrrr"/>
        <phase duration="27" state="GrrGGGGGG"/>
        <phase duration="3" state="GrrGyyyyy"/>
    </tlLogic>
    <tlLogic id="E0" type="static" programID="0" offset="0">
        <phase duration="27" state="GGGGrrrrr"/>
        <phase duration="3" state="GyyGrrrrr"/>
        <phase duration="27" state="GrrGGGGGG"/>
        <phase duration="3" state="GrrGyyyyy"/>
    </tlLogic>
    <tlLogic id="F0" type="static" programID="0" offset="0">
        <phase duration="27" state="GGGGrrrrr"/>
        <phase duration="3" state="GyyGrrrrr"/>
        <phase duration="27" state="GrrGGGGGG"/>
        <phase duration="3" state="GrrGyyyyy"/>
    </tlLogic>
    <tlLogic id="G0" type="static" programID="0" offset="0">
        <phase duration="27" state="GGGGrrrrr"/>
        <phase duration="3" state="GyyGrrrrr"/>
        <phase duration="27" state="GrrGGGGGG"/>
        <phase duration="3" state="GrrGyyyyy"/>
    </tlLogic>
</additional>
根据信号灯方案配置文件为指定的交叉口配置信号方案,-s为输入的路网文件,-i为输入的信号方案文件,-o是输出的配置好指定交叉口信号方案的路网文件
netconvert -s "./network/grid_network.net.xml" -i "./network/tl_pro_down.xml" -o "./network/grid_network_d.net.xml"

3.2 Requirements

The demand setting is relatively simple. There are many ways to set the demand in sumo. The most basic ones are trip and routes. The final demand file required by sumo is the .rou.xml file, which contains the route and departure time of each vehicle. In my requirements, I can be random, so I directly use the randomTrips.py command to generate requirements. First, the first step is to generate trips. The trip file can be considered as the OD of each car. The following code randomly generates 5 on every s road network. The OD of the car.

为1800s整个路网生成随机的trip,-n为路网文件,-e是结束时间,-p是每秒生成的车辆数,--binomial为每秒结束出行的车辆数的分布的最大值,-o是生成的trips.xml的保存文件名
python "E:\Program Files\sumo\tools\randomTrips.py" -n "./network/grid_network_dlurm.net.xml" -e 1800 -p 0.2 -o "./random_demand/random_trip.trips.xml"

After generating OD, further generate routes according to the shortest path, as follows:

将生成的trips.xml文件填补为rou.xml文件,-n是路网文件,--route-files为trips.xml文件,-o为输出的rou.xml文件
duarouter -n "./network/grid_network_dlurm.net.xml"  --route-files "./random_demand/random_trip.trips.xml" -o "./random_demand/random_routes.rou.xml"

In this way, the generation of the requirements file is completed.

3.3 Configure sumo simulation file

Just write the input and output files directly, and you can understand it by looking at the code below, so I won’t say much. The only thing that needs to be explained is the setting of the output file. In the following code, there is only input but no output file configuration. This is because the output file setting is written in < additional − filesvalue = " addition . add . xml " / > <additional-files value="addition.add.xml"/><additionalfilesvalue="addition.add.xml"/> In this additional-files, see the following code for details of this file. The freq parameter in it is set to collect data every 300s.

<?xml version="1.0" encoding="iso-8859-1"?>

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/sumoConfiguration.xsd">

    <input>
        <net-file value="E:\study_e\mfd_optimization\simulation_result\mfd_data_basedon_sumo\network\grid_network_dlurm.net.xml"/>
        <additional-files value="addition.add.xml"/>
        <route-files value="E:\study_e\mfd_optimization\simulation_result\mfd_data_basedon_sumo\random_demand\random_routes.rou.xml"/>
    </input>

    <time>
        <begin value="0"/>
        <end value="86400"/>
    </time>

    

</configuration>
<additional>
    <edgeData id="EDGE_MEASUREMENT" file="edge_data_output.xml" freq="300" excludeEmpty="true" />
</additional>

3.4 Simulation

The simulation is easy. Open the configuration file with sumo-gui, and click to run. The delay controls the running speed of the simulation. 0 is the fastest, and the bigger it is, the slower it runs. You can choose real world on the standard side, which looks better.

3.5 Result processing

The output file generated by the simulation is also xml, which can be processed directly or converted into a csv file with the sumo command, and then the csv can be processed by various software, which is very convenient.

将最终结果的xml文件转化为csv文件
python "E:\Program Files\sumo\tools\xml\xml2csv.py" --separator=","  "./sumo_simu/edge_data_output.xml"

reference link

https://tech.chaotictoejam.com/index.php/2020/07/09/how-to-create-a-network-in-sumo/

Guess you like

Origin blog.csdn.net/qq_39805362/article/details/124191877