Exemplo n.º 1
0
def setCompleteRedYellowGreenDefinition(tlsID, tls):
    """setCompleteRedYellowGreenDefinition(string, ) -> None

    .
    """
    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
    traci._beginMessage(
        tc.CMD_SET_TL_VARIABLE, tc.TL_COMPLETE_PROGRAM_RYG, tlsID, length)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, itemNo)
    # programID
    traci._message.string += struct.pack("!Bi",
                                         tc.TYPE_STRING, len(tls._subID)) + str(tls._subID)
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, 0)  # type
    # subitems
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    # index
    traci._message.string += struct.pack("!Bi",
                                         tc.TYPE_INTEGER, tls._currentPhaseIndex)
    # phaseNo
    traci._message.string += struct.pack("!Bi",
                                         tc.TYPE_INTEGER, len(tls._phases))
    for p in tls._phases:
        traci._message.string += struct.pack("!BiBiBi", tc.TYPE_INTEGER,
                                             p._duration, tc.TYPE_INTEGER, p._duration1, tc.TYPE_INTEGER, p._duration2)
        traci._message.string += struct.pack("!Bi",
                                             tc.TYPE_STRING, len(p._phaseDef)) + str(p._phaseDef)
    traci._sendExact()
Exemplo n.º 2
0
def addFull(vehID,
            routeID,
            typeID="DEFAULT_VEHTYPE",
            depart=None,
            departLane="0",
            departPos="base",
            departSpeed="0",
            arrivalLane="current",
            arrivalPos="max",
            arrivalSpeed="current",
            fromTaz="",
            toTaz="",
            line="",
            personCapacity=0,
            personNumber=0):
    messageString = struct.pack("!Bi", tc.TYPE_COMPOUND, 14)
    if depart is None:
        depart = str(traci.simulation.getCurrentTime() / 1000.)
    for val in (routeID, typeID, depart, departLane, departPos, departSpeed,
                arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line):
        messageString += struct.pack("!Bi", tc.TYPE_STRING, len(val)) + val
    messageString += struct.pack("!Bi", tc.TYPE_INTEGER, personCapacity)
    messageString += struct.pack("!Bi", tc.TYPE_INTEGER, personNumber)

    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.ADD_FULL, vehID,
                        len(messageString))
    traci._message.string += messageString
    traci._sendExact()
Exemplo n.º 3
0
def setStop(vehID,
            edgeID,
            pos=1.,
            laneIndex=0,
            duration=2**31 - 1,
            flags=STOP_DEFAULT,
            startPos=tc.INVALID_DOUBLE_VALUE,
            until=-1):
    """setStop(string, string, double, integer, integer, integer, double, integer) -> None

    Adds or modifies a stop with the given parameters. The duration and the until attribute are
    in milliseconds.
    """
    traci._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_STOP, vehID, 1 + 4 + 1 + 4 +
        len(edgeID) + 1 + 8 + 1 + 1 + 1 + 4 + 1 + 1 + 1 + 8 + 1 + 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 7)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING,
                                         len(edgeID)) + str(edgeID)
    traci._message.string += struct.pack("!BdBBBiBB", tc.TYPE_DOUBLE, pos,
                                         tc.TYPE_BYTE, laneIndex,
                                         tc.TYPE_INTEGER, duration,
                                         tc.TYPE_BYTE, flags)
    traci._message.string += struct.pack("!BdBi", tc.TYPE_DOUBLE, startPos,
                                         tc.TYPE_INTEGER, until)
    traci._sendExact()
Exemplo n.º 4
0
def setColor(typeID, color):
    traci._beginMessage(tc.CMD_SET_VEHICLETYPE_VARIABLE, tc.VAR_COLOR, typeID,
                        1 + 1 + 1 + 1 + 1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR,
                                         int(color[0]), int(color[1]),
                                         int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 5
0
def setShape(polygonID, shape):
    traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_SHAPE, polygonID,
                        1 + 1 + len(shape) * (8 + 8))
    traci._message.string += struct.pack("!BB", tc.TYPE_POLYGON, len(shape))
    for p in shape:
        traci._message.string += struct.pack("!dd", p)
    traci._sendExact()
