Path: blob/main/tests/tools/sumolib/getShortestRoute/runner.py
428387 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2008-2026 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 Jakob Erdmann15# @date1617from __future__ import absolute_import18from __future__ import print_function1920import os21import sys22if 'SUMO_HOME' in os.environ:23tools = os.path.join(os.environ['SUMO_HOME'], 'tools')24sys.path.append(tools)25else:26sys.exit("please declare environment variable 'SUMO_HOME'")27import sumolib # noqa2829net = sumolib.net.readNet(sys.argv[1], withInternal=True, withLatestPrograms=True)30SC = net.getEdge("SC")31CE = net.getEdge("CE")32EC = net.getEdge("EC")33print("%s %.2f" % net.getShortestPath(SC, CE))34route = net.getShortestPath(SC, CE, vClass="passenger")35print("%s %.2f" % route)36print("%s %.2f" % net.getShortestPath(SC, CE, vClass="bus"))37print("%s %.2f" % net.getShortestPath(SC, CE, withInternal=True))38route2 = net.getShortestPath(SC, CE, vClass="passenger", withInternal=True)39print("%s %.2f" % route2)40routeA = tuple(sumolib.route.addInternal(net, route[0]))41print(routeA, routeA == route2[0])42print("%s %.2f" % net.getShortestPath(net.getEdge(":C_12"), CE))43print("%s %.2f" % net.getShortestPath(net.getEdge(":C_22"), CE))44print("%s %.2f" % net.getShortestPath(SC, net.getEdge(":C_15")))45print("%s %.2f" % net.getShortestPath(net.getEdge(":C_12"), net.getEdge(":C_15")))46print("%s %.2f" % net.getShortestPath(CE, SC))47print("%s %.2f" % net.getShortestPath(CE, SC, ignoreDirection=True))4849print("%s %.2f" % net.getShortestPath(SC, EC))50print("%s %.2f" % net.getShortestPath(SC, EC, ignoreDirection=True))515253