Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def printToCParams(vehID, only_dynamic=False):
holder = traci.vehicle.getParameter(vehID, "device.toc.holder")
manualType = traci.vehicle.getParameter(vehID, "device.toc.manualType")
automatedType = traci.vehicle.getParameter(vehID, "device.toc.automatedType")
responseTime = traci.vehicle.getParameter(vehID, "device.toc.responseTime")
recoveryRate = traci.vehicle.getParameter(vehID, "device.toc.recoveryRate")
initialAwareness = traci.vehicle.getParameter(vehID, "device.toc.initialAwareness")
mrmDecel = traci.vehicle.getParameter(vehID, "device.toc.mrmDecel")
dynamicToCThreshold = traci.vehicle.getParameter(vehID, "device.toc.dynamicToCThreshold")
currentAwareness = traci.vehicle.getParameter(vehID, "device.toc.currentAwareness")
state = traci.vehicle.getParameter(vehID, "device.toc.state")
speed = traci.vehicle.getSpeed(vehID)
print("time", traci.simulation.getTime())
print("ToC device infos for vehicle '%s'" % vehID)
if not only_dynamic:
print("Static parameters:")
print(" holder = %s" % holder)
print(" manualType = %s" % manualType)
print(" automatedType = %s" % automatedType)
print(" responseTime = %s" % responseTime)
print(" recoveryRate = %s" % recoveryRate)
print(" initialAwareness = %s" % initialAwareness)
print(" mrmDecel = %s" % mrmDecel)
print(" dynamicToCThreshold = %s" % dynamicToCThreshold)
print("Dynamic parameters:")
print(" currentAwareness = %s" % currentAwareness)
print(" currentSpeed = %s" % speed)
vehID, "device.driverstate.errorNoiseIntensityCoefficient")
speedDifferenceErrorCoefficient = traci.vehicle.getParameter(
vehID, "device.driverstate.speedDifferenceErrorCoefficient")
headwayErrorCoefficient = traci.vehicle.getParameter(vehID, "device.driverstate.headwayErrorCoefficient")
speedDifferenceChangePerceptionThreshold = traci.vehicle.getParameter(
vehID, "device.driverstate.speedDifferenceChangePerceptionThreshold")
headwayChangePerceptionThreshold = traci.vehicle.getParameter(
vehID, "device.driverstate.headwayChangePerceptionThreshold")
maximalReactionTime = traci.vehicle.getParameter(
vehID, "device.driverstate.maximalReactionTime")
originalReactionTime = traci.vehicle.getParameter(
vehID, "device.driverstate.originalReactionTime")
actionStepLength = traci.vehicle.getParameter(
vehID, "device.driverstate.actionStepLength")
actionStepLengthVeh = traci.vehicle.getActionStepLength(vehID)
traci.vehicle.getSpeed(vehID)
print("time", traci.simulation.getTime())
print("Driver state device infos for vehicle '%s'" % vehID)
if not only_dynamic:
print("Static parameters:")
print(" minAwareness = %s" % minAwareness)
print(" initialAwareness = %s" % initialAwareness)
print(" errorTimeScaleCoefficient = %s" % errorTimeScaleCoefficient)
print(" errorNoiseIntensityCoefficient = %s" % errorNoiseIntensityCoefficient)
print(" speedDifferenceErrorCoefficient = %s" % speedDifferenceErrorCoefficient)
print(" headwayErrorCoefficient = %s" % headwayErrorCoefficient)
print(" speedDifferenceChangePerceptionThreshold = %s" % speedDifferenceChangePerceptionThreshold)
print(" headwayChangePerceptionThreshold = %s" % headwayChangePerceptionThreshold)
print(" maximalReactionTime = %s" % maximalReactionTime)
print(" originalReactionTime = %s" % originalReactionTime)
print("Dynamic parameters:")
def checkOffRoad(vehID):
print(("veh", vehID,
"speed", traci.vehicle.getSpeed(vehID),
"pos", posToString(traci.vehicle.getPosition(vehID)),
"pos3d", posToString(traci.vehicle.getPosition3D(vehID)),
"angle", traci.vehicle.getAngle(vehID),
"road", traci.vehicle.getRoadID(vehID),
"lane", traci.vehicle.getLaneID(vehID),
"lanePos", traci.vehicle.getLanePosition(vehID),
"CO2", traci.vehicle.getCO2Emission(vehID)
))
def printToCParams(vehID, only_dynamic=False):
holder = traci.vehicle.getParameter(vehID, "device.toc.holder")
manualType = traci.vehicle.getParameter(vehID, "device.toc.manualType")
automatedType = traci.vehicle.getParameter(vehID, "device.toc.automatedType")
responseTime = traci.vehicle.getParameter(vehID, "device.toc.responseTime")
recoveryRate = traci.vehicle.getParameter(vehID, "device.toc.recoveryRate")
initialAwareness = traci.vehicle.getParameter(vehID, "device.toc.initialAwareness")
mrmDecel = traci.vehicle.getParameter(vehID, "device.toc.mrmDecel")
currentAwareness = traci.vehicle.getParameter(vehID, "device.toc.currentAwareness")
state = traci.vehicle.getParameter(vehID, "device.toc.state")
speed = traci.vehicle.getSpeed(vehID)
print("time", traci.simulation.getTime())
print("ToC device infos for vehicle '%s'" % vehID)
if not only_dynamic:
print("Static parameters:")
print(" holder = %s" % holder)
print(" manualType = %s" % manualType)
print(" automatedType = %s" % automatedType)
print(" responseTime = %s" % responseTime)
print(" recoveryRate = %s" % recoveryRate)
print(" initialAwareness = %s" % initialAwareness)
print(" mrmDecel = %s" % mrmDecel)
print("Dynamic parameters:")
print(" currentAwareness = %s" % currentAwareness)
print(" currentSpeed = %s" % speed)
print(" state = %s" % state)
print(e, file=sys.stderr)
print("recovering from exception after asking for unknown device")
try:
print(traci.vehicle.getParameter(electricVeh, "device.battery.foobar"))
except traci.TraCIException as e:
if traci.isLibsumo():
print(e, file=sys.stderr)
print("recovering from exception after asking for unknown device parameter")
traci.vehicle.subscribe(electricVeh, [tc.VAR_POSITION, tc.VAR_POSITION3D])
for i in range(10):
step()
print(('%s speed="%s" consumed="%s" charged="%s" cap="%s" maxCap="%s" station="%s" mass=%s emissionClass=%s ' +
'electricityConsumption=%s') % (
electricVeh,
traci.vehicle.getSpeed(electricVeh),
traci.vehicle.getParameter(electricVeh, "device.battery.energyConsumed"),
traci.vehicle.getParameter(electricVeh, "device.battery.energyCharged"),
traci.vehicle.getParameter(electricVeh, "device.battery.actualBatteryCapacity"),
traci.vehicle.getParameter(electricVeh, "device.battery.maximumBatteryCapacity"),
traci.vehicle.getParameter(electricVeh, "device.battery.chargingStationId"),
traci.vehicle.getParameter(electricVeh, "device.battery.vehicleMass"),
traci.vehicle.getEmissionClass(electricVeh),
traci.vehicle.getElectricityConsumption(electricVeh),
))
print(sorted(traci.vehicle.getSubscriptionResults(electricVeh).items()))
# test for adding a trip
traci.route.add("trip2", ["3si", "4si"])
traci.vehicle.addLegacy("triptest2", "trip2", typeID="reroutingType")
print("triptest route:", traci.vehicle.getRoute("triptest2"))
step()
print("triptest route:", traci.vehicle.getRoute("triptest2"))
def printToCParams(vehID, only_dynamic=False):
holder = traci.vehicle.getParameter(vehID, "device.toc.holder")
manualType = traci.vehicle.getParameter(vehID, "device.toc.manualType")
automatedType = traci.vehicle.getParameter(vehID, "device.toc.automatedType")
responseTime = traci.vehicle.getParameter(vehID, "device.toc.responseTime")
recoveryRate = traci.vehicle.getParameter(vehID, "device.toc.recoveryRate")
initialAwareness = traci.vehicle.getParameter(vehID, "device.toc.initialAwareness")
mrmDecel = traci.vehicle.getParameter(vehID, "device.toc.mrmDecel")
currentAwareness = traci.vehicle.getParameter(vehID, "device.toc.currentAwareness")
state = traci.vehicle.getParameter(vehID, "device.toc.state")
speed = traci.vehicle.getSpeed(vehID)
print("time", traci.simulation.getTime())
print("ToC device infos for vehicle '%s'" % vehID)
if not only_dynamic:
print("Static parameters:")
print(" holder = %s" % holder)
print(" manualType = %s" % manualType)
print(" automatedType = %s" % automatedType)
print(" responseTime = %s" % responseTime)
print(" recoveryRate = %s" % recoveryRate)
print(" initialAwareness = %s" % initialAwareness)
print(" mrmDecel = %s" % mrmDecel)
print("Dynamic parameters:")
print(" currentAwareness = %s" % currentAwareness)
print(" currentSpeed = %s" % speed)
print(" state = %s" % state)
def check(vehID):
print("examining", vehID)
print("speed", traci.vehicle.getSpeed(vehID))
print("speed w/o traci", traci.vehicle.getSpeedWithoutTraCI(vehID))
print("acceleration", traci.vehicle.getAcceleration(vehID))
print("lane", traci.vehicle.getLaneID(vehID))
print("lanePos", traci.vehicle.getLanePosition(vehID))
:rtype: list[int]
"""
merges = [-1] * len(platoons)
lane_changes = [False] * len(platoons)
for i in range(len(platoons) - 1):
if platoons[i].is_splitting():
continue
if platoons[i].leader_wants_to_leave(edge_filter) and platoons[i].length() == 1:
continue
min_distance = max_distance
index = -1
l1 = platoons[i].length()
speed_1 = traci.vehicle.getSpeed(platoons[i].get_leader())
max_speed_1 = traci.vehicle.getMaxSpeed(platoons[i].get_leader())
allowed_speed_1 = traci.vehicle.getAllowedSpeed(platoons[i].get_leader())
lane_1 = platoons[i].get_desired_lane()
lane_id_1 = platoons[i].get_desired_lane_id()
road_max_speed = traci.lane.getMaxSpeed(lane_id_1)
routes = platoons[i].get_routes_list()
edges_list = platoons[i].get_edges_list()
for j in range(i + 1, len(platoons)):
l2 = platoons[j].length()
if platoons[j].is_splitting() or l1 + l2 > max_platoon_length:
continue
if platoons[j].leader_wants_to_leave(edge_filter) and platoons[j].length() == 1:
continue
def initialize_simulation(self):
if not self.initial_config:
# Get initial state of each vehicle, and store in initial config object
for veh_id in self.ids:
edge_id = traci.vehicle.getRoadID(veh_id)
route_id = traci.vehicle.getRouteID(veh_id)
lane_id = traci.vehicle.getLaneID(veh_id)
lane_index = traci.vehicle.getLaneIndex(veh_id)
lane_pos = traci.vehicle.getLanePosition(veh_id)
pos = traci.vehicle.getPosition(veh_id)
angle = traci.vehicle.getAngle(veh_id)
speed = traci.vehicle.getSpeed(veh_id)
self.initial_config[veh_id] = (edge_id, route_id, lane_id, lane_index, lane_pos, pos, angle, speed)
self.reset()