Exemplo n.º 6
0
def moveTo(vehID, laneID, pos):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE,
                        tc.VAR_MOVE_TO, vehID, 1 + 4 + 1 + 4 + len(laneID) + 1 + 8)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2)
    traci._message.packString(laneID)
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, pos)
    traci._sendExact()
Exemplo n.º 7
0
def add(routeID, edges):
    traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID,
                        1 + 4 + sum(map(len, edges)) + 4 * len(edges))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edges))
    for e in edges:
        traci._message.string += struct.pack("!i", len(e)) + str(e)
    traci._sendExact()
Exemplo n.º 8
0
def setColor(polygonID, color):
    traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_COLOR, polygonID,
                        1 + 1 + 1 + 1 + 1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR,
                                         int(color[0]), int(color[1]),
                                         int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 9
0
def add(routeID, edges):
    traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID,
                        1+4+sum(map(len, edges))+4*len(edges))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edges))
    for e in edges:
        traci._message.string += struct.pack("!i", len(e)) + e
    traci._sendExact()
Exemplo n.º 10
0
def changeLane(vehID, laneIndex, duration):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_CHANGELANE, vehID,
                        1 + 4 + 1 + 1 + 1 + 4)
    traci._message.string += struct.pack("!BiBBBi", tc.TYPE_COMPOUND, 2,
                                         tc.TYPE_BYTE, laneIndex,
                                         tc.TYPE_INTEGER, duration)
    traci._sendExact()
Exemplo n.º 11
0
def slowDown(vehID, speed, duration):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_SLOWDOWN, vehID,
                        1 + 4 + 1 + 8 + 1 + 4)
    traci._message.string += struct.pack("!BiBdBi", tc.TYPE_COMPOUND, 2,
                                         tc.TYPE_DOUBLE, speed,
                                         tc.TYPE_INTEGER, duration)
    traci._sendExact()
Exemplo n.º 12
0
def setCompleteRedYellowGreenDefinition(tlsID, tls):
    """setCompleteRedYellowGreenDefinition(string, ) -> None
    
    .
    """
    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
    traci._beginMessage(tc.CMD_SET_TL_VARIABLE, tc.TL_COMPLETE_PROGRAM_RYG,
                        tlsID, length)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, itemNo)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(
        tls._subID)) + tls._subID  # programID
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, 0)  # type
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND,
                                         0)  # subitems
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER,
                                         tls._currentPhaseIndex)  # index
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER,
                                         len(tls._phases))  # phaseNo
    for p in tls._phases:
        traci._message.string += struct.pack("!BiBiBi", tc.TYPE_INTEGER,
                                             p._duration, tc.TYPE_INTEGER,
                                             p._duration1, tc.TYPE_INTEGER,
                                             p._duration2)
        traci._message.string += struct.pack("!Bi", tc.TYPE_STRING,
                                             len(p._phaseDef)) + p._phaseDef
    traci._sendExact()
