示例#1
0
def Controller(settings) :
    """
    Controller is the main entry point for driving the simulation.

    Arguments:
    settings -- nested dictionary with variables for configuring the connectors
    """

    laysettings = LayoutSettings.LayoutSettings(settings)
    #laysettings = None
    # load the world
    infofile = settings["General"].get("WorldInfoFile","info.js")
    logger.info('loading world data from %s',infofile)
    world = WorldInfo.WorldInfo.LoadFromFile(infofile)
    #world = None

    cnames = settings["General"].get("Connectors",['sumo', 'opensim', 'social', 'stats'])
    #if 'opensim' in cnames:
    #    cnames.remove('opensim')
    #    for sname in settings["OpenSimConnector"]["Scenes"].keys():
    #        _SimulationControllers['osc:'+sname] = OpenSimConnector.OpenSimConnector
    #        cnames.append('osc:'+sname)
    # evrouter = EventRouter.EventRouter()
    # initialize the connectors first
    connectors = []
    store = SimpleStore()
    #store= RemoteStore()
    for cname in cnames :
        if cname not in _SimulationControllers :
            logger.warn('skipping unknown simulation connector; %s' % (cname))
            continue

        cframe = Frame(store)
        connector = _SimulationControllers[cname](settings, world, laysettings, cname, cframe)
        cframe.attach(connector)
        #connproc = Process(target=connector.SimulationStart, args=())
        #connproc.start()
        connectors.append(cframe)
        cframe.go()
            
    #evrouterproc = Process(target=evrouter.RouteEvents, args=())
    #evrouterproc.start()

    # start the timer thread
    #thread = TimerThread(evrouter, settings)
    #thread.start()

    controller = MobdatController(logger, connectors)
    controller.cmdloop()

    #thread.join()

    # send the shutdown event to the connectors
    for connproc in connectors :
        connproc.join()
示例#2
0
    def __init__(self):
        """
        Constructor
        """
        frame_car = Frame(RemoteStore())
        frame_car.interval = 1.0
        frame_car.attach(TrafficSimulation(frame_car))

        frame_ped = Frame(frame_car.Store)
        frame_ped.interval = 1.0
        frame_ped.attach(PedestrianSimulation(frame_ped))

        frame_car.go()
        frame_ped.go()
示例#3
0
    def __init__(self):
        '''
        Constructor
        '''
        frame_car = Frame(RemoteStore())
        frame_car.interval = 1.0
        frame_car.attach(TrafficSimulation(frame_car))

        frame_ped = Frame(frame_car.Store)
        frame_ped.interval = 1.0
        frame_ped.attach(PedestrianSimulation(frame_ped))

        frame_car.go()
        frame_ped.go()
示例#4
0
def Controller(settings) :
    """
    Controller is the main entry point for driving the simulation.

    Arguments:
    settings -- nested dictionary with variables for configuring the connectors
    """

    laysettings = LayoutSettings.LayoutSettings(settings)
    # laysettings = None
    # load the world
    infofile = settings["General"].get("WorldInfoFile", "info.js")
    logger.info('loading world data from %s', infofile)
    world = WorldInfo.WorldInfo.LoadFromFile(infofile)
    # world = None

    cnames = settings["General"].get("Connectors", ['sumo', 'opensim', 'social', 'stats'])
    store_type = settings["General"].get("Store", "SimpleStore")
    process = settings["General"].get("MultiProcessing", False)
    timer = settings["General"].get("Timer", None)
    autostart = settings["General"].get("AutoStart", False)
    if timer:
        seconds = 0
        minutes = 0
        hours = 0
        if "Seconds" in timer:
            seconds = timer["Seconds"]
        if "Minutes" in timer:
            minutes = timer["Minutes"]
        if "Hours" in timer:
            hours = timer["Hours"]
        timer = datetime.timedelta(seconds=seconds, minutes=minutes, hours=hours)

    connectors = []

    if store_type == "RemoteStore":
        manager = Manager()
        cmd_dict = manager.dict()
    else:
        cmd_dict = {}

    cmd_dict["SimulatorStartup"] = False
    cmd_dict["SimulatorShutdown"] = False
    cmd_dict["SimulatorPaused"] = False

    if store_type == "RemoteStore":
        Store = PythonRemoteStore
    elif store_type == "SimpleStore":
        Store = SimpleStore
    else: #default to SimpleStore
        Store = SimpleStore

    if process and Store == SimpleStore:
        logger.warn("Cannot use multiprocessing with SimpleStore. Continuing with Threading.")
        process = False

    for cname in cnames :
        if cname not in _SimulationControllers :
            logger.warn('skipping unknown simulation connector; %s' % (cname))
            continue

        cframe = Frame(Store(), process, settings)
        cmd_dict["APP_" + _SimulationControllers[cname].__name__] = "Initializing"
        connector = _SimulationControllers[cname](settings, world, laysettings, cname, cframe)
        cframe.attach(connector)
        connectors.append(cframe)
        cframe.go(cmd_dict, timer)

    controller = MobdatController(logger, connectors, cmd_dict, autostart)
    controller.cmdloop()

    for connproc in connectors :
        connproc.join()
    print "closing down controller"
    sys.exit(0)