Skip to content

Commit

Permalink
fixing style #22
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Feb 24, 2024
1 parent 3d2f0c8 commit dca1aa7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tests/complex/sumo/ToCDevice/use_cases/runScenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def printParameterSet(ia, rt, rr, md, t):
'--summary', summaryfile,
'--lanechange-file', lcfile,
'--error-log', logfile,
'--nogui', "false",
'--gui',
# '--verbose',
]
print("calling %s" % ' '.join(cmd))
Expand Down
40 changes: 18 additions & 22 deletions tests/complex/sumo/ToCDevice/use_cases/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,37 @@

import os
import sys
import optparse
# we need to import python modules from the $SUMO_HOME/tools directory
if "SUMO_HOME" in os.environ:
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
from sumolib import checkBinary # noqa
import sumolib # noqa
import traci # noqa

AV_identifier = "AVflow"
ToC_identifier = "AVflowToC."
routeID = "r0"
global options


def doToC(vehSet, changePerformed, timeUntilMRM, edgeID, distance):
global options
def doToC(vehSet, changePerformed, timeUntilMRM, edgeID, distance, verbose):
for vehID in vehSet:
distToTOR = traci.vehicle.getDrivingDistance(vehID, edgeID, distance)
if distToTOR < 0.:
changePerformed.add(vehID)
if vehID.startswith("AVflowToC."):
requestToC(vehID, timeUntilMRM)
if options.verbose:
if verbose:
t = traci.simulation.getCurrentTime() / 1000.
print("## Requesting ToC for vehicle '%s'!" % (vehID))
print("Requested ToC of %s at t=%s (until t=%s)" % (vehID, t, t + float(timeUntilMRM)))
printToCParams(vehID, True)
elif traci.vehicle.getTypeID(vehID).startswith("auto"):
if options.verbose:
if verbose:
print("## Informing AV '%s' about alternative path!" % (vehID))
traci.vehicle.setVehicleClass(vehID, "passenger")
# ~ return changePerformed


def run(timeUntilMRM, downwardEdgeID, distance, upwardEdgeID, upwardDist):
def run(timeUntilMRM, downwardEdgeID, distance, upwardEdgeID, upwardDist, options):
"""execute the TraCI control loop"""
# this is the list of vehicle states for the scenario, which each AV will traverse
downwardToCPending = set(traci.vehicle.getIDList())
Expand All @@ -82,7 +79,7 @@ def run(timeUntilMRM, downwardEdgeID, distance, upwardEdgeID, upwardDist):
if vehID.startswith(AV_identifier)])

# provide the ToCService at the traffic sign for informing the lane closure
doToC(downwardToCPending, downwardTocRequested, timeUntilMRM, downwardEdgeID, distance)
doToC(downwardToCPending, downwardTocRequested, timeUntilMRM, downwardEdgeID, distance, options.verbose)
downwardToCPending.difference_update(downwardTocRequested)

# keep book on performed ToCs and trigger best lanes update by resetting the route
Expand All @@ -100,7 +97,7 @@ def run(timeUntilMRM, downwardEdgeID, distance, upwardEdgeID, upwardDist):

# provide ToCService to the upwardTransitions
upwardTocPerformed = set()
doToC(upwardToCPending, upwardTocPerformed, 0., upwardEdgeID, upwardDist)
doToC(upwardToCPending, upwardTocPerformed, 0., upwardEdgeID, upwardDist, options.verbose)
upwardToCPending.difference_update(upwardTocPerformed)
if options.debug:
print("downwardTocRequested=%s" % downwardTocRequested)
Expand Down Expand Up @@ -145,9 +142,9 @@ def printToCParams(vehID, only_dynamic=False):


