def getDrivingDistance2D(vehID, x, y): """getDrivingDistance2D(string, double, double) -> integer . """ trace._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1 + 4 + 1 + 4 + 4 + 1) trace._message.string += struct.pack("!BiBddB", tc.TYPE_COMPOUND, 2, tc.POSITION_2D, x, y, REQUEST_DRIVINGDIST) return trace._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
def convert2D(edgeID, pos, laneIndex=0, toGeo=False): posType = tc.POSITION_2D if toGeo: posType = tc.POSITION_LAT_LON trace._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+4+len(edgeID)+8+1 + 1+1) trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) trace._message.string += struct.pack("!Bi", tc.POSITION_ROADMAP, len(edgeID)) + edgeID trace._message.string += struct.pack("!dBBB", pos, laneIndex, tc.TYPE_UBYTE, posType) return trace._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "").read("!dd")
def convertRoad(x, y, isGeo=False): posType = tc.POSITION_2D if isGeo: posType = tc.POSITION_LAT_LON trace._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+8+8 + 1+1) trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) trace._message.string += struct.pack("!Bdd", posType, x, y) trace._message.string += struct.pack("!BB", tc.TYPE_UBYTE, tc.POSITION_ROADMAP) result = trace._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "") return result.readString(), result.readDouble(), result.read("!B")[0]
def getEffort(vehID, time, edgeID): """getEffort(string, double, string) -> double . """ trace._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID)) trace._message.string += ( struct.pack("!BiBiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time, tc.TYPE_STRING, len(edgeID)) + edgeID ) return trace._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID).readDouble()
def convertGeo(x, y, fromGeo=False): fromType = tc.POSITION_2D toType = tc.POSITION_LAT_LON if fromGeo: fromType = tc.POSITION_LAT_LON toType = tc.POSITION_2D trace._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+8+8 + 1+1) trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2) trace._message.string += struct.pack("!Bdd", fromType, x, y) trace._message.string += struct.pack("!BB", tc.TYPE_UBYTE, toType) return trace._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "").read("!dd")
def getDrivingDistance(vehID, edgeID, pos, laneID=0): """getDrivingDistance(string, string, double, integer) -> double . """ trace._beginMessage( tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1 + 4 + 1 + 4 + len(edgeID) + 4 + 1 + 1 ) trace._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2, tc.POSITION_ROADMAP, len(edgeID)) + edgeID trace._message.string += struct.pack("!dBB", pos, laneID, REQUEST_DRIVINGDIST) return trace._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
def getEffort(edgeID, time): """getEffort(string, double) -> double Returns the effort value used for (re-)routing which is valid on the edge at the given time. """ trace._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1+4) trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, trace._TIME2STEPS(time)) return trace._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID).readDouble()
def getAdaptedTraveltime(edgeID, time): """getAdaptedTraveltime(string, double) -> double Returns the travel time value (in s) used for (re-)routing which is valid on the edge at the given time. """ trace._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1+4) trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, trace._TIME2STEPS(time)) return trace._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID).readDouble()
def getEffort(edgeID, time): """getEffort(string, double) -> double Returns the effort value used for (re-)routing which is valid on the edge at the given time. """ trace._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1 + 4) trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, trace._TIME2STEPS(time)) return trace._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID).readDouble()
def getAdaptedTraveltime(edgeID, time): """getAdaptedTraveltime(string, double) -> double Returns the travel time value (in s) used for (re-)routing which is valid on the edge at the given time. """ trace._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1 + 4) trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, trace._TIME2STEPS(time)) return trace._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID).readDouble()
def getEffort(vehID, time, edgeID): """getEffort(string, double, string) -> double . """ trace._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID)) trace._message.string += struct.pack("!BiBiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time, tc.TYPE_STRING, len(edgeID)) + edgeID return trace._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID).readDouble()
def getDistanceRoad(edgeID1, pos1, edgeID2, pos2, isDriving=False): """getDistanceRoad(string, double, string, double, boolean) -> double . """ distType = tc.REQUEST_AIRDIST if isDriving: distType = tc.REQUEST_DRIVINGDIST trace._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST, "", 1+4 + 1+4+len(edgeID1)+8+1 + 1+4+len(edgeID2)+8+1 + 1) trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 3) trace._message.string += struct.pack("!Bi", tc.POSITION_ROADMAP, len(edgeID1)) + edgeID1 trace._message.string += struct.pack("!dBBi", pos1, 0, tc.POSITION_ROADMAP, len(edgeID2)) + edgeID2 trace._message.string += struct.pack("!dBB", pos2, 0, distType) return trace._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST, "").readDouble()
def getDrivingDistance(vehID, edgeID, pos, laneID=0): """getDrivingDistance(string, string, double, integer) -> double . """ trace._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1 + 4 + 1 + 4 + len(edgeID) + 4 + 1 + 1) trace._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2, tc.POSITION_ROADMAP, len(edgeID)) + edgeID trace._message.string += struct.pack("!dBB", pos, laneID, REQUEST_DRIVINGDIST) return trace._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
def getDistance2D(x1, y1, x2, y2, isGeo=False, isDriving=False): """getDistance2D(double, double, double, double, boolean, boolean) -> double . """ posType = tc.POSITION_2D if isGeo: posType = tc.POSITION_LAT_LON distType = tc.REQUEST_AIRDIST if isDriving: distType = tc.REQUEST_DRIVINGDIST trace._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST, "", 1+4 + 1+8+8 + 1+8+8 + 1) trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 3) trace._message.string += struct.pack("!Bdd", posType, x1, y1) trace._message.string += struct.pack("!BddB", posType, x2, y2, distType) return trace._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST, "").readDouble()