Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/output/parkingSearchTraffic.py
169674 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) 2008-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 parkingSearchTraffic.py
16
# @author Michael Behrisch
17
# @date 2021-11-05
18
19
from __future__ import absolute_import
20
from __future__ import print_function
21
import os
22
import sys
23
sys.path.append(os.path.join(os.environ["SUMO_HOME"], 'tools'))
24
import sumolib # noqa
25
from sumolib.options import ArgumentParser # noqa
26
27
28
def parse_args():
29
optParser = ArgumentParser()
30
optParser.add_argument("net", help="net file")
31
optParser.add_argument("routes", help="route file")
32
return optParser.parse_args()
33
34
35
def main(net, routes):
36
net = sumolib.net.readNet(net)
37
dist = sumolib.miscutils.Statistics("Distance")
38
time = sumolib.miscutils.Statistics("Time")
39
walk_dist = sumolib.miscutils.Statistics("Walking Distance")
40
for vehicle in sumolib.xml.parse(routes, 'vehicle'):
41
if not vehicle.stop:
42
print("Warning! Vehicle '%s' did not arrive." % vehicle.id)
43
continue
44
if vehicle.routeDistribution and vehicle.stop:
45
replace_index = None
46
for r in vehicle.routeDistribution[0].route:
47
if replace_index is None and r.replacedOnEdge:
48
replace_index = len(r.edges.split())
49
replace_time = r.replacedAtTime
50
extra_route = r.edges.split()[replace_index:]
51
length = sum([net.getEdge(e).getLength() for e in extra_route])
52
dist.add(length, vehicle.id)
53
time.add(sumolib.miscutils.parseTime(vehicle.stop[0].started) -
54
sumolib.miscutils.parseTime(replace_time), vehicle.id)
55
if extra_route:
56
walk, _ = net.getShortestPath(net.getEdge(extra_route[-1]), net.getEdge(extra_route[0]),
57
ignoreDirection=True)
58
walk_length = sum([e.getLength() for e in walk])
59
else:
60
walk_length = 0
61
walk_dist.add(walk_length, vehicle.id)
62
else:
63
dist.add(0, vehicle.id)
64
time.add(0, vehicle.id)
65
walk_dist.add(0, vehicle.id)
66
print(dist)
67
print(time)
68
print(walk_dist)
69
70
71
if __name__ == "__main__":
72
options = parse_args()
73
main(options.net, options.routes)
74
75