def get_options():
optParser = optparse.OptionParser()
optParser = sumolib.options.ArgumentParser()
optParser.add_option("-a", "--add-file", dest="afile", help="additional file")
optParser.add_option("-c", "--code", dest="code", help="scenario code")
optParser.add_option("--code", help="scenario code")
optParser.add_option("-e", "--error-log", dest="elfile", help="error log file")
optParser.add_option("-f", "--fcd-file", dest="opfile", help="fcd file")
optParser.add_option("-g", "--view-file", dest="vfile", help="sumo-gui view setting file")
Expand All @@ -156,14 +153,13 @@ def get_options():
optParser.add_option("-r", "--route-file", dest="rfile", help="route file")
optParser.add_option("-s", "--summary", dest="summary", help="summary file")
optParser.add_option("-t", "--time-MRM", dest="timeUntilMRM", default=8, help="time until MRM")
optParser.add_option("--nogui", action="store_false",
default=True, help="run the commandline version of sumo")
optParser.add_option("--gui", action="store_true",
default=False, help="run the GUI version of sumo")
optParser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="tell me what you are doing")
optParser.add_option("-d", "--debug", action="store_true", dest="debug",
default=False, help="debug messages")
options, args = optParser.parse_args()
return options
return optParser.parse_args()


# this is the main entry point of this script
Expand All @@ -177,17 +173,17 @@ def get_options():
print("time to MRM: %s" % (timeUntilMRM))
# this script has been called from the command line. It will start sumo as a
# server, then connect and run
if options.nogui:
sumoBinary = checkBinary('sumo')
if options.gui:
sumoBinary = sumolib.checkBinary('sumo-gui')
else:
sumoBinary = checkBinary('sumo-gui')
sumoBinary = sumolib.checkBinary('sumo')

# this is the normal way of using traci. sumo is started as a
# subprocess and then the python script connects and runs
traci.start(map(str, [sumoBinary, "-n", options.nfile, "-r", options.rfile, "-a", options.afile, "--step-length=0.25",
traci.start([sumoBinary, "-n", options.nfile, "-r", options.rfile, "-a", options.afile, "--step-length=0.25",
"--lateral-resolution=0.8", "--ignore-route-errors", "--step-method.ballistic",
"--fcd-output", options.opfile, "--gui-settings-file", options.vfile, "--summary", options.summary,
"--lanechange-output", options.lcfile, "--error-log", options.elfile, "--no-step-log", "true"]))
"--lanechange-output", options.lcfile, "--error-log", options.elfile, "--no-step-log"])

if code == "UC1_1":
downwardEdgeID = "approach2"
Expand All @@ -202,7 +198,7 @@ def get_options():
upwardDist = 3500.0

if downwardEdgeID and distance:
run(timeUntilMRM, downwardEdgeID, distance, upwardEdgeID, upwardDist)
run(timeUntilMRM, downwardEdgeID, distance, upwardEdgeID, upwardDist, options)

traci.close()
sys.stdout.flush()
2 changes: 1 addition & 1 deletion tests/complex/sumo/overtake/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later

# @file doItAll.py
# @file runner.py
# @author Michael Behrisch
# @date 2012-02-15

Expand Down
1 change: 1 addition & 0 deletions tests/complex/sumo/tls_emissions/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
import sumolib # noqa


def call(command, log):
print("-" * 79, file=log)
print(command, file=log)
Expand Down
2 changes: 1 addition & 1 deletion tests/complex/traci/vehicle/alightingPersons/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
nextStops = traci.vehicle.getStops(vehID, limit=1)
if len(nextStops) > 0:
stopID = nextStops[0].stoppingPlaceID
stopEdge = nextStops[0].lane.rsplit("_",1)[1]
stopEdge = nextStops[0].lane.rsplit("_", 1)[1]
alightingPassengers = []
for passengerID in passengerIDs:
nextStage = traci.person.getStage(passengerID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void main(String[] args) {
for (Map.Entry<String, TraCIResults> vehEntry : vsRes.entrySet()) {
System.out.println("Vehicle Subscription: id=" + vehEntry.getKey());
vehEntry.getValue().entrySet().stream().sorted(Map.Entry.comparingByKey())
.forEach(entry -> System.out.println(" variable id: " + entry.getKey() + " value: " + entry.getValue().getString()));
.forEach(entry -> System.out.println(" variable id: " + entry.getKey() + " value: " + entry.getValue().getString()));
}
}

Expand Down

0 comments on commit dca1aa7

Please sign in to comment.