示例#1
0
def notifyAndUpdateArrivedVehicles(mtraci, outputSocket, priorityVehicles, mPriorityVehicles, managedTllDict, vehicles):
    """
    Sends an arrived vehicles message (2) to the remote client and Remove every arrived vehicles from the priority vehicles shared list
    """
    mtraci.acquire()
    arrivedVehicles = traci.simulation.getArrivedIDList()
    mtraci.release()
    arrivedVehicles = getRegularVehicles(arrivedVehicles)
    
    if constants.SEND_ARRIVED_VEHICLES and (constants.SEND_MSG_EVEN_IF_EMPTY or (not constants.SEND_MSG_EVEN_IF_EMPTY and arrivedVehicles)):
        sendArrivedVehicles(arrivedVehicles, mtraci, outputSocket)
    removeArrivedVehicles(arrivedVehicles, priorityVehicles, mPriorityVehicles, managedTllDict, vehicles)
示例#2
0
def notifyAndUpdateArrivedVehicles(mtraci, outputSocket, priorityVehicles,
                                   mPriorityVehicles, managedTllDict,
                                   vehicles):
    """
    Sends an arrived vehicles message (2) to the remote client and Remove every arrived vehicles from the priority vehicles shared list
    """
    mtraci.acquire()
    arrivedVehicles = traci.simulation.getArrivedIDList()
    mtraci.release()
    arrivedVehicles = getRegularVehicles(arrivedVehicles)

    if constants.SEND_ARRIVED_VEHICLES and (
            constants.SEND_MSG_EVEN_IF_EMPTY or
        (not constants.SEND_MSG_EVEN_IF_EMPTY and arrivedVehicles)):
        sendArrivedVehicles(arrivedVehicles, mtraci, outputSocket)
    removeArrivedVehicles(arrivedVehicles, priorityVehicles, mPriorityVehicles,
                          managedTllDict, vehicles)
