Example #1
0
def swarm_sim(argv):
    """In the main function first the config is getting parsed and than
    the swarm_sim_world and the swarm_sim_world item is created. Afterwards the run method of the swarm_sim_world
    is called in which the simlator is going to start to run"""
    config_data = config.ConfigData()

    unique_descriptor = "%s_%s_%s" % (config_data.local_time,
                                      config_data.scenario.rsplit('.', 1)[0],
                                      config_data.solution.rsplit('.', 1)[0])

    logging.basicConfig(filename="outputs/logs/system_%s.log" %
                        unique_descriptor,
                        filemode='w',
                        level=logging.INFO,
                        format='%(message)s')
    logging.info('Started')

    read_cmd_args(argv, config_data)
    create_directory_for_data(config_data, unique_descriptor)
    random.seed(config_data.seed_value)
    swarm_sim_world = world.World(config_data)
    swarm_sim_world.init_scenario(get_scenario(swarm_sim_world.config_data))

    reset = True
    while reset:
        reset = main_loop(config_data, swarm_sim_world)

    logging.info('Finished')
    generate_data(config_data, swarm_sim_world)
Example #2
0
    def __init__(self,
                 net_config,
                 num_agents=1,
                 timestep=0.010,
                 seed=None,
                 update_period=None):
        if update_period is None:
            update_period = len(goons)

        #get config data
        self.config_data = config.ConfigData()

        #set up logging
        unique_descriptor = "%s_%s_%s" % (
            self.config_data.local_time,
            self.config_data.scenario.rsplit(
                '.', 1)[0], self.config_data.solution.rsplit('.', 1)[0])

        logging.basicConfig(filename="outputs/logs/system_%s.log" %
                            unique_descriptor,
                            filemode='w',
                            level=logging.INFO,
                            format='%(message)s')
        logging.info('Started')

        read_cmd_args(self.config_data)

        create_directory_for_data(self.config_data, unique_descriptor)
        if seed is not None:
            self.config_data.seed_value = seed
        # random.seed(seed)
        # TODO : Move this to be different lol
        self.config_data.follow_the_leader = net_config.follow
        self.config_data.flock_rad = net_config.flock_rad
        self.config_data.flock_vel = net_config.flock_vel
        self.config_data.conn_class = net_config.conn_class
        self.config_data.num_agents = num_agents

        #set up world
        self.swarm_sim_world = world.World(self.config_data)
        self.swarm_sim_world.timestep = timestep
        self.swarm_sim_world.init_scenario(get_scenario(
            self.swarm_sim_world.config_data),
                                           num_agents=num_agents)
        self.swarm_sim_world.network_formed = False
        self._init_log(id="custom",
                       scenario=self.config_data.scenario,
                       num_agents=num_agents,
                       seed=self.config_data.seed_value,
                       comms=net_config.conn_class,
                       flock_rad=net_config.flock_rad,
                       flock_vel=net_config.flock_vel,
                       update_period=update_period)
Example #3
0
    def __init__(self):
        super(SingleExplorer, self).__init__()
        # Define action and observation space
        # They must be gym.spaces objects
        # Example when using discrete actions:
        ##may need to alter configdata to be closer to fit our needs.
        config_data = config.ConfigData()
        unique_descriptor = "%s_%s_%s" % (
            config_data.local_time, config_data.scenario.rsplit(
                '.', 1)[0], config_data.solution.rsplit('.', 1)[0])

        logging.basicConfig(filename="outputs/logs/system_%s.log" %
                            unique_descriptor,
                            filemode='w',
                            level=logging.INFO,
                            format='%(message)s')
        logging.info('Started')

        swarmsim.read_cmd_args(config_data)
        swarmsim.create_directory_for_data(config_data, unique_descriptor)
        swarmsim.random.seed(config_data.seed_value)
        self.swarm_sim_world = world.World(config_data)
        self.ts = 0
        self.discovered_items = set()
        self.explored_points = set()

        self.swarm_sim_world.init_scenario(swarmsim.get_scenario(config_data))
        #self.NUM_AGENTS = self.swarm_sim_world.get_amount_of_agents()
        #each agent can move one of 9 ways, with
        #self.action_space = spaces.MultiDiscrete(np.full_like(self.NUM_AGENTS, 9)) # xyz motion
        self.action_space = spaces.Discrete(
            len(self.swarm_sim_world.grid.get_directions_list()))
        #observation of the coordinates of each agent and the 6 neighboring locations
        #space should be the current position, plus the hops
        self.observation_space = spaces.Box(
            np.array([-9999, -9999, -9999] + [0] *
                     len(self.swarm_sim_world.grid.get_directions_list())),
            np.array([9999, 9999, 9999] + [1] *
                     len(self.swarm_sim_world.grid.get_directions_list())))