Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/scenario_generation/demand_models/runner.py
169685 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
4
# Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file runner.py
16
# @author Daniel Krajzewicz
17
# @date 2013-10-30
18
19
# import osm network
20
21
22
import sys
23
import os
24
SUMO_HOME = os.environ.get('SUMO_HOME',
25
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..'))
26
sys.path.append(os.path.join(SUMO_HOME, 'tools'))
27
28
from sumolib.net.generator.network import Edge # noqa
29
from sumolib.net.generator.demand import Demand, Stream, LinearChange, WaveComposition # noqa
30
31
demand = Demand()
32
demand.addStream(Stream(None, None, None, 800, "from", "to", "passenger"))
33
vehicles1 = []
34
for s in demand.streams:
35
vehicles1.extend(s.toVehicles(0, 86400))
36
37
# demand.build(0, 3600, 3600, "net.net.xml", "linear.rou.xml")
38
39
demand = Demand()
40
demand.addStream(Stream(None, 0, 39600, 400, "from", "to", "passenger"))
41
demand.addStream(Stream(None, 39600, 46800, LinearChange(
42
400, 1200, 39600, 46800), "from", "to", "passenger"))
43
demand.addStream(Stream(None, 46800, 86400, 1200, "from", "to", "passenger"))
44
vehicles2 = []
45
for s in demand.streams:
46
vehicles2.extend(s.toVehicles(0, 86400))
47
# demand.build(0, 3600, 3600, "net.net.xml", "linear.rou.xml")
48
49
vehicles3 = [] # [600, 0, .000025, 14400]
50
demand = Demand()
51
demand.addStream(Stream(None, None, None, WaveComposition(
52
800, [[400, 0, .000025, 14400], [200, 0, .00001, 14400]]), "from", "to", "passenger"))
53
for s in demand.streams:
54
vehicles3.extend(s.toVehicles(0, 86400))
55
# demand.build(0, 3600, "net.net.xml", "linear.rou.xml")
56
57
STEP = 300
58
d1 = [0] * (86400 // STEP)
59
for v in vehicles1:
60
d = v.depart / STEP
61
d1[int(d)] = d1[int(d)] + 1
62
d2 = [0] * (86400 // STEP)
63
for v in vehicles2:
64
d = v.depart / STEP
65
d2[int(d)] = d2[int(d)] + 1
66
d3 = [0] * (86400 // STEP)
67
for v in vehicles3:
68
d = v.depart / STEP
69
d3[int(d)] = d3[int(d)] + 1
70
71
fdo = open("t1.csv", "w")
72
for i in range(0, 86400 // STEP):
73
fdo.write("%s;%s;%s;%s\n" % (
74
i * STEP, d1[i] * 3600 / STEP, d2[i] * 3600 / STEP, d3[i] * 3600 / STEP))
75
fdo.close()
76
77