LoginSignup
1
0

More than 3 years have passed since last update.

sumo simulator でのトレースの取り方

Last updated at Posted at 2019-09-11

を(自分に必要な部分だけ)要点だけまとめたもの。個人的なメモなので細かい話は、省略してあります。

トレースをとるには、

sumo -c myConfig.sumocfg --fcd-output sumoTrace.xml

みたいに、起動時に指定するか、sumocfgファイルに書けば良い。
(追記:よく考えたら、このトレースファイルと、以下で指定したdumpファイルやtripファイルが同じものかどうか未確認)

sumocfgファイルへの追記方法はこのページには書いていないが、以下のように output タグで指定できる(どこかに書いてあった)。dumpはすべての時刻のすべての車のログ。tripは、各車がいつ出発していつゴールしたかのログ。自分で色々計算したかったらdumpの方を使うのが良い。但し、サイズは大きくなる。

<configuration>
    <input>
        <net-file value="sim0.net.xml"/>
        <route-files value="sim0.rou.xml"/>
        <gui-settings-file value="sim0.settings.xml"/>
    </input>
    <time>
        <begin value="0"/>
        <end value="2000"/>
    </time>
    <output>
        <netstate-dump value="sim0-dump.xml" />
        <tripinfo-output value="sim0-trip.xml" />
    </output>
</configuration>

TraceExporterを使うとns2/ns3, OMNET, Shawn, and PHEMのファイルが得られるらしいが、そもそもこれらを知らないので使わない。

には、xml2csv.py について書いてある。これを使うとトレースのxmlファイルをcsvに変換できる。この後pythonでオープンすれば、自由に解析できるので、楽。lxmlをインストールする必要あり。xsd.pyが必要。python3でないと動かない。

dumpをxml2csvすると、以下のようなCSVファイルになる。

timestep_time,edge_id,lane_id,vehicle_id,vehicle_pos,vehicle_speed
0.00,edge0111,edge0111_0,01to41.0,2.10,17.67
0.00,edge1011,edge1011_0,10to30S.0,2.10,15.64
1.00,edge0111,edge0111_0,01to41.0,19.53,17.43
1.00,edge1011,edge1011_0,10to30.0,2.10,14.31
1.00,edge1011,edge1011_0,10to30S.0,17.71,15.61

このCSVファイルを

data = np.genfromtxt(argvs[1], delimiter=',', skip_header=1, dtype=None, encoding=None)

みたいに、numpy (pandasでも良い)で読み込めば、

  • 各時刻の平均速度、平均台数
  • 各車の平均速度

みたいな計算ができる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0