Exemplo n.º 13
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()).
    """
    traci._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_BOUNDARY, viewID, 1+8+8+8+8)
    traci._message.string += struct.pack("!Bdddd", tc.TYPE_BOUNDINGBOX, xmin, ymin, xmax, ymax)
    traci._sendExact()
Exemplo n.º 14
0
def setOffset(viewID, x, y):
    """setOffset(string, double, double) -> None
    
    Set the current offset for the given view.
    """
    traci._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_OFFSET, viewID, 1+8+8)
    traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    traci._sendExact()
Exemplo n.º 15
0
def setColor(typeID, color):
    """setColor(string, (integer, integer, integer, integer)) -> None
    
    Sets the color of this type.
    """
    traci._beginMessage(tc.CMD_SET_VEHICLETYPE_VARIABLE, tc.VAR_COLOR, typeID, 1+1+1+1+1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 16
0
def setEffort(edgeID, effort):
    """setEffort(string, double) -> None
    
    Adapt the effort value used for (re-)routing for the given edge.
    """
    traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1+4+1+8)
    traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, effort)
    traci._sendExact()
Exemplo n.º 17
0
def adaptTraveltime(edgeID, time):
    """adaptTraveltime(string, double) -> None
    
    Adapt the travel time value (in s) used for (re-)routing for the given edge.
    """
    traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1+4+1+8)
    traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, time)
    traci._sendExact()
Exemplo n.º 18
0
def setEffort(vehID, begTime, endTime, edgeID, effort):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID,
                        1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID) + 1 + 4)
    traci._message.string += struct.pack(
        "!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime,
        tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, effort)
    traci._sendExact()
Exemplo n.º 19
0
def setColor(poiID, color):
    """setColor(string, (integer, integer, integer, integer)) -> None
    
    Sets the rgba color of the poi.
    """
    traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_COLOR, poiID, 1+1+1+1+1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 20
0
def setColor(typeID, color):
    """setColor(string, (integer, integer, integer, integer)) -> None
    
    Sets the color of this type.
    """
    traci._beginMessage(tc.CMD_SET_VEHICLETYPE_VARIABLE, tc.VAR_COLOR, typeID, 1+1+1+1+1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 21
0
def setEffort(edgeID, effort):
    """setEffort(string, double) -> None

    Adapt the effort value used for (re-)routing for the given edge.
    """
    traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1 + 4 + 1 + 8)
    traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, effort)
    traci._sendExact()
Exemplo n.º 22
0
def add(poiID, x, y, color, poiType="", layer=0):
    traci._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)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(poiType)) + poiType
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, layer)
    traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    traci._sendExact()
Exemplo n.º 23
0
def setPosition(poiID, x, y):
    """setPosition(string, (double, double)) -> None
    
    Sets the position coordinates of the poi. 
    """
    traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_POSITION, poiID, 1+8+8)
    traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    traci._sendExact()
Exemplo n.º 24
0
def moveToVTD(vehID, edgeID, lane, x, y):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO_VTD, vehID, 1+4+1+4+len(edgeID)+1+4+1+8+1+8)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, lane)    
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, x)
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, y)
    traci._sendExact()
Exemplo n.º 25
0
def add(poiID, x, y, color, poiType="", layer=0):
    traci._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)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(poiType)) + poiType
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, layer)
    traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    traci._sendExact()
Exemplo n.º 26
0
def moveToVTD(vehID, edgeID, lane, x, y):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO_VTD, vehID, 1+4+1+4+len(edgeID)+1+4+1+8+1+8)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, lane)    
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, x)
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, y)
    traci._sendExact()
Exemplo n.º 27
0
def setOffset(viewID, x, y):
    """setOffset(string, double, double) -> None
    
    Set the current offset for the given view.
    """
    traci._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_OFFSET, viewID, 1+8+8)
    traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    traci._sendExact()
Exemplo n.º 28
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()).
    """
    traci._beginMessage(tc.CMD_SET_GUI_VARIABLE, tc.VAR_VIEW_BOUNDARY, viewID, 1+8+8+8+8)
    traci._message.string += struct.pack("!Bdddd", tc.TYPE_BOUNDINGBOX, xmin, ymin, xmax, ymax)
    traci._sendExact()
Exemplo n.º 29
0
def moveTo(vehID, laneID, pos):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_MOVE_TO, vehID,
                        1 + 4 + 1 + 4 + len(laneID) + 1 + 8)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING,
                                         len(laneID)) + laneID
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, pos)
    traci._sendExact()
Exemplo n.º 30
0
def setType(poiID, poiType):
    """setType(string, string) -> None
    
    Sets the (abstract) type of the poi.
    """
    traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_TYPE, poiID, 1+4+len(poiType))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(poiType)) + poiType
    traci._sendExact()
Exemplo n.º 31
0
def adaptTraveltime(edgeID, time):
    """adaptTraveltime(string, double) -> None

    Adapt the travel time value (in s) used for (re-)routing for the given edge.
    """
    traci._beginMessage(tc.CMD_SET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1 + 4 + 1 + 8)
    traci._message.string += struct.pack("!BiBd", tc.TYPE_COMPOUND, 1, tc.TYPE_DOUBLE, time)
    traci._sendExact()
