Exemplo n.º 1
0
def add(routeID, edges):
    trace._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID,
                        1+4+sum(map(len, edges))+4*len(edges))
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edges))
    for e in edges:
        trace._message.string += struct.pack("!i", len(e)) + e
    trace._sendExact()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
def setOffset(viewID, x, y):
    """setOffset(string, double, double) -> None
    
    Set the current offset for the given view.
    """
    trace._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_OFFSET, viewID, 1+8+8)
    trace._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    trace._sendExact()
Exemplo n.º 4
0
def adaptTraveltime(edgeID, time):
    """adaptTraveltime(string, double) -> None
    
    Adapt the travel time value (in s) used for (re-)routing for the given edge.
    """
    trace._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1+4+1+8)
    trace._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, time)
    trace._sendExact()
Exemplo n.º 5
0
def setBoundary(viewID, xmin, ymin, xmax, ymax):
    """setBoundary(string, double, double, double, double) -> None
    
    Set the current boundary for the given view (see getBoundary()).
    """
    trace._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_BOUNDARY, viewID, 1+8+8+8+8)
    trace._message.string += struct.pack("!Bdddd", tc.TYPE_BOUNDINGBOX, xmin, ymin, xmax, ymax)
    trace._sendExact()
Exemplo n.º 6
0
def add(poiID, x, y, color, poiType="", layer=0):
    trace._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.ADD, poiID, 1+4 + 1+4+len(poiType) + 1+1+1+1+1 + 1+4 + 1+8+8)
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(poiType)) + poiType
    trace._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, layer)
    trace._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    trace._sendExact()
Exemplo n.º 7
0
def setEffort(edgeID, effort):
    """setEffort(string, double) -> None
    
    Adapt the effort value used for (re-)routing for the given edge.
    """
    trace._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1+4+1+8)
    trace._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, effort)
    trace._sendExact()
Exemplo n.º 8
0
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")
Exemplo n.º 9
0
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]
Exemplo n.º 10
0
def moveToVTD(vehID, edgeID, lane, x, y):
    trace._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO_VTD, vehID, 1 + 4 + 1 + 4 + len(edgeID) + 1 + 4 + 1 + 8 + 1 + 8
    )
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(edgeID)) + edgeID
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, lane)
    trace._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, x)
    trace._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, y)
    trace._sendExact()
Exemplo n.º 11
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()
Exemplo n.º 12
0
def setStop(vehID, edgeID, pos=1.0, laneIndex=0, duration=2 ** 31 - 1):
    trace._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_STOP, vehID, 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8 + 1 + 1 + 1 + 4
    )
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(edgeID)) + edgeID
    trace._message.string += struct.pack(
        "!BdBBBi", tc.TYPE_DOUBLE, pos, tc.TYPE_BYTE, laneIndex, tc.TYPE_INTEGER, duration
    )
    trace._sendExact()
Exemplo n.º 13
0
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()
Exemplo n.º 14
0
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")
Exemplo n.º 15
0
def add(polygonID, shape, color, fill=False, polygonType="", layer=0):
    trace._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.ADD, polygonID, 1+4 + 1+4+len(polygonType) + 1+1+1+1+1 + 1+1 + 1+4 + 1+1+len(shape)*(8+8))
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 5)
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(polygonType)) + polygonType
    trace._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    trace._message.string += struct.pack("!BB", tc.TYPE_UBYTE, int(fill))
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, layer)
    trace._message.string += struct.pack("!BB", tc.TYPE_POLYGON, len(shape))
    for p in shape:
        trace._message.string += struct.pack("!dd", *p)
    trace._sendExact()
Exemplo n.º 16
0
def setColor(vehID, color):
    """setColor(string, (integer, integer, integer, integer))
    sets color for vehicle with the given ID.
    i.e. (255,0,0,0) for the color red. 
    The fourth integer (alpha) is currently ignored
    """
    trace._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_COLOR, vehID, 1 + 1 + 1 + 1 + 1)
    trace._message.string += struct.pack(
        "!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3])
    )
    trace._sendExact()
Exemplo n.º 17
0
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()
Exemplo n.º 18
0
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()
Exemplo n.º 19
0
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()
Exemplo n.º 20
0
def add(vehID, routeID, depart=DEPART_NOW, pos=0, speed=0, lane=0, typeID="DEFAULT_VEHTYPE"):
    trace._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE,
        tc.ADD,
        vehID,
        1 + 4 + 1 + 4 + len(typeID) + 1 + 4 + len(routeID) + 1 + 4 + 1 + 8 + 1 + 8 + 1 + 1,
    )
    if depart > 0:
        depart *= 1000
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 6)
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(typeID)) + typeID
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(routeID)) + routeID
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, depart)
    trace._message.string += struct.pack("!BdBd", tc.TYPE_DOUBLE, pos, tc.TYPE_DOUBLE, speed)
    trace._message.string += struct.pack("!BB", tc.TYPE_BYTE, lane)
    trace._sendExact()
