Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/purgatory/inputs.py
169674 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2007-2025 German Aerospace Center (DLR) and others.
3
# This program and the accompanying materials are made available under the
4
# terms of the Eclipse Public License 2.0 which is available at
5
# https://www.eclipse.org/legal/epl-2.0/
6
# This Source Code may also be made available under the following Secondary
7
# Licenses when the conditions for such availability set forth in the Eclipse
8
# Public License 2.0 are satisfied: GNU General Public License, version 2
9
# or later which is available at
10
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
12
13
# @file inputs.py
14
# @author Yun-Pang Floetteroed
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2007-10-25
18
19
"""
20
This script is to retrieve the assignment parameters, the OD districts and the matrix from the input files.
21
Moreover, the link travel time for district connectors will be estimated.
22
"""
23
from __future__ import print_function
24
25
# read the analyzed matrix
26
27
28
def getMatrix(net, verbose, matrix, matrixSum, demandscale=None):
29
matrixPshort = []
30
startVertices = []
31
endVertices = []
32
Pshort_EffCells = 0
33
periodList = []
34
if verbose:
35
print('matrix:', str(matrix))
36
odpairs = 0
37
origins = 0
38
dest = 0
39
currentMatrixSum = 0.0
40
skipCount = 0
41
zones = 0
42
smallDemandNum = 0
43
for line in open(matrix):
44
if line[0] == '$':
45
visumCode = line[1:3]
46
if visumCode != 'VM':
47
skipCount += 1
48
elif line[0] != '*' and line[0] != '$':
49
skipCount += 1
50
if skipCount == 2:
51
for elem in line.split():
52
periodList.append(float(elem))
53
elif skipCount > 3:
54
if zones == 0:
55
for elem in line.split():
56
zones = int(elem)
57
elif len(startVertices) < zones:
58
for elem in line.split():
59
if len(elem) > 0:
60
for startVertex in net.getstartVertices():
61
if startVertex._id == elem:
62
startVertices.append(startVertex)
63
for endVertex in net.getendVertices():
64
if endVertex._id == elem:
65
endVertices.append(endVertex)
66
origins = len(startVertices)
67
dest = len(endVertices)
68
elif len(startVertices) == zones:
69
if odpairs % origins == 0:
70
matrixPshort.append([])
71
for item in line.split():
72
elem = float(item)
73
if demandscale is not None and demandscale != 1.:
74
elem *= demandscale
75
matrixPshort[-1].append(elem)
76
odpairs += 1
77
matrixSum += elem
78
currentMatrixSum += elem
79
if elem > 0.:
80
Pshort_EffCells += 1
81
if elem < 1. and elem > 0.:
82
smallDemandNum += 1
83
begintime = int(periodList[0])
84
assignPeriod = int(periodList[1]) - begintime
85
smallDemandRatio = float(smallDemandNum) / float(Pshort_EffCells)
86
87
if verbose:
88
print('Number of zones:', zones)
89
print('Number of origins:', origins)
90
print('Number of destinations:', dest)
91
print('begintime:', begintime)
92
print('currentMatrixSum:', currentMatrixSum)
93
print('Effective O-D Cells:', Pshort_EffCells)
94
print('number of start Vertices:', net.getstartCounts())
95
print('number of end Vertices):', net.getendCounts())
96
print('smallDemandRatio):', smallDemandRatio)
97
98
return matrixPshort, startVertices, endVertices, currentMatrixSum, begintime, assignPeriod, \
99
Pshort_EffCells, matrixSum, smallDemandRatio
100
101
# estimate the travel times on the district connectors
102
# assumption: all vehilces can reach the access links within 20 min (1200
103
# sec) from the respective traffic zone
104
105
106
def getConnectionTravelTime(startVertices, endVertices):
107
for vertex in startVertices:
108
weightList = []
109
for edge in vertex.getOutgoing():
110
weightList.append(float(edge.ratio))
111
if len(weightList) > 0:
112
minWeight = min(weightList)
113
114
for edge in vertex.getOutgoing():
115
edge.freeflowtime = (float(edge.ratio) / minWeight) * 1200.
116
edge.actualtime = edge.freeflowtime
117
118
for vertex in endVertices:
119
weightList = []
120
for edge in vertex.getIncoming():
121
weightList.append(float(edge.ratio))
122
if len(weightList) > 0:
123
minWeight = min(weightList)
124
125
for edge in vertex.getIncoming():
126
edge.freeflowtime = (float(edge.ratio) / minWeight) * 1200.
127
edge.actualtime = edge.freeflowtime
128
129