Пример #1
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()
Пример #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)) + str(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()
Пример #3
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()
Пример #4
0
def getDistance2D(x1, y1, x2, y2, isGeo=False, isDriving=False):
    """getDistance2D(double, double, double, double, boolean, boolean) -> double

    Returns the distance between the two coordinate pairs (x1,y1) and (x2,y2)

    If isGeo=True, coordinates are interpreted as longitude and latitude rather
    than cartesian coordinates in meters.

    If isDriving=True, the coordinates are mapped onto the road network and the
    length of the shortest route in the network is returned. Otherwise, the
    straight-line distance is returned.
    """
    posType = tc.POSITION_2D
    if isGeo:
        posType = tc.POSITION_LON_LAT
    distType = tc.REQUEST_AIRDIST
    if isDriving:
        distType = tc.REQUEST_DRIVINGDIST
    traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST, "",
                        1 + 4 + 1 + 8 + 8 + 1 + 8 + 8 + 1)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 3)
    traci._message.string += struct.pack("!Bdd", posType, x1, y1)
    traci._message.string += struct.pack("!BddB", posType, x2, y2, distType)
    return traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.DISTANCE_REQUEST,
                              "").readDouble()
Пример #5
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()
Пример #6
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()
Пример #7
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()
Пример #8
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()
Пример #9
0
def setColor(poiID, color):
    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()
Пример #10
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()
Пример #11
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()
Пример #12
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()
Пример #13
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()
Пример #14
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()
Пример #15
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()
Пример #16
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()
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()
Пример #18
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()
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()
Пример #20
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()
Пример #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()
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()
Пример #23
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()
Пример #24
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()
Пример #25
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()
Пример #26
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()
Пример #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()
Пример #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()
Пример #29
0
def convert2D(edgeID, pos, laneIndex=0, toGeo=False):
    posType = tc.POSITION_2D
    if toGeo:
        posType = tc.POSITION_LAT_LON
    traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+4+len(edgeID)+8+1 + 1+8+8)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2)
    traci._message.string += struct.pack("!Bi", tc.POSITION_ROADMAP, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!dBBdd", pos, laneIndex, posType, 0., 0.)
    return traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "").read("!dd")
Пример #30
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()
Пример #31
0
def getEffort(vehID, time, edgeID):
    """getEffort(string, double, string) -> double
    
    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1+4+1+4+1+4+len(edgeID))
    traci._message.string += struct.pack("!BiBiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time,
                                         tc.TYPE_STRING, len(edgeID)) + edgeID
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID).readDouble()
Пример #32
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()
Пример #33
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()
Пример #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()
Пример #35
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()
Пример #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()
Пример #37
0
def getDrivingDistance2D(vehID, x, y):
    """getDrivingDistance2D(string, double, double) -> integer
    
    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+4+4+1)
    traci._message.string += struct.pack("!BiBddB", tc.TYPE_COMPOUND, 2,
                                         tc.POSITION_2D, x, y, REQUEST_DRIVINGDIST)
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
Пример #38
0
def convert2D(edgeID, pos, laneIndex=0, toGeo=False):
    posType = tc.POSITION_2D
    if toGeo:
        posType = tc.POSITION_LAT_LON
    traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+4+len(edgeID)+8+1 + 1+1)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2)
    traci._message.string += struct.pack("!Bi", tc.POSITION_ROADMAP, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!dBBB", pos, laneIndex, tc.TYPE_UBYTE, posType)
    return traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "").read("!dd")
Пример #39
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()
Пример #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()
Пример #41
0
def getDrivingDistance2D(vehID, x, y):
    """getDrivingDistance2D(string, double, double) -> integer
    
    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+8+8+1)
    traci._message.string += struct.pack("!BiBddB", tc.TYPE_COMPOUND, 2,
                                         tc.POSITION_2D, x, y, tc.REQUEST_DRIVINGDIST)
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
Пример #42
0
def getLeader(vehID, dist=0.):
    """getLeader(string, double) -> (string, double)
    
    Return the leading vehicle id together with the distance.
    The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap.
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID, 1+8)
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, dist)
    return _readLeader(traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID))