Exemplo n.º 21
0
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()
Exemplo n.º 22
0
def setRoute(vehID, edgeList):
    """
    changes the vehicle route to given edges list.
    The first edge in the list has to be the one that the vehicle is at at the moment.
    
    example usage:
    setRoute('1', ['1', '2', '4', '6', '7'])
    
    this changes route for vehicle id 1 to edges 1-2-4-6-7
    """
    trace._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_ROUTE, vehID, 1 + 4 + sum(map(len, edgeList)) + 4 * len(edgeList)
    )
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edgeList))
    for edge in edgeList:
        trace._message.string += struct.pack("!i", len(edge)) + edge
    trace._sendExact()
Exemplo n.º 23
0
def setCompleteRedYellowGreenDefinition(tlsID, tls):
    length = 1+4 + 1+4+len(tls._subID) + 1+4 + 1+4 + 1+4 + 1+4 # tls parameter
    itemNo = 1+1+1+1+1
    for p in tls._phases:
        length += 1+4 + 1+4 + 1+4 + 1+4+len(p._phaseDef)
        itemNo += 4
    trace._beginMessage(tc.CMD_SET_TL_VARIABLE, tc.TL_COMPLETE_PROGRAM_RYG, tlsID, length)
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, itemNo)
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(tls._subID)) + tls._subID # programID
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, 0) # type
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0) # subitems
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, tls._currentPhaseIndex) # index
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, len(tls._phases)) # phaseNo
    for p in tls._phases:
        trace._message.string += struct.pack("!BiBiBi", tc.TYPE_INTEGER, p._duration, tc.TYPE_INTEGER, p._duration1, tc.TYPE_INTEGER, p._duration2)
        trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(p._phaseDef)) + p._phaseDef
    trace._sendExact()
Exemplo n.º 24
0
def setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time):
    trace._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID, 1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8
    )
    trace._message.string += (
        struct.pack(
            "!BiBiBiBi",
            tc.TYPE_COMPOUND,
            4,
            tc.TYPE_INTEGER,
            begTime,
            tc.TYPE_INTEGER,
            endTime,
            tc.TYPE_STRING,
            len(edgeID),
        )
        + edgeID
    )
    trace._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, time)
    trace._sendExact()
Exemplo n.º 25
0
def setEffort(vehID, begTime, endTime, edgeID, effort):
    trace._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID) + 1 + 4
    )
    trace._message.string += (
        struct.pack(
            "!BiBiBiBi",
            tc.TYPE_COMPOUND,
            4,
            tc.TYPE_INTEGER,
            begTime,
            tc.TYPE_INTEGER,
            endTime,
            tc.TYPE_STRING,
            len(edgeID),
        )
        + edgeID
    )
    trace._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, effort)
    trace._sendExact()
Exemplo n.º 26
0
def rerouteTraveltime(vehID):
    trace._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_REROUTE_TRAVELTIME, vehID, 1 + 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    trace._sendExact()
Exemplo n.º 27
0
def remove(poiID, layer=0):
    trace._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.REMOVE, poiID, 1 + 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, layer)
    trace._sendExact()
Exemplo n.º 28
0
def rerouteTraveltime(vehID):
    trace._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_REROUTE_TRAVELTIME,
                        vehID, 1 + 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    trace._sendExact()
Exemplo n.º 29
0
def rerouteEffort(vehID):
    trace._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_REROUTE_EFFORT,
                        vehID, 1 + 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    trace._sendExact()
Exemplo n.º 30
0
def setPosition(poiID, x, y):
    trace._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_POSITION, poiID,
                        1 + 8 + 8)
    trace._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    trace._sendExact()
Exemplo n.º 31
0
def setDisallowed(laneID, disallowedClasses):
    trace._beginMessage(tc.CMD_SET_LANE_VARIABLE, tc.LANE_DISALLOWED, laneID, 1+4+sum(map(len, disallowedClasses))+4*len(disallowedClasses))
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(disallowedClasses))
    for c in disallowedClasses:
        trace._message.string += struct.pack("!i", len(c)) + c
    trace._sendExact()
Exemplo n.º 32
0
def rerouteEffort(vehID):
    trace._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_REROUTE_EFFORT, vehID, 1 + 4)
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    trace._sendExact()
Exemplo n.º 33
0
def moveTo(vehID, laneID, pos):
    trace._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO, vehID, 1 + 4 + 1 + 4 + len(laneID) + 1 + 8)
    trace._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2)
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(laneID)) + laneID
    trace._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, pos)
    trace._sendExact()
Exemplo n.º 34
0
def setColor(typeID, color):
    trace._beginMessage(tc.CMD_SET_VEHICLETYPE_VARIABLE, tc.VAR_COLOR, typeID, 1+1+1+1+1)
    trace._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    trace._sendExact()
Exemplo n.º 35
0
def setType(poiID, poiType):
    trace._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_TYPE, poiID,
                        1 + 4 + len(poiType))
    trace._message.string += struct.pack("!Bi", tc.TYPE_STRING,
                                         len(poiType)) + poiType
    trace._sendExact()