Path: blob/main/tests/complex/traci/bugs/ticket5114/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 Jakob Erdmann16# @date 2018-09-271718from __future__ import print_function19from __future__ import absolute_import20import os21import sys2223if "SUMO_HOME" in os.environ:24sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))2526import traci # noqa27import sumolib # noqa2829sumoBinary = sumolib.checkBinary('sumo')30traci.start([sumoBinary,31"-n", "input_net.net.xml",32"--no-step-log",33])3435print("getDistanceRoad (no connection):",36traci.simulation.getDistanceRoad("gneE0", 100, "gneE1", 100, isDriving=True))37print("getDistanceRoad (normal to normal):",38traci.simulation.getDistanceRoad("gneE4", 50, "-gneE2", 50, isDriving=True))39print("getDistanceRoad (normal to 1st internal):",40traci.simulation.getDistanceRoad("gneE4", 50, ":gneJ5_4", 5, isDriving=True))41print("getDistanceRoad (normal to 2nd internal):",42traci.simulation.getDistanceRoad("gneE4", 50, ":gneJ5_7", 5, isDriving=True))43print("getDistanceRoad (1st internal to normal):",44traci.simulation.getDistanceRoad(":gneJ5_4", 5, "-gneE2", 50, isDriving=True))45print("getDistanceRoad (1st internal to 2nd internal):",46traci.simulation.getDistanceRoad(":gneJ5_4", 5, ":gneJ5_7", 5, isDriving=True))47print("getDistanceRoad (2nd internal to normal):",48traci.simulation.getDistanceRoad(":gneJ5_7", 5, "-gneE2", 50, isDriving=True))49print("getDistanceRoad (2nd internal to 1st internal):",50traci.simulation.getDistanceRoad(":gneJ5_7", 5, ":gneJ5_4", 5, isDriving=True))5152traci.route.add("r", ["gneE4", "-gneE2"])53traci.vehicletype.setMaxSpeed("DEFAULT_VEHTYPE", 1)54traci.vehicle.add("v", "r")55traci.simulationStep()5657print("getDrivingDistance (no connection):",58traci.vehicle.getDrivingDistance("v", "gneE1", 100))59print("getDrivingDistance (normal to normal):",60traci.vehicle.getDrivingDistance("v", "-gneE2", 50))61print("getDrivingDistance (normal to 1st internal):",62traci.vehicle.getDrivingDistance("v", ":gneJ5_4", 5))63print("getDrivingDistance (normal to 2nd internal):",64traci.vehicle.getDrivingDistance("v", ":gneJ5_7", 5))65while traci.vehicle.getRoadID("v") != ":gneJ5_4":66traci.simulationStep()67print("getDrivingDistance (1st internal to normal):",68traci.vehicle.getDrivingDistance("v", "-gneE2", 50))69print("getDrivingDistance (1st internal to 2nd internal):",70traci.vehicle.getDrivingDistance("v", ":gneJ5_7", 5))71while traci.vehicle.getRoadID("v") != ":gneJ5_7":72traci.simulationStep()73print("getDrivingDistance (2nd internal to normal):",74traci.vehicle.getDrivingDistance("v", "-gneE2", 50))75print("getDrivingDistance (2nd internal to 1st internal):",76traci.vehicle.getDrivingDistance("v", ":gneJ5_4", 5))7778traci.close()798081