예제 #1
0
    def __init__(self, params: GridParams, stats):
        super().__init__(params, stats)
        self.params = params
        if params.multi_agent:
            self.num_agents = params.num_agents_range[0]
        else:
            self.num_agents = 1

        self.device_list = None
        self.device_manager = DeviceManager(self.params.device_manager)

        free_space = np.logical_not(
            np.logical_or(self.map_image.obstacles,
                          self.map_image.start_land_zone))
        free_idcs = np.where(free_space)
        self.device_positions = list(zip(free_idcs[1], free_idcs[0]))
예제 #2
0
    def __init__(self, root):
        self.root = root
        self.root.protocol("WM_DELETE_WINDOW", self.exit)

        self.dev_views = dict()  # Кортеж видов для устройств

        self.log = LogGetter.get_logger()  # Создаем логер
        self.settings = None  # Создаем настройки
        self.dm = DeviceManager(self.log)  # Создаем менеджер устройств
        for dev_name in DEV_LIST:  # Добовляем устройства к менеджеру
            self.dm.add_device(dev_name)

        self.init_gui()  # Создаем форму

        self.task_ctrl.load_settings()
        for dev_view in self.dev_views.values():  # Обновляем список устройств
            dev_view.refresh_devices()  # для каждого вида
예제 #3
0
class Oscil_GUI:
    def __init__(self, root):
        self.root = root
        self.root.protocol("WM_DELETE_WINDOW", self.exit)

        self.dev_views = dict()  # Кортеж видов для устройств

        self.log = LogGetter.get_logger()  # Создаем логер
        self.settings = None  # Создаем настройки
        self.dm = DeviceManager(self.log)  # Создаем менеджер устройств
        for dev_name in DEV_LIST:  # Добовляем устройства к менеджеру
            self.dm.add_device(dev_name)

        self.init_gui()  # Создаем форму

        self.task_ctrl.load_settings()
        for dev_view in self.dev_views.values():  # Обновляем список устройств
            dev_view.refresh_devices()  # для каждого вида

    def init_gui(self):
        self.fileoptions = FileOptions(self.root)
        for dev_name in DEV_LIST:
            device = self.dm.devices[dev_name]
            if device is not None:
                self.dev_views[dev_name] = DeviceView(self.root, self.dm,
                                                      device, self.log)

        self.task_ctrl = TaskControl(self)

        self.console = ConsoleView(self.root)
        wh = ConsoleHandler(self.console)  # Подписываем консоль к логеру
        self.log.addHandler(wh)

        self.fileoptions.pack(side="top", fill="both")
        for dev in self.dev_views.values():
            dev.pack(side="top", fill="both")
        self.task_ctrl.pack(side="top", fill="both")
        self.console.pack(side="top", fill="both")

    def exit(self):
        self.dm.close_all()
        self.root.destroy()
예제 #4
0
class Grid(BaseGrid):
    def __init__(self, params: GridParams, stats):
        super().__init__(params, stats)
        self.params = params
        if params.multi_agent:
            self.num_agents = params.num_agents_range[0]
        else:
            self.num_agents = 1

        self.device_list = None
        self.device_manager = DeviceManager(self.params.device_manager)

        free_space = np.logical_not(
            np.logical_or(self.map_image.obstacles,
                          self.map_image.start_land_zone))
        free_idcs = np.where(free_space)
        self.device_positions = list(zip(free_idcs[1], free_idcs[0]))

    def get_comm_obstacles(self):
        return self.map_image.obstacles

    def get_data_map(self):
        return self.device_list.get_data_map(self.shape)

    def get_collected_map(self):
        return self.device_list.get_collected_map(self.shape)

    def get_device_list(self):
        return self.device_list

    def get_grid_params(self):
        return self.params

    def init_episode(self):
        self.device_list = self.device_manager.generate_device_list(
            self.device_positions)

        if self.params.multi_agent:
            self.num_agents = int(
                np.random.randint(low=self.params.num_agents_range[0],
                                  high=self.params.num_agents_range[1] + 1,
                                  size=1))
        else:
            self.num_agents = 1
        state = State(self.map_image, self.num_agents, self.params.multi_agent)
        state.reset_devices(self.device_list)

        if self.params.fixed_starting_idcs:
            idx = self.params.starting_idcs
        else:
            # Replace False insures that starting positions of the agents are different
            idx = np.random.choice(len(self.starting_vector),
                                   size=self.num_agents,
                                   replace=False)
        state.positions = [self.starting_vector[i] for i in idx]

        state.movement_budgets = np.random.randint(
            low=self.params.movement_range[0],
            high=self.params.movement_range[1] + 1,
            size=self.num_agents)

        state.initial_movement_budgets = state.movement_budgets.copy()

        return state

    def init_scenario(self, scenario):
        self.device_list = scenario.device_list
        self.num_agents = scenario.init_state.num_agents

        return scenario.init_state

    def get_example_state(self):
        if self.params.multi_agent:
            num_agents = self.params.num_agents_range[0]
        else:
            num_agents = 1
        state = State(self.map_image, num_agents, self.params.multi_agent)
        state.device_map = np.zeros(self.shape, dtype=float)
        state.collected = np.zeros(self.shape, dtype=float)
        return state