Exemplo n.º 32
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
    """
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_COLOR, vehID, 1+1+1+1+1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 33
0
def setType(poiID, poiType):
    """setType(string, string) -> None

    Sets the (abstract) type of the poi.
    """
    traci._beginMessage(
        tc.CMD_SET_POI_VARIABLE, tc.VAR_TYPE, poiID, 1 + 4 + len(poiType))
    traci._message.packString(poiType)
    traci._sendExact()
Exemplo n.º 34
0
def add(routeID, edges):
    """add(string, list(string)) -> None

    Adds a new route with the given id consisting of the given list of edge IDs.
    """
    traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID,
                        1 + 4 + sum(map(len, edges)) + 4 * len(edges))
    traci._message.packStringList(edges)
    traci._sendExact()
Exemplo n.º 35
0
def resume(vehID):
    """resume(string) -> None

    Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped).
    """
    traci._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_RESUME, vehID, 1 + 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    traci._sendExact()
Exemplo n.º 36
0
def resume(vehID):
    """resume(string) -> None

    Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped).
    """
    traci._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_RESUME, vehID, 1 + 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    traci._sendExact()
Exemplo n.º 37
0
def setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME,
                        vehID,
                        1 + 4 + 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8)
    traci._message.string += struct.pack(
        "!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime,
        tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, time)
    traci._sendExact()
Exemplo n.º 38
0
def setDisallowed(laneID, disallowedClasses):
    traci._beginMessage(
        tc.CMD_SET_LANE_VARIABLE, tc.LANE_DISALLOWED, laneID,
        1 + 4 + sum(map(len, disallowedClasses)) + 4 * len(disallowedClasses))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST,
                                         len(disallowedClasses))
    for c in disallowedClasses:
        traci._message.string += struct.pack("!i", len(c)) + c
    traci._sendExact()
Exemplo n.º 39
0
def setPosition(poiID, x, y):
    """setPosition(string, (double, double)) -> None

    Sets the position coordinates of the poi. 
    """
    traci._beginMessage(tc.CMD_SET_POI_VARIABLE, tc.VAR_POSITION, poiID,
                        1 + 8 + 8)
    traci._message.string += struct.pack("!Bdd", tc.POSITION_2D, x, y)
    traci._sendExact()
Exemplo n.º 40
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
    """
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_COLOR, vehID, 1+1+1+1+1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 41
0
def setShape(polygonID, shape):
    """setShape(string, list((double, double))) -> None
    
    Sets the shape (list of 2D-positions) of this polygon.
    """
    traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_SHAPE, polygonID, 1 + 1 + len(shape) * (8 + 8))
    traci._message.string += struct.pack("!BB", tc.TYPE_POLYGON, len(shape))
    for p in shape:
        traci._message.string += struct.pack("!dd", p)
    traci._sendExact()
Exemplo n.º 42
0
def setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time):
    """setAdaptedTraveltime(string, double, string, double) -> None
    
    .
    """
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID, 1+4+1+4+1+4+1+4+len(edgeID)+1+8)
    traci._message.string += struct.pack("!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime,
                                         tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, time)
    traci._sendExact()
Exemplo n.º 43
0
def setType(polygonID, polygonType):
    """setType(string, string) -> None
    
    Sets the (abstract) type of the polygon.
    """
    traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_TYPE, polygonID,
                        1 + 4 + len(polygonType))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING,
                                         len(polygonType)) + polygonType
    traci._sendExact()
Exemplo n.º 44
0
def setStop(vehID, edgeID, pos=1., laneIndex=0, duration=2**31 - 1):
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_STOP, vehID,
                        1 + 4 + 1 + 4 + len(edgeID) + 1 + 8 + 1 + 1 + 1 + 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING,
                                         len(edgeID)) + edgeID
    traci._message.string += struct.pack("!BdBBBi", tc.TYPE_DOUBLE, pos,
                                         tc.TYPE_BYTE, laneIndex,
                                         tc.TYPE_INTEGER, duration)
    traci._sendExact()
Exemplo n.º 45
0
def setEffort(vehID, begTime, endTime, edgeID, effort):
    """setEffort(string, double, string, double) -> None
    
    .
    """
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1+4+1+4+1+4+1+4+len(edgeID)+1+4)
    traci._message.string += struct.pack("!BiBiBiBi", tc.TYPE_COMPOUND, 4, tc.TYPE_INTEGER, begTime,
                                         tc.TYPE_INTEGER, endTime, tc.TYPE_STRING, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, effort)
    traci._sendExact()
