Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/jtrrouter/randomized_flow/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) 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 runner.py
16
# @author Jakob Erdmann
17
# @author Laura Bieker
18
# @author Michael Behrisch
19
# @author Daniel Krajzewicz
20
# @date 2011-01-18
21
22
from __future__ import absolute_import
23
from __future__ import print_function
24
25
import sys
26
import os
27
import subprocess
28
import random
29
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
30
from sumolib import checkBinary # noqa
31
32
33
def get_depart_lines(route_file):
34
with open(route_file) as rf:
35
return [d for d in rf if 'depart' in d]
36
37
38
output_file1 = 'output1.rou.xml'
39
output_file2 = 'output2.rou.xml'
40
41
args = [checkBinary('jtrrouter'),
42
'--net-file', 'input_net.net.xml',
43
'--route-files', 'input_flows.flows.xml',
44
'--turn-ratio-files', 'input_turns.turns.xml',
45
'--output-file', output_file1,
46
'--sinks=end',
47
'--seed', None,
48
'--no-step-log',
49
'--randomize-flows']
50
51
args[11] = str(random.randint(0, 2 ** 31))
52
subprocess.call(args)
53
route_lines1 = get_depart_lines(output_file1)
54
55
args[8] = output_file2
56
args[11] = str(random.randint(0, 2 ** 31))
57
subprocess.call(args)
58
route_lines2 = get_depart_lines(output_file2)
59
60
if route_lines1 != route_lines2:
61
print('test passed. output is random')
62
else:
63
print('test failed. output is deterministic')
64
65