예제 #5
0
 def __init__(self):
     Cmd.__init__(self)
     self.DeviceManager = DeviceManager()
     self.intro = """
예제 #6
0
class MyPrompt(Cmd):
    def __init__(self):
        Cmd.__init__(self)
        self.DeviceManager = DeviceManager()
        self.intro = """
   ____   ______  ___           _           _____            __     __          
  /  _/__/_  __/ / _ \___ _  __(_)______   / __(_)_ _  __ __/ /__ _/ /____  ____
 _/ // _ \/ /   / // / -_) |/ / / __/ -_) _\ \/ /  ' \/ // / / _ `/ __/ _ \/ __/
/___/\___/_/   /____/\__/|___/_/\__/\__/ /___/_/_/_/_/\_,_/_/\_,_/\__/\___/_/   
================================================================================                                                                                
Type 'help' to see available commands
        """

    def do_provision(self, args):
        """Adds a new device to the device manager. Does not take args"""
        self.DeviceManager.add_device()

    def do_delete(self, args):
        """Deletes device from the manager, must supply short name of the device"""
        if len(args.split()) == 2:
            self.DeviceManager.remove_device(args)
        else:
            print("Incorrect number of args sent!")

    def do_list(self, args):
        """Lists all Devices currently managed"""
        print(self.DeviceManager)

    def do_run(self, args):
        """Stars the devices run thread, must supply short name of the device"""
        if len(args.split()) == 2:
            self.DeviceManager.run_device(args)
        else:
            print("Incorrect number of args sent!")

    def do_stop(self, args):
        """Stops the devices run thread, must supply short name of the device"""
        if len(args.split()) == 2:
            self.DeviceManager.stop_device(args)
        else:
            print("Incorrect number of args sent!")

    def do_read(self, args):
        """Reads the last payload generated by device, must supply short name of the device"""
        if len(args.split()) == 3:
            args = args.split()
            payl = self.DeviceManager.find_payload("{} {}".format(
                args[0], args[1]))
            print(
                json.dumps(
                    payl[args[2]],
                    indent=4,
                    default=str,
                    sort_keys=True,
                ))
        elif len(args.split()) == 2:
            payl = self.DeviceManager.find_payload(args)
            print(json.dumps(
                payl,
                indent=4,
                default=str,
                sort_keys=True,
            ))
        else:
            print("Incorrect number of args sent!")

    def do_stats(self, args):
        """Displays some statistics about the device running, must supply short name of the device"""
        if len(args.split()) == 2:
            self.DeviceManager.find_stats(args)
        else:
            print("Incorrect number of args sent!")

    def do_quit(self, args):
        """Quits the program."""
        print("--------------------")
        print("Quitting.")
        print("Removing all Devices")
        self.DeviceManager.remove_all_devices()
        raise SystemExit
예제 #7
0
def test_add_device():
    dm = DeviceManager(Fake_log())
    dm.add_device('123')
예제 #8
0
def test_init():
    dm = DeviceManager(Fake_log())