Exemplo n.º 46
0
def setDisallowed(laneID, disallowedClasses):
    """setDisallowed(string, list) -> None

    Sets a list of disallowed vehicle classes.
    """
    if isinstance(disallowedClasses, str):
        disallowedClasses = [disallowedClasses]
    traci._beginMessage(tc.CMD_SET_LANE_VARIABLE, tc.LANE_DISALLOWED, laneID,
                        1 + 4 + sum(map(len, disallowedClasses)) + 4 * len(disallowedClasses))
    traci._message.packStringList(disallowedClasses)
    traci._sendExact()
Exemplo n.º 47
0
def setColor(polygonID, color):
    """setColor(string, (integer, integer, integer, integer)) -> None
    
    Sets the rgba color of this polygon.
    """
    traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_COLOR, polygonID,
                        1 + 1 + 1 + 1 + 1)
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR,
                                         int(color[0]), int(color[1]),
                                         int(color[2]), int(color[3]))
    traci._sendExact()
Exemplo n.º 48
0
def setShape(polygonID, shape):
    """setShape(string, list((double, double))) -> None
    
    Sets the shape (list of 2D-positions) of this polygon.
    """
    traci._beginMessage(tc.CMD_SET_POLYGON_VARIABLE, tc.VAR_SHAPE, polygonID,
                        1 + 1 + len(shape) * (8 + 8))
    traci._message.string += struct.pack("!BB", tc.TYPE_POLYGON, len(shape))
    for p in shape:
        traci._message.string += struct.pack("!dd", p)
    traci._sendExact()
Exemplo n.º 49
0
def add(polygonID, shape, color, fill=False, polygonType="", layer=0):
    traci._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))
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 5)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(polygonType)) + polygonType
    traci._message.string += struct.pack("!BBBBB", tc.TYPE_COLOR, int(color[0]), int(color[1]), int(color[2]), int(color[3]))
    traci._message.string += struct.pack("!BB", tc.TYPE_UBYTE, int(fill))
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, layer)
    traci._message.string += struct.pack("!BB", tc.TYPE_POLYGON, len(shape))
    for p in shape:
        traci._message.string += struct.pack("!dd", *p)
    traci._sendExact()
Exemplo n.º 50
0
def add(routeID, edges):
    """add(string, list(string)) -> None

    Adds a new route with the given id consisting of the given list of edge IDs.
    """
    traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID,
                        1 + 4 + sum(map(len, edges)) + 4 * len(edges))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edges))
    for e in edges:
        traci._message.string += struct.pack("!i", len(e)) + str(e)
    traci._sendExact()
Exemplo n.º 51
0
def add(routeID, edges):
    """add(string, list(string)) -> None

    Adds a new route with the given id consisting of the given list of edge IDs.
    """
    traci._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID,
                        1 + 4 + sum(map(len, edges)) + 4 * len(edges))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(edges))
    for e in edges:
        traci._message.string += struct.pack("!i", len(e)) + str(e)
    traci._sendExact()
Exemplo n.º 52
0
def setAllowed(laneID, allowedClasses):
    """setAllowed(string, list) -> None

    Sets a list of allowed vehicle classes. Setting an empty list means all vehicles are allowed.
    """
    if isinstance(allowedClasses, str):
        allowedClasses = [allowedClasses]
    traci._beginMessage(tc.CMD_SET_LANE_VARIABLE, tc.LANE_ALLOWED, laneID,
                        1 + 4 + sum(map(len, allowedClasses)) + 4 * len(allowedClasses))
    traci._message.packStringList(allowedClasses)
    traci._sendExact()
Exemplo n.º 53
0
def setAllowed(laneID, allowedClasses):
    """setAllowed(string, list) -> None
    
    Sets a list of allowed vehicle classes. Setting an empty list means all vehicles are allowed.
    """
    if isinstance(allowedClasses, str):
        allowedClasses= [allowedClasses]
    traci._beginMessage(tc.CMD_SET_LANE_VARIABLE, tc.LANE_ALLOWED, laneID, 1+4+sum(map(len, allowedClasses))+4*len(allowedClasses))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(allowedClasses))
    for c in allowedClasses:
        traci._message.string += struct.pack("!i", len(c)) + c
    traci._sendExact()
Exemplo n.º 54
0
def setDisallowed(laneID, disallowedClasses):
    """setDisallowed(string, list) -> None
    
    Sets a list of disallowed vehicle classes.
    """
    if isinstance(disallowedClasses, str):
        disallowedClasses= [disallowedClasses]
    traci._beginMessage(tc.CMD_SET_LANE_VARIABLE, tc.LANE_DISALLOWED, laneID, 1+4+sum(map(len, disallowedClasses))+4*len(disallowedClasses))
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRINGLIST, len(disallowedClasses))
    for c in disallowedClasses:
        traci._message.string += struct.pack("!i", len(c)) + c
    traci._sendExact()
Exemplo n.º 55
0
def add(vehID, routeID, depart=DEPART_NOW, pos=0, speed=0, lane=0, typeID="DEFAULT_VEHTYPE"):
    traci._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
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 6)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(typeID)) + typeID
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(routeID)) + routeID
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, depart)
    traci._message.string += struct.pack("!BdBd", tc.TYPE_DOUBLE, pos, tc.TYPE_DOUBLE, speed)
    traci._message.string += struct.pack("!BB", tc.TYPE_BYTE, lane)
    traci._sendExact()
Exemplo n.º 56
0
def add(vehID, routeID, depart=DEPART_NOW, pos=0, speed=0, lane=0, typeID="DEFAULT_VEHTYPE"):
    traci._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
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 6)
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(typeID)) + typeID
    traci._message.string += struct.pack("!Bi", tc.TYPE_STRING, len(routeID)) + routeID
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, depart)
    traci._message.string += struct.pack("!BdBd", tc.TYPE_DOUBLE, pos, tc.TYPE_DOUBLE, speed)
    traci._message.string += struct.pack("!BB", tc.TYPE_BYTE, lane)
    traci._sendExact()
Exemplo n.º 57
0
def rerouteTraveltime(vehID, currentTravelTimes = True):
    """rerouteTraveltime(string, bool) -> None Reroutes a vehicle. If
    currentTravelTimes is True (default) then the current traveltime of the
    edges is loaded and used for rerouting. If currentTravelTimes is False,
    travel times loaded from a weight file are used. In the absence of loaded
    weights, the minimum travel time is used (speed limit). 
    """
    if currentTravelTimes:
        for edge in traci.edge.getIDList():
            traci.edge.adaptTraveltime(edge, traci.edge.getTraveltime(edge)) 
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_REROUTE_TRAVELTIME, vehID, 1+4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 0)
    traci._sendExact()
Exemplo n.º 58
0
def setStop(vehID, edgeID, pos=1., laneIndex=0, duration=2**31 - 1, flags=STOP_DEFAULT):
    """setStop(string, string, double, integer, integer, integer) -> None

    Adds or modifies a stop with the given parameters. The duration attribute is
    in milliseconds.
    """
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_STOP,
                        vehID, 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8 + 1 + 1 + 1 + 4 + 1 + 1)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 5)
    traci._message.string += struct.pack("!Bi",
                                         tc.TYPE_STRING, len(edgeID)) + str(edgeID)
    traci._message.string += struct.pack("!BdBBBiBB", tc.TYPE_DOUBLE, pos,
                                         tc.TYPE_BYTE, laneIndex, tc.TYPE_INTEGER, duration, tc.TYPE_BYTE, flags)
    traci._sendExact()
Exemplo n.º 59
0
def setStop(vehID, edgeID, pos=1., laneIndex=0, duration=2**31 - 1, flags=STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=-1):
    """setStop(string, string, double, integer, integer, integer, double, integer) -> None

    Adds or modifies a stop with the given parameters. The duration and the until attribute are
    in milliseconds.
    """
    traci._beginMessage(tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_STOP,
                        vehID, 1 + 4 + 1 + 4 + len(edgeID) + 1 + 8 + 1 + 1 + 1 + 4 + 1 + 1 + 1 + 8 + 1 + 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 7)
    traci._message.packString(edgeID)
    traci._message.string += struct.pack("!BdBBBiBB", tc.TYPE_DOUBLE, pos,
                                         tc.TYPE_BYTE, laneIndex, tc.TYPE_INTEGER, duration, tc.TYPE_BYTE, flags)
    traci._message.string += struct.pack("!BdBi",
                                         tc.TYPE_DOUBLE, startPos, tc.TYPE_INTEGER, until)
    traci._sendExact()