示例#3
0
文件: manager.py 项目: gitali/ASTra
def main():
    """
    See file description
    """
    Logger.initLogger()
    
    # Automatic restart is the remote sockets are closed or if TraCI or SUMO crash
    while True:
        # Variables
        # Mutex
        mtraci = Lock()
        mRelaunch = Lock()
        mPriorityVehicle = Lock()
        mVehicles = Lock()
        # Events
        eRouteReady = threading.Event()
        eGraphReady = threading.Event()
        eVehicleReady = threading.Event()
        eTrafficLightsReady = threading.Event()
        eSimulationReady = threading.Event()
        eShutdown = threading.Event()
        eManagerReady = threading.Event()
        # Vehicles list
        priorityVehicles = []
        vehicles = []
        
        Logger.info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
                  + "+ Initializing app 'ASTra'                                 +\n"
                  + "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    
        if constants.POSIX_OS:
            Logger.warning("You are running on a POSIX based operating system (See constants).\nThe screenshot functionality has been disabled for the traffic lights management.")
        
        # Starting SUMO
        sumoGuiProcess = startSUMO(constants.SUMO_GUI_START_COMMAND)
        
        # Connecting to TraCI
        initTraciConnection(constants.TRACI_PORT, constants.TRACI_CONNECT_MAX_STEPS)
        
        # Building dictionaries
        if constants.ROUTING_ENABLED or constants.GRAPH_ENABLED:
            graphDict, junctionsDict, edgesDict = graph.getGraphAndJunctionsDictionaryAndEdgesDictionary(mtraci)
            
        if constants.VEHICLE_ENABLED or constants.SIMULATION_ENABLED:
            mtraci.acquire()
            vehicles = traci.vehicle.getIDList()
            mtraci.release()
            vehicles = vehicle.getRegularVehicles(vehicles)
        
        graphThread, graphInputSocket, graphOutputSocket, routerThread, routerInputSocket, routerOutputSocket, orderThread, orderInputSocket, orderOutputSocket, trafficLightsThread, tllInputSocket, tllOutputSocket, simulatorThread, simulatorOutputSocket = deployThreads(mtraci, mRelaunch, mPriorityVehicle, eRouteReady, eGraphReady, eVehicleReady, eTrafficLightsReady, eSimulationReady, eShutdown, eManagerReady, priorityVehicles, graphDict, junctionsDict, edgesDict, vehicles, mVehicles)

        # Waiting for the threads to be ready
        while not eGraphReady.is_set() or not eRouteReady.is_set() or not eVehicleReady.is_set() or not eTrafficLightsReady.is_set() or not eSimulationReady.is_set():
            time.sleep(constants.SLEEP_SYNCHRONISATION)
        
        # Sending a ready message to the remote client
        eManagerReady.set()
        
        Logger.info("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
                   +"+ Started app 'ASTra'                                      +\n"
                   +"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
            
        # Waiting for a TraCI exception
        if constants.SIMULATION_ENABLED:
            mRelaunch.acquire()
        else:
            # No redeployment if an error occurs
            while(True):
                time.sleep(65536)
        
        # Asking for the threads to shutdown
        Logger.info("{}Shutting down all threads. Preparing for redeployment...".format(constants.PRINT_PREFIX_MANAGER))
        
        shutdownThreads(eShutdown, graphThread, graphInputSocket, graphOutputSocket, routerThread, routerInputSocket, routerOutputSocket, orderThread, orderInputSocket, orderOutputSocket, trafficLightsThread, tllInputSocket, tllOutputSocket, simulatorThread, simulatorOutputSocket, sumoGuiProcess)
            
        traci.close()
        sys.stdout.flush()
        time.sleep(1)
示例#4
0
def main():
    """
    See file description
    """
    Logger.initLogger()

    # Automatic restart is the remote sockets are closed or if TraCI or SUMO crash
    while True:
        # Variables
        # Mutex
        mtraci = Lock()
        mRelaunch = Lock()
        mPriorityVehicle = Lock()
        mVehicles = Lock()
        # Events
        eRouteReady = threading.Event()
        eGraphReady = threading.Event()
        eVehicleReady = threading.Event()
        eTrafficLightsReady = threading.Event()
        eSimulationReady = threading.Event()
        eShutdown = threading.Event()
        eManagerReady = threading.Event()
        # Vehicles list
        priorityVehicles = []
        vehicles = []

        Logger.info(
            "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" +
            "+ Initializing app 'ASTra'                                 +\n" +
            "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

        if constants.POSIX_OS:
            Logger.warning(
                "You are running on a POSIX based operating system (See constants).\nThe screenshot functionality has been disabled for the traffic lights management."
            )

        # Starting SUMO
        sumoGuiProcess = startSUMO(constants.SUMO_GUI_START_COMMAND)

        # Connecting to TraCI
        initTraciConnection(constants.TRACI_PORT,
                            constants.TRACI_CONNECT_MAX_STEPS)

        # Building dictionaries
        if constants.ROUTING_ENABLED or constants.GRAPH_ENABLED:
            graphDict, junctionsDict, edgesDict = graph.getGraphAndJunctionsDictionaryAndEdgesDictionary(
                mtraci)

        if constants.VEHICLE_ENABLED or constants.SIMULATION_ENABLED:
            mtraci.acquire()
            vehicles = traci.vehicle.getIDList()
            mtraci.release()
            vehicles = vehicle.getRegularVehicles(vehicles)

        graphThread, graphInputSocket, graphOutputSocket, routerThread, routerInputSocket, routerOutputSocket, orderThread, orderInputSocket, orderOutputSocket, trafficLightsThread, tllInputSocket, tllOutputSocket, simulatorThread, simulatorOutputSocket = deployThreads(
            mtraci, mRelaunch, mPriorityVehicle, eRouteReady, eGraphReady,
            eVehicleReady, eTrafficLightsReady, eSimulationReady, eShutdown,
            eManagerReady, priorityVehicles, graphDict, junctionsDict,
            edgesDict, vehicles, mVehicles)

        # Waiting for the threads to be ready
        while not eGraphReady.is_set() or not eRouteReady.is_set(
        ) or not eVehicleReady.is_set() or not eTrafficLightsReady.is_set(
        ) or not eSimulationReady.is_set():
            time.sleep(constants.SLEEP_SYNCHRONISATION)

        # Sending a ready message to the remote client
        eManagerReady.set()

        Logger.info(
            "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" +
            "+ Started app 'ASTra'                                      +\n" +
            "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

        # Waiting for a TraCI exception
        if constants.SIMULATION_ENABLED:
            mRelaunch.acquire()
        else:
            # No redeployment if an error occurs
            while (True):
                time.sleep(65536)

        # Asking for the threads to shutdown
        Logger.info(
            "{}Shutting down all threads. Preparing for redeployment...".
            format(constants.PRINT_PREFIX_MANAGER))

        shutdownThreads(eShutdown, graphThread, graphInputSocket,
                        graphOutputSocket, routerThread, routerInputSocket,
                        routerOutputSocket, orderThread, orderInputSocket,
                        orderOutputSocket, trafficLightsThread, tllInputSocket,
                        tllOutputSocket, simulatorThread,
                        simulatorOutputSocket, sumoGuiProcess)

        traci.close()
        sys.stdout.flush()
        time.sleep(1)