Пример #43
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.
    """
    traci._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID, 1 + 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, traci._TIME2STEPS(time))
    return traci._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_EFFORT, edgeID).readDouble()
Пример #44
0
def getEffort(vehID, time, edgeID):
    """getEffort(string, double, string) -> double
    
    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID, 1+4+1+4+1+4+len(edgeID))
    traci._message.string += struct.pack("!BiBiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time,
                                         tc.TYPE_STRING, len(edgeID)) + edgeID
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_EFFORT, vehID).readDouble()
Пример #45
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()
Пример #46
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.
    """
    traci._beginMessage(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID, 1 + 4)
    traci._message.string += struct.pack("!Bi", tc.TYPE_INTEGER, traci._TIME2STEPS(time))
    return traci._checkResult(tc.CMD_GET_EDGE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, edgeID).readDouble()
Пример #47
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()
Пример #48
0
def convertRoad(x, y, isGeo=False):
    posType = tc.POSITION_2D
    if isGeo:
        posType = tc.POSITION_LAT_LON
    traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+8+8 + 1+4+8+1)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2)
    traci._message.string += struct.pack("!Bdd", posType, x, y)
    traci._message.string += struct.pack("!BidB", tc.POSITION_ROADMAP, 0, 0., 0)
    result = traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "")
    return result.readString(), result.readDouble(), result.read("!B")[0]
Пример #49
0
def getDrivingDistance(vehID, edgeID, pos, laneID=0):
    """getDrivingDistance(string, string, double, integer) -> double
    
    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+4+len(edgeID)+4+1+1)
    traci._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2,
                                         tc.POSITION_ROADMAP, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!dBB", pos, laneID, REQUEST_DRIVINGDIST)
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
Пример #50
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()
Пример #51
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()
Пример #52
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()
Пример #53
0
def getDrivingDistance(vehID, edgeID, pos, laneID=0):
    """getDrivingDistance(string, string, double, integer) -> double
    
    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID, 1+4+1+4+len(edgeID) + 8+1+1)
    traci._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2,
                                         tc.POSITION_ROADMAP, len(edgeID)) + edgeID
    traci._message.string += struct.pack("!dBB", pos, laneID, tc.REQUEST_DRIVINGDIST)
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.DISTANCE_REQUEST, vehID).readDouble()
Пример #54
0
def getLeader(vehID, dist=0.):
    """getLeader(string, double) -> (string, double)

    Return the leading vehicle id together with the distance.
    The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap.
    """
    traci._beginMessage(
        tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID, 1 + 8)
    traci._message.string += struct.pack("!Bd", tc.TYPE_DOUBLE, dist)
    return _readLeader(traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_LEADER, vehID))
Пример #55
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()
Пример #56
0
def convertRoad(x, y, isGeo=False):
    posType = tc.POSITION_2D
    if isGeo:
        posType = tc.POSITION_LAT_LON
    traci._beginMessage(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "", 1+4 + 1+8+8 + 1+1)
    traci._message.string += struct.pack("!Bi", tc.TYPE_COMPOUND, 2)
    traci._message.string += struct.pack("!Bdd", posType, x, y)
    traci._message.string += struct.pack("!BB", tc.TYPE_UBYTE, tc.POSITION_ROADMAP)
    result = traci._checkResult(tc.CMD_GET_SIM_VARIABLE, tc.POSITION_CONVERSION, "")
    return result.readString(), result.readDouble(), result.read("!B")[0]
Пример #57
0
def getAdaptedTraveltime(vehID, time, edgeID):
    """getAdaptedTraveltime(string, double, string) -> double

    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE,
                        tc.VAR_EDGE_TRAVELTIME, vehID, 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID))
    traci._message.string += struct.pack("!BiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time)
    traci._message.packString(edgeID)
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID).readDouble()
Пример #58
0
def getAdaptedTraveltime(vehID, time, edgeID):
    """getAdaptedTraveltime(string, double, string) -> double

    .
    """
    traci._beginMessage(tc.CMD_GET_VEHICLE_VARIABLE,
                        tc.VAR_EDGE_TRAVELTIME, vehID, 1 + 4 + 1 + 4 + 1 + 4 + len(edgeID))
    traci._message.string += struct.pack("!BiBiBi", tc.TYPE_COMPOUND, 2, tc.TYPE_INTEGER, time,
                                         tc.TYPE_STRING, len(edgeID)) + str(edgeID)
    return traci._checkResult(tc.CMD_GET_VEHICLE_VARIABLE, tc.VAR_EDGE_TRAVELTIME, vehID).readDouble()
Пример #59
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()
Пример #60
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()