def build_environment_from_json(self): """Build env from jsondata.""" jsondata = JsonData.load_json_file(filename) # Create a instance of JsonData to store object that # needs to be sent to UI self.render = JsonData() self.render.objects = {} # First create the agents in the environment for name in jsondata.keys(): obj = eval(name.capitalize()) self.render.objects[name] = self.create_environment_object( jsondata, obj) self.hub = self.render.objects['hub'][0] self.total_food_units = 0 self.foods = [] self.sites = [] try: j = 0 for site in self.render.objects['sites']: self.sites.append(site) for i in range(self.num_agents * 1): f = Food(j, location=site.location, radius=site.radius) f.agent_name = None self.grid.add_object_to_grid(f.location, f) self.total_food_units += f.weight self.foods.append(f) j += 1 except KeyError: pass
def __init__(self, N, width, height, grid=10, seed=None): if seed is None: super(SingleCarryFoodModel, self).__init__(seed=None) else: super(SingleCarryFoodModel, self).__init__(seed) self.num_agents = N self.grid = Grid(width, height, grid) self.schedule = SimultaneousActivation(self) for a in range(5): self.thing = Food(id=a, location=(0, 0), radius=16) self.grid.add_object_to_grid(self.thing.location, self.thing) for i in range(self.num_agents): a = SwarmSingleCarryFood(i, self) self.schedule.add(a) x = 0 y = 0 a.location = (x, y) a.direction = -2.3561944901923448 self.grid.add_object_to_grid((x, y), a) self.agent = a
def __init__(self, N, width, height, grid=10, seed=None): if seed is None: super(XMLEnvironmentModel, self).__init__(seed=None) else: super(XMLEnvironmentModel, self).__init__(seed) self.num_agents = N self.grid = Grid(width, height, grid) self.schedule = SimultaneousActivation(self) self.site = Sites(id=1, location=(45, 45), radius=5, q_value=0.5) self.grid.add_object_to_grid(self.site.location, self.site) self.hub = Hub(id=1, location=(0, 0), radius=11) self.grid.add_object_to_grid(self.hub.location, self.hub) self.agents = [] # Create agents for i in range(self.num_agents): a = XMLTestAgent(i, self) self.schedule.add(a) x = 45 y = 45 a.location = (x, y) self.grid.add_object_to_grid((x, y), a) a.operation_threshold = 2 # self.num_agents // 10 self.agents.append(a) # Add equal number of food source for i in range(5): # self.num_agents * 2): f = Food(i, location=(45, 45), radius=3) f.agent_name = None self.grid.add_object_to_grid(f.location, f)
def build_environment_from_json(self): """Build env from jsondata.""" jsondata = JsonData.load_json_file(filename) # Create a instance of JsonData to store object that # needs to be sent to UI self.render = JsonData() self.render.objects = {} for name in jsondata.keys(): obj = eval(name.capitalize()) self.render.objects[name] = self.create_environment_object( jsondata, obj) self.hub = self.render.objects['hub'][0] try: self.site = self.render.objects['sites'][0] for i in range(self.num_agents * 1): f = Food( i, location=self.site.location, radius=self.site.radius) f.agent_name = None self.grid.add_object_to_grid(f.location, f) except KeyError: pass
def __init__(self, N, width, height, grid=10, seed=None, viewer=False): if seed is None: super(SingleCarryDropReturnSwarmEnvironmentModel, self).__init__(seed=None) else: super(SingleCarryDropReturnSwarmEnvironmentModel, self).__init__(seed) self.num_agents = N self.grid = Grid(width, height, grid) self.viewer = viewer self.schedule = SimultaneousActivation(self) self.hub = Hub(id=2, location=(0, 0), radius=5) self.grid.add_object_to_grid(self.hub.location, self.hub) self.site = Sites(id=3, location=(-35, -5), radius=5) self.grid.add_object_to_grid(self.site.location, self.site) self.agents = [] self.foods = [] for i in range(self.num_agents): f = Food(i, location=(-35, -5), radius=5) self.grid.add_object_to_grid(f.location, f) self.foods.append(f) for i in range(self.num_agents): # a = SwarmAgentRandomSingleCarryDropReturn(i, self) a = SwarmAgentHandCodedForaging(i, self) self.schedule.add(a) x = -45 y = -45 a.location = (x, y) a.direction = -2.3561944901923448 self.grid.add_object_to_grid((x, y), a) self.agents.append(a) if self.viewer: self.ui = UI((width, height), [self.hub], self.agents, [self.site], food=self.foods)