Path: blob/main/tests/complex/traci/bugs/ticket1433/runner.py
169708 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file runner.py14# @author Laura Bieker-Walz15# @date 2020-09-041617from __future__ import absolute_import18from __future__ import print_function1920import os21import sys22import subprocess2324# we need to import python modules from the $SUMO_HOME/tools directory25if 'SUMO_HOME' in os.environ:26sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))2728from sumolib import checkBinary # noqa29import traci # noqa303132def run():33"""execute the TraCI control loop"""34step = 035while traci.simulation.getMinExpectedNumber() > 0:36traci.simulationStep()37step += 138ids = traci.simulation.getDepartedIDList()39# print(ids)40if "1" in ids:41traci.vehicle.setRoute("1", ["4/1to3/1", "3/1to2/1", "2/1to1/1"])42traci.close()43sys.stdout.flush()444546# this is the main entry point of this script47if __name__ == "__main__":4849sumoBinary = checkBinary('sumo')50# prepare state51subprocess.call([sumoBinary, "-c", "sumo.sumocfg"] + sys.argv[1:])5253args = [sumoBinary, "-n", "input_net.net.xml",54"-a", "input_routes.rou.xml",55"--load-state", "input_state.xml",56"--no-step-log",57"--begin", "9"]5859args += sys.argv[1:]6061traci.start(args)62run()636465