Path: blob/main/tests/complex/traci/bugs/ticket4432/runner.py
169708 views
#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file runner.py15# @author Leonhard Luecken16# @author Michael Behrisch17# @author Jakob Erdmann18# @author Daniel Krajzewicz19# @date 2011-03-04202122from __future__ import print_function23from __future__ import absolute_import24import os25import sys2627if "SUMO_HOME" in os.environ:28sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))2930import traci # noqa31import sumolib # noqa323334def countWrittenTrips(fname):35return len(list(sumolib.xml.parse_fast(fname, 'tripinfo', ['id'])))363738def lastLine(fname):39with open(fname) as f:40lines = f.readlines()41return None if len(lines) == 0 else lines[-1].strip()424344sumo = sumolib.checkBinary('sumo')45opts = [46'-n', 'input_net.net.xml',47'-r', 'input_routes.rou.xml',48'--no-step-log',49'--duration-log.statistics',50'-S', '-Q',51]52traci.start([sumo] + opts + ['--tripinfo-output', 'tripinfos.xml', '-l', 'log']53# + ['--save-configuration', 'debug.sumocfg']54)555657while traci.simulation.getMinExpectedNumber() > 0:58traci.simulationStep()5960print("tripinfos at last step: %s" % countWrittenTrips('tripinfos.xml'))61print("logfile at last step: %s" % lastLine('log'))62traci.load(opts + ['--tripinfo-output', 'tripinfos2.xml', '-l', 'log2'])63traci.simulationStep()64print("tripinfos after load: %s" % countWrittenTrips('tripinfos.xml'))65print("logfile after load: %s" % lastLine('log'))6667while traci.simulation.getMinExpectedNumber() > 0:68traci.simulationStep()69print("tripinfos2 at last step: %s" % countWrittenTrips('tripinfos2.xml'))70print("logfile2 at last step: %s" % lastLine('log2'))7172traci.close()73print("tripinfos2 after close: %s" % countWrittenTrips('tripinfos2.xml'))74print("logfile2 after close: %s" % lastLine('log2'))75# done767778