def make_world(self): world = World() # set any world properties first world.dim_c = 2 num_good_agents = 1 num_adversaries = 2 num_agents = num_adversaries + num_good_agents num_landmarks = 1 num_borders = 80 # (20 * 4) # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = True if i < num_adversaries else False agent.size = 0.075 if agent.adversary else 0.05 agent.accel = 3.0 if agent.adversary else 4.0 #agent.accel = 20.0 if agent.adversary else 25.0 agent.max_speed = 1.0 if agent.adversary else 1.3 # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.2 landmark.boundary = False # add borders """ shapes = [[[0.0, 0.0], [1.95, 0.0], [1.95, 0.05], [0.0, 0.05]], \ [[0.0, 0.0], [0.05, 0.0], [0.05, 1.95], [0.0, 1.95]], \ [[0.0, 0.0], [1.95, 0.0], [1.95, 0.05], [0.0, 0.05]], \ [[0.0, 0.0], [0.05, 0.0], [0.05, 1.95], [0.0, 1.95]]] """ world.borders = [Border() for i in range(num_borders)] for i, border in enumerate(world.borders): border.name = 'border %d' % i border.collide = True border.movable = False border.size = 0.15 border.boundary = False # border.shape = [[-0.05, -0.05], [0.05, -0.05], [0.05, 0.05], [-0.05, 0.05]] border.shape = [[-0.1, -0.1], [0.1, -0.1], [0.1, 0.1], [-0.1, 0.1]] #print(border.pos) # make initial conditions self.reset_world(world) return world
def make_world(self): # main configurations num_agents = 2 num_hills = 2 num_switches = 1 self.max_episode_length = 100 # create hills (on edges) possible_hill_positions = [ np.array([-0.8, 0]), np.array([0, 0.8]), np.array([0.8, 0]), np.array([0, -0.8]) ] hill_positions = random.sample(possible_hill_positions, k=num_hills) hills = [Hill(hill_positions[i]) for i in range(num_hills)] # create switches (in corners) possible_switch_positions = [ np.array([-0.8, -0.8]), np.array([-0.8, 0.8]), np.array([0.8, -0.8]), np.array([0.8, 0.8]) ] switch_positions = random.sample(possible_switch_positions, k=num_switches) switches = [Switch(switch_positions[i]) for i in range(num_switches)] # make world and set basic properties world = SwitchWorld(hills, switches) world.dim_c = 2 world.collaborative = True # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.size = 0.1 agent.accel = 5.0 agent.max_speed = 5.0 if i == 0: agent.color = np.array([0.35, 0.35, 0.85]) else: agent.color = np.array([0.35, 0.85, 0.85]) # make initial conditions self.reset_world(world) return world
def make_world(self, staged=False, set_trap=True, use_dense_rewards=False): world = World() world.use_dense_rewards = use_dense_rewards # set any world properties first self.staged = staged self.set_trap = set_trap num_agents = 2 num_landmarks = 2 * num_agents self.num_walls = 4 + int(self.staged) # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False landmark.size *= 4 landmark.is_activated = False # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = False if i == 0: agent.role = 'imitator' agent.clip_positions = np.array( [[-world.scale, .55 * world.scale], [world.scale, world.scale]]) agent.landmarks = [world.landmarks[2], world.landmarks[3]] self.trap_width = agent.size * 4. elif i == 1: agent.role = 'demonstrator' agent.clip_positions = np.array( [[-world.scale, -world.scale], [world.scale, .45 * world.scale]]) agent.landmarks = [world.landmarks[0], world.landmarks[1]] else: raise ValueError( 'There should only be two agents in this scenario') # add walls to force the "leader" through a longer path world.walls = [Wall() for i in range(self.num_walls)] if self.set_trap: world.trap = Wall() world.walls.append(world.trap) # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 4 #world.damping = 1 num_good_agents = 1 num_adversaries = 2 num_agents = num_adversaries + num_good_agents num_landmarks = 1 num_food = 1 num_forests = 2 # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.leader = True if i == 0 else False agent.silent = True if i > 0 else False agent.adversary = True if i < num_adversaries else False agent.size = 0.075 if agent.adversary else 0.045 agent.accel = 3.0 if agent.adversary else 4.0 #agent.accel = 20.0 if agent.adversary else 25.0 agent.max_speed = 1.0 if agent.adversary else 1.3 # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.2 landmark.boundary = False world.food = [Landmark() for i in range(num_food)] for i, landmark in enumerate(world.food): landmark.name = 'food %d' % i landmark.collide = False landmark.movable = False landmark.size = 0.03 landmark.boundary = False world.forests = [Landmark() for i in range(num_forests)] for i, landmark in enumerate(world.forests): landmark.name = 'forest %d' % i landmark.collide = False landmark.movable = False landmark.size = 0.3 landmark.boundary = False world.landmarks += world.food world.landmarks += world.forests #world.landmarks += self.set_boundaries(world) # world boundaries now penalized with negative reward # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first num_humans = 2 num_zombies = 5 num_agents = num_humans + num_zombies # add agents agents = [] # add humans' team for i in range(num_humans): agent = Agent() agent.collide = True agent.team = 0 agent.name = 'human %d' % i agent.size = 0.05 agent.accel = 4.0 agent.max_speed = 1.3 agent.health_decay = 0.99 agents.append(agent) # add zombies' team for i in range(num_zombies): agent = Agent() agent.collide = True agent.team = 1 agent.name = 'zombie %d' % i agent.size = 0.05 agent.accel = 3.0 agent.max_speed = 1.0 agents.append(agent) world.agents = agents # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 num_agents = self.num_agents num_landmarks = self.num_agents num_obstacles = 12 # generate one-hot encoding for unique hidden goals self.one_hot_array = list(itertools.product([0, 1], repeat=num_landmarks)) # generate colours for goal identification for _ in range(num_landmarks): self.colours.append(np.random.uniform(-1, +1, 3)) # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.size = 0.10 agent.color = self.colours[i] # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False landmark.color = self.colours[i] landmark.id = self.one_hot_array[2**i] self.occupied_landmarks.append(0) # add obstacles world.obstacles = [Landmark() for i in range(num_obstacles)] for i, obstacle in enumerate(world.obstacles): obstacle.name = 'obstacle %d' % i obstacle.collide = True obstacle.movable = False obstacle.size = 0.40 obstacle.boundary = False obstacle.color = np.array([0.25, 0.25, 0.25]) # self.create_wall(world, obstacle, 10, -0.2, -1, -0.2, -0.2) # make initial conditions for i, agent in enumerate(world.agents): agent.state.p_pos = np.array(self.sample_position()) if i > 0: self.check_for_spawn_clash(world.agents, agent) agent.state.p_vel = np.zeros(world.dim_p) agent.state.c = np.zeros(world.dim_c) self.assign_goals(i, agent) self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.cache_dists = True world.dim_c = 2 num_agents = 8 num_collectors = 6 num_deposits = num_agents - num_collectors world.treasure_types = list(range(num_deposits)) world.treasure_colors = np.array( sns.color_palette(n_colors=num_deposits)) num_treasures = num_collectors # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.i = i agent.name = 'agent %d' % i agent.collector = True if i < num_collectors else False if agent.collector: agent.color = np.array([0.85, 0.85, 0.85]) else: agent.d_i = i - num_collectors agent.color = world.treasure_colors[agent.d_i] * 0.35 agent.collide = True agent.silent = True agent.ghost = True agent.holding = None agent.size = 0.05 if agent.collector else 0.075 agent.accel = 1.5 agent.initial_mass = 1.0 if agent.collector else 2.25 agent.max_speed = 1.0 # add treasures world.landmarks = [Landmark() for i in range(num_treasures)] for i, landmark in enumerate(world.landmarks): landmark.i = i + num_agents landmark.name = 'treasure %d' % i landmark.respawn_prob = 1.0 landmark.type = np.random.choice(world.treasure_types) landmark.color = world.treasure_colors[landmark.type] landmark.alive = True landmark.collide = False landmark.movable = False landmark.size = 0.025 landmark.boundary = False world.walls = [] # make initial conditions self.reset_world(world) self.reset_cached_rewards() return world
def make_world(self): world = World() # add agents world.agents = [Agent() for i in range(numAgents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.sight = 0.2 agent.size = 0.05 agent.max_speed = 0.3 # make initial conditions self.reset_world(world) return world
def make_world(self, config): self.shaping = config.shaping self.predators_comm = config.predators_comm world = World() world.randomPreySpeed = True if config.prey_max_speed == 'random' else False # set any world properties first world.dim_c = config.predators_comm_size if config.predators_comm else 0 num_prey = config.num_prey num_predators = config.num_predators num_agents = num_predators + num_prey num_landmarks = config.num_landmarks # add walls if config.bound_world: world.walls.append(Wall(orient='H', axis_pos=1.3, endpoints=(-2, 2), width=0.2, hard=True)) world.walls.append(Wall(orient='H', axis_pos=-1.3, endpoints=(-2, 2), width=0.2, hard=True)) world.walls.append(Wall(orient='V', axis_pos=1.3, endpoints=(-2, 2), width=0.2, hard=True)) world.walls.append(Wall(orient='V', axis_pos=-1.3, endpoints=(-2, 2), width=0.2, hard=True)) # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.id = i agent.collide = True agent.adversary = True if i < num_predators else False # if config.predators_comm: # agent.silent = False if agent.adversary else True # Oren # else: # agent.silent = True agent.silent = True agent.size = 0.075 if agent.adversary else 0.05 # agent.accel = 3.0 if agent.adversary else 2.0 # agent.max_speed = 1.0 if agent.adversary else 0.5 agent.accel = config.pred_acc if agent.adversary else config.prey_acc agent.max_speed = config.pred_max_speed if agent.adversary else config.prey_max_speed # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.2 landmark.boundary = False # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 num_agents = FLAGS.num_uav # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = False agent.silent = True agent.max_speed = FLAGS.max_speed / FLAGS.map_scale_rate / 0.1 agent.size = FLAGS.radius / FLAGS.map_scale_rate # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 # self.num_groups = cfg.gs.num_groups # self.num_landmarks = cfg.gs.num_landmarks # self.has_collision = cfg.gs.has_collision # individual can/cannot overlap # self.has_comm = cfg.gs.has_comm # individual can/cannot communicate # self.different_landmarks = cfg.gs.different_landmarks # targets of different groups are/aren't different. # # world.collaborative = True # self.group_colours = cfg.gs.group_colours self.num_groups = 2 self.num_landmarks = 3 self.has_collision = False # individual can/cannot overlap self.has_comm = False # individual can/cannot communicate self.different_landmarks = True # targets of different groups are/aren't different. # world.collaborative = True self.group_colours = [[0.35, 0.35, 0.85], [0.35, 0.85, 0.35]] assert (len(self.group_colours) == self.num_groups) # add agents num_agents = self.num_groups * self.num_landmarks world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d group %d' % (i, i // self.num_landmarks) agent.collide = self.has_collision agent.silent = not self.has_comm agent.size = 0.15 # add landmarks total_landmarks = \ num_agents if self.different_landmarks else \ self.num_landmarks world.landmarks = [Landmark() for i in range(total_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = ('landmark %d' % i) \ + (' group %d' % (i // self.num_landmarks) \ if self.different_landmarks else '') landmark.collide = False landmark.movable = False # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # add agents world.agents = [Agent() for i in range(1)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = False agent.silent = True # add landmarks world.landmarks = [Landmark() for i in range(1)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False # make initial conditions self.reset_world(world) return world
def make_world(self, team_size=1): world = World() world.use_walls = True world.goal_width = 0.20 # set any world properties first world.dim_c = 2 num_good_agents = team_size num_adversaries = team_size num_agents = num_adversaries + num_good_agents num_landmarks = 1 # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = True if i < num_adversaries else False agent.size = 0.06 agent.accel = 2.0 agent.kicking = True angle = np.linspace(0, 2 * np.pi, 16, endpoint=False)[np.newaxis, :] agent.kicks = np.concatenate([np.cos(angle), np.sin(angle)]).T * 2.35 agent.discrete_action_space = False agent.max_speed = 0.75 agent.is_ball = False # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] landmark = world.landmarks[0] landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = True landmark.size = 0.06 landmark.is_ball = True landmark.adversary = -1 # make initial conditions def done(agent, world): return self.is_goal(world) world.is_scenareo_over = done self.reset_world(world) return world
def make_world(self, graph_obs=False): world = World() world.graph_obs = graph_obs # set any world properties first world.dim_c = 2 num_good_agents = 4 num_adversaries = 4 num_agents = num_adversaries + num_good_agents num_landmarks = 2 num_walls = 0 # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = True if i < num_adversaries else False agent.size = 0.075 if agent.adversary else 0.05 agent.accel = 3.0 if agent.adversary else 4.0 #agent.accel = 20.0 if agent.adversary else 25.0 agent.max_speed = 1.0 if agent.adversary else 1.3 # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.2 landmark.boundary = False world.walls = [Wall() for i in range(num_walls)] for i, wall in enumerate(world.walls): wall.name = 'wall %d' % i wall.collide = True wall.movable = False wall.size = 0.0 wall.boundary = False if num_walls != 0: world.walls[0].state.p_pos = np.asarray([1, 0]) world.walls[1].state.p_pos = np.asarray([0, 1]) world.walls[2].state.p_pos = np.asarray([-1, 0]) world.walls[3].state.p_pos = np.asarray([0, -1]) # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first num_good_agents = 2 num_adversaries = 2 num_balloons = 5 num_landmarks = 3 vocabulary_size = 2 world.dim_c = vocabulary_size num_agents = num_adversaries + num_good_agents # add agents world.agents = [Agent() for _ in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.index = i agent.collide = True agent.adversary = True if i < num_adversaries else False agent.size = 0.1 if agent.adversary else 0.1 agent.accel = 3.0 if agent.adversary else 4.0 agent.max_speed = 1.0 if agent.adversary else 1.3 # Added attributes for balloons and observation range agent.num_balloons = num_balloons agent.init_num_balloons = num_balloons agent.obs_range = 3.0 if agent.adversary else 3.0 agent.atk_range = 0.5 if agent.adversary else 0.5 agent.team = 0 if agent.adversary else 1 agent.state.c = np.zeros((num_agents, world.dim_c), dtype=int) world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.1 landmark.boundary = False # make initial conditions self.obs = {} self.reset_world(world) return world
def make_world(self): print("**********liyuan scenario*************") world = World() # set any world properties first world.dim_c = 2 num_good_agents = 3 num_adversaries = 3 num_agents = num_adversaries + num_good_agents num_landmarks = 0 self.num_green = copy.deepcopy(num_good_agents) self.num_red = copy.deepcopy(num_adversaries) # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = True if i < num_adversaries else False agent.size = 0.04 if agent.adversary else 0.04 # agent.accel = 3.0 if agent.adversary else 2.0 agent.accel = 2.0 if agent.adversary else 2.0 # agent.accel = 20.0 if agent.adversary else 25.0 # agent.max_speed = 1.5 if agent.adversary else 1.2 # agent.max_speed = 1.0 if agent.adversary else 1.0 agent.max_speed = 1.0 if agent.adversary else 0.5 ###changed by liyuan agent.death = False agent.chi = np.array([0.1, 0]) if agent.adversary: agent.lock_num = [0 for j in range(num_good_agents)] else: agent.lock_num = [0 for j in range(num_adversaries)] # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.2 landmark.boundary = False # make initial conditions self.reset_world(world) return world
def make_world(self, args): if 'shared_obs' in args.keys(): self.shared_obs = args['shared_obs'] else: self.shared_obs = True if ('boundary' in args.keys()) and (args['boundary'] is not None): world = World(boundary=args['boundary']) else: world = World() # set any world properties first world.dim_c = 2 if ('num_agents' in args.keys()) and (args['num_agents'] is not None): num_agents = args['num_agents'] else: num_agents = 3 self.num_agents = num_agents if ('num_landmarks' in args.keys()) and (args['num_landmarks'] is not None): num_landmarks = args['num_landmarks'] else: num_landmarks = 3 self.num_landmarks = num_landmarks world.collaborative = True # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = False agent.size = 0.15 agent.id = i # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False # make initial conditions self.reset_world(world) self.self_obs_indices = np.arange(2 * world.dim_p + num_landmarks * world.dim_p) return world
def make_world(self, n_agents, config, prob_random): """ n_agents - number of agents (also equal to number of target landmarks) config - dictionary prob_random - probability of random agent and landmark initial locations """ world = World() # set any world properties first world.dim_c = 0 self.n_agents = n_agents self.agents_x = config['agents_x'] self.agents_y = config['agents_y'] self.landmarks_x = config['landmarks_x'] self.landmarks_y = config['landmarks_y'] # standard deviation of Gaussian noise on initial agent location self.initial_std = config['initial_std'] self.prob_random = prob_random num_agents = n_agents num_landmarks = n_agents # deliberate False, to prevent environment.py from sharing reward world.collaborative = False # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.idx = i agent.collide = True agent.silent = True agent.size = 0.15 # agent.size = 0.1 agent.reached = False # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.idx = i landmark.collide = False landmark.movable = False # landmark.size = 0.05 # read colors # self.colors = np.loadtxt('colors.csv', delimiter=',') self.colors = colors # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 num_agents = 3 num_landmarks = 8 world.collaborative = True # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): if i == 0: agent.name = 'poacher' agent.size = 0.075 agent.id = 1 agent.accel = 2 agent.max_speed = 1 agent.sight = 0.3 agent.color = np.array([0.85, 0.35, 0.35]) if i == 1: agent.name = 'ranger' agent.size = 0.075 agent.id = 2 agent.accel = 2.15 agent.max_speed = 1 agent.sight = 0.3 agent.color = np.array([0.35, 0.35, 0.85]) if i == 2: agent.name = 'uav' agent.size = 0.05 agent.id = 3 agent.accel = 3 agent.max_speed = 1.3 agent.sight = 0.5 agent.color = np.array([0.35, 0.85, 0.35]) # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'animal %d' % i landmark.collide = False landmark.movable = False landmark.collisionTimes = 0 landmark.captured = False # make initial conditions self.reset_world(world) return world
def make_world(self, mode): world = World() self.mode = mode # add agents world.agents = [Agent() for i in range(2)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.size = 0.1 # add boxes n_box = 1 # One box and pushing to left self.boxes = [Landmark() for _ in range(n_box)] for i, box in enumerate(self.boxes): box.name = 'box %d' % i box.collide = True box.movable = True box.size = 0.25 box.initial_mass = 7. box.index = i world.landmarks.append(box) # add targets self.targets = [Landmark() for _ in range(2)] for i, target in enumerate(self.targets): target.name = 'target %d' % i target.collide = False target.movable = False target.size = 0.05 target.index = i world.landmarks.append(target) # add goals (used only for vis) world.goals = [Goal() for i in range(len(world.agents))] for i, goal in enumerate(world.goals): goal.name = 'goal %d' % i goal.collide = False goal.movable = False # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 num_agents = 2 num_landmarks = num_agents + 1 num_goals = num_agents world.collaborative = True # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = False agent.silent = True agent.size = 0.15 world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): # Add landmarks if i == 0 or i == 1: landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False landmark.size = 0.10 elif i == 2: # Add oracle landmark.name = "oracle" landmark.collide = False landmark.movable = False landmark.oracle_on = False landmark.size = 0.10 else: raise ValueError() # add goals (used only for vis) world.goals = [Goal() for i in range(num_goals)] for i, goal in enumerate(world.goals): goal.name = 'goal %d' % i goal.collide = False goal.movable = False # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() world.es = Geo_env(coord_len=12,red_line_total=red_line_total) world.red = world.es.red_line world.red_init = world.red world.norm = [(world.es.red_line_maxx-world.es.red_line_minx),(world.es.red_line_maxy-world.es.red_line_miny)] # add agents world.agents = [Agent() for i in range(world.es.coord_len)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.index = i agent.collide = False agent.silent = True agent.adversary = False agent.color = np.array([0.25,0.25,0.25]) self.reset_world(world) return world
def make_world(self): # world object keeps list of agents and entities (can change at execution-time!) world = World() # add agents world.agents = [Agent() for i in range(1)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = False agent.silent = True # add landmarks world.landmarks = [Landmark() for i in range(1)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False # make initial conditions self.reset_world(world) return world
def reset_world(self, world): world = World() # add agents world.agents = [ Agent(i, self.num_tasks, self.maxTask, self.num_agents) for i in range(self.num_agents) ] world.int_matrix = self.generate_graph(world) for i, agent in enumerate(world.agents): _, agent.state[0], agent.nghd = self.secondhop(world.int_matrix, i) agent.c = np.random.uniform(0, 100, self.num_tasks) world.initializeCommDictionaries() world.updateCommNeighbors() reward_i = self.ideal_reward(world) return reward_i
def make_world(self): world = World() # set any world properties first world.dim_c = 10 # add agents world.agents = [Agent() for i in range(2)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = False # add landmarks world.landmarks = [Landmark() for i in range(3)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False # make initial conditions self.reset_world(world) return world
def make_world(self, name, num_good_agents=0, num_adversaries=0, is_random_states_for_new_agent=False, bounds=False, REWARD_FOR_COLISION=10, adv_speed=1.5, good_speed=0.7): self.name = name self.bounds = bounds self.is_random_states_for_new_agent = is_random_states_for_new_agent self.REWARD_FOR_COLISION = REWARD_FOR_COLISION self.evaluate = False world = World() # set any world properties first world.dim_c = 2 num_good_agents = num_good_agents num_adversaries = num_adversaries num_agents = num_adversaries + num_good_agents num_landmarks = 0 # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = True if i < num_adversaries else False agent.size = 0.02 if agent.adversary else 0.02 agent.accel = 3.0 if agent.adversary else 4.0 # agent.accel = 20.0 if agent.adversary else 25.0 agent.max_speed = adv_speed if agent.adversary else good_speed # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.2 landmark.boundary = False # make initial conditions self.reset_world(world) self.evaluate = False return world
def make_world(self): """Define two agents, one box, and two targets. Note that world.goals are used only for hierarchical RL visualization only Note that this domain should have one target. But, we empirically found that having the additional right target does not affect performance much as the reward is based on the left target only """ world = World() world.agents = [Agent() for i in range(2)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.size = 0.1 # Radius self.boxes = [Landmark() for _ in range(1)] for i, box in enumerate(self.boxes): box.name = 'box %d' % i box.collide = True box.movable = True box.size = 0.25 box.initial_mass = 7. box.index = i world.landmarks.append(box) self.targets = [Landmark() for _ in range(2)] for i, target in enumerate(self.targets): target.name = 'target %d' % i target.collide = False target.movable = False target.size = 0.05 target.index = i world.landmarks.append(target) world.goals = [Goal() for i in range(len(world.agents))] for i, goal in enumerate(world.goals): goal.name = 'goal %d' % i goal.collide = False goal.movable = False self.reset_world(world) return world
def make_world(self, args): if ('boundary' in args.keys()) and args['boundary']: world = World(boundary=args['boundary']) else: world = World() # set any world properties first world.dim_c = 2 if ('num_agents' in args.keys()) and args['num_agents']: num_good_agents = args['num_agents'] else: num_good_agents = 2 if ('num_adversaries' in args.keys()) and args['num_adversaries']: num_adversaries = args['num_adversaries'] else: num_adversaries = 1 num_agents = num_adversaries + num_good_agents world.num_agents = num_agents if ('num_landmarks' in args.keys()) and args['num_landmarks']: num_landmarks = args['num_landmarks'] else: num_landmarks = 2 # num_agents = 3 # world.num_agents = num_agents # num_adversaries = 1 # num_landmarks = num_agents - 1 # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = False agent.silent = True agent.adversary = True if i < num_adversaries else False agent.size = 0.15 # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False landmark.size = 0.08 # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 num_agents = 6 world.num_agents = num_agents num_adversaries = num_agents - 1 num_landmarks = 1 num_obstacles = 1 # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = True if i < num_adversaries else False agent.size = 0.08 if i < num_adversaries else 0.10 agent.max_speed = 0.9 if i < num_adversaries else None # add landmarks world.landmarks = [Landmark() for i in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False landmark.size = 0.03 # add obstacle world.obstacles = [Landmark() for i in range(num_obstacles)] for i, obstacle in enumerate(world.obstacles): obstacle.name = 'obstacle %d' % i obstacle.collide = True obstacle.movable = True obstacle.size = 0.30 # make initial conditions for agent in world.agents: agent.state.p_pos = np.random.uniform(-1, +1, world.dim_p) agent.state.p_vel = np.zeros(world.dim_p) agent.state.c = np.zeros(world.dim_c) for obstacle in world.obstacles: obstacle.state.p_pos = np.random.uniform(-1, +1, world.dim_p) self.obstacle_vel = np.random.uniform(-1, +1, world.dim_p) obstacle.state.p_vel = self.obstacle_vel obstacle.state.c = np.zeros(world.dim_c) self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 num_agents = 1 num_obstacle = 4 num_target = 1 world.collaborative = True # add agents world.agents = [Agent() for i in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.size = 0.1 # add obstacles world.landmarks = [Landmark() for i in range(num_obstacle)] for i, landmark in enumerate(world.landmarks): landmark.name = 'obstacle %d' % i landmark.collide = True landmark.movable = False landmark.size = 0.1 # add target target = Landmark() target.name = 'target' target.collide = False target.movable = False target.size = 0.1 # Merge the landmarks (obstacles + target) world.landmarks.append(target) # make initial conditions self.n = num_agents self.x = [0.0, 0.0] * num_agents self.y = [0.0, 0.0] * num_agents self.theta = [0.0, 0.0] * num_agents self.reset_world(world) # Send initial information to pheromone system self.sock_sender.send_number(self.n) return world