def make_world(self): # world = World(self.scripted_agents, self.observation) world = World(None, self.observation) self.np_rnd = np.random.RandomState(0) # set any world properties first world.dim_c = 2 num_good_agents = 3 num_adversaries = 2 world.num_adversaries = num_adversaries num_agents = num_adversaries + num_good_agents num_landmarks = 2 self.world_radius = 1 # add agents world.agents = [Agent(), Agent(), Agent(), Agent(), Agent()] # world.agents = [Agent(), Agent(), Agent(), Agent(action_callback)] 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 # 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 = 7 num_preys = 3 world.collaborative = False world.discrete_action = True world.num_agents_obs = 3 world.num_preys_obs = 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.04 agent.accel = 5.0 # add landmarks world.preys = [Agent() for i in range(num_preys)] for i, prey in enumerate(world.preys): prey.name = 'prey %d' % i prey.collide = False prey.movable = True prey.silent = True prey.size = 0.05 prey.accel = 7.0 # make initial conditions self.reset_world(world) return world
def _create_agent_base(self, ind): agent = Agent() agent.i = ind agent.name = 'agent %i' % agent.i agent.collide = False agent.size = 0.075 agent.accel = 1.5 agent.initial_mass = 1.0 agent.max_speed = 1.0 agent.predicted = False return agent
def make_world(self): world = World() # set any world properties first world.dim_c = 2 world.num_agents = 4 world.num_goals = 4 # world.num_obstacles = 2 world.num_obstacles = 2 world.collaborative = True # self.landmarkspeed = np.random.normal(size=2) # add agents world.agents = [Agent() for i in range(world.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 goals world.landmarks = [ Landmark() for i in range(world.num_goals + world.num_obstacles) ] p_vel = np.random.normal(size=2) for i, landmark in enumerate(world.landmarks): if i < world.num_goals: landmark.name = 'goal %d' % i landmark.collide = False landmark.movable = False landmark.state.p_vel = p_vel else: landmark.name = 'obstacle %d' % (i - world.num_goals) landmark.collide = True landmark.movable = False self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 world.num_agents = num_agents = 1 world.num_goals = num_goals = 1 world.num_obstacles = num_obstacles = 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 landmarks world.landmarks = [ Landmark() for i in range(num_goals + num_obstacles) ] for i, landmark in enumerate(world.landmarks): if i < num_goals: landmark.name = 'goal %d' % i landmark.collide = True landmark.movable = False else: landmark.name = 'obstacle %d' % (i - num_goals) landmark.size = 0.1 landmark.collide = True landmark.movable = False # make initial conditions 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 = 2 num_landmarks = 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.size = 0.03 agent.holding = 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.collide = True landmark.movable = False landmark.size = 0.02 landmark.collector = True if i < 2 else False # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 3 num_landmarks = 3 world.collaborative = True # 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 agent.size = 0.075 # speaker world.agents[0].movable = False # listener world.agents[1].silent = True # 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.04 # 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 = 3 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.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 # add noise field noise_field = create_noise_field(world.dim_p) world.landmarks.append(noise_field) # make initial conditions self.reset_world(world) return world
def make_world(self, use_dense_rewards=True): world = World() world.use_dense_rewards = True # We always use_dense_rewards in this task # set any world properties first num_landmarks = 3 num_agents = 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.clip_positions = np.array([[-world.scale, -world.scale], [world.scale, world.scale]]) agent.collide = False if i == 0: agent.role = "runner" elif i == 1: agent.role = "pursuer" else: raise ValueError( 'There should only be two agents in this scenario') # 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 # 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 = 1 world.collaborative = False # add agents world.agents = [Agent(iden=i) 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.05 agent.adversary = 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.collide = False landmark.movable = False landmark.size = 0.03 # make initial conditions self.reset_world(world) world.dists = [] return world
def make_world(self): world = World(is_dynamic=False, position_scale=50000.0) world.discrete_action_space = True world.dt = 1.0 n_landmarks = 1 # 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 agent.fusioned_sa = LandMarkObservation(n_landmarks, agent, world) agent.platform_action = HeadingAction() agent.fire_action = FireAction(2) agent.max_speed = 350.0 # 700.0 agent.min_speed = 0.8 * agent.max_speed agent.accel = [1.0 * 9.81, 8.0] agent.sensor = Sensor([2 * np.pi / 3], [100000.0], [2.5e-5]) # add landmarks world.landmarks = [Landmark() for i in range(n_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False # landmark.rwr = Rwr(max_range=200000.0, min_range=2.5e-5) # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 2 # communication channel dimensionality num_observers = 3 num_targets = 0 # add agents world.agents = [Agent() for i in range(num_observers)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.adversary = True agent.size = 0.05 agent.accel = 4.0 agent.max_speed = 1.3 # add targets world.landmarks = [Landmark() for i in range(num_targets)] for i, landmark in enumerate(world.landmarks): landmark.name = 'target %d' % i landmark.collide = True landmark.movable = True landmark.size = 0.2 landmark.accel = 3.0 landmark.max_speed = 1.0 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 self.threshold_dist = 0.1 self.num_agents = 4 self.num_landmarks = 4 self.exist_pen = -0.001 self.cum_pen = [0] * self.num_agents print("NUMBER OF AGENTS:", self.num_agents) print("NUMBER OF LANDMARKS:", self.num_landmarks) world.collaborative = True # add agents world.agents = [Agent() for i in range(self.num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.size = 0.1 # Pairing landmarks i with N-i # add landmarks world.landmarks = [Landmark() for i in range(self.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) return world
def make_world(self, **kwargs): self.before_make_world(**kwargs) world = World() world.np_random = self.np_random # set any world properties first world.dim_c = 2 num_agents = 2 num_adversaries = 1 num_landmarks = 2 # add agents world.agents = [Agent() for _ in range(num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True if i < num_adversaries: agent.adversary = True else: agent.adversary = False self.change_entity_attribute(agent, **kwargs) # add landmarks world.landmarks = [Landmark() for _ in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False self.change_entity_attribute(landmark, **kwargs) # 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 = 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.size = 0.08 # 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 # 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.30 obstacle.boundary = False # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() #setting the world properties... world.dim_c=2 num_agents=2 world.num_agents = num_agents num_adversaries=1 num_landmarks=2 #adding the agents... #probability that agent is an enemy/ally prob_enemy=np.random.uniform(0,1) # TODO: use uniform 0-1 and pick a threshold between 0, 1 (done & confirmed) threshold = 0.5 world.agents = [Agent() for i in range(num_agents)] for i,agent in enumerate(world.agents): agent.name='agent %d' % i agent.collide = False # TODO: 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.max_speed = 1.0 if agent.adversary else 1.3 # agent either an ally or an enemy agent.ally= True if prob_enemy<threshold and i<num_agents else False agent.enemy=True if prob_enemy>=threshold and i<num_agents else False #adding the 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.2 #make landmark very big landmark.boundary = False #making the initial conditions... self.reset_world(world) return world
def make_world(self, nb_agents=4, nb_objects=1, obs_range=0.4, collision_pen=10.0, relative_coord=True, dist_reward=False): world = PushWorld(nb_objects) # add agent self.nb_agents = nb_agents world.agents = [Agent() for i in range(self.nb_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.silent = True agent.size = AGENT_SIZE agent.initial_mass = AGENT_MASS agent.color = np.array([0.5, 0.0, 0.0]) # Objects and landmarks self.nb_objects = nb_objects # Scenario attributes self.obs_range = obs_range self.relative_coord = relative_coord self.dist_reward = dist_reward # Reward attributes self.collision_pen = collision_pen # Flag for end of episode self._done_flag = 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 world.agents_num = self.num_agents num_landmarks = 0 # add agents world.agents = [Agent() for i in range(self.num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i ############## agent.index = i agent.collide = True agent.silent = True ########################## agent.adversary = True if i < self.num_adversaries else False agent.size = agent_size if agent.adversary else adver_size # agent.accel = 3.0 if agent.adversary else 4.0 agent.accel = 200.0 if agent.adversary else 250.0 agent.max_speed = agent_speed * 10 if agent.adversary else adver_speed * 10 #v = speed /10 # 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): world = World() # set any world properties first world.dim_c = 2 world.num_agents = args.num_agents world.num_landmarks = args.num_landmarks world.step_unknown = args.step_unknown world.unknown_decay = args.unknown_decay world.decay_episode = args.decay_episode world.critic_full_obs = args.critic_full_obs world.num_reset = 0 # add agents world.agents = [Agent() for i in range(world.num_agents)] for i, agent in enumerate(world.agents): agent.name = 'agent %d' % i agent.collide = True agent.silent = True agent.size = 0.15 # add landmarks world.landmarks = [Landmark() for i in range(world.num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False world.select_goal = np.random.randint(0, world.num_landmarks) world.agents[0].goal = world.landmarks[world.select_goal] # 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 = 0 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.collide = True agent.silent = True agent.size = 0.08 # add edges world.edges = [] for i in range(len(world.agents)): world.edges.append(1) # 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) return world
def make_world(self): 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 = 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.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 # 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 = 3 num_obstacles = 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 = size_agents # 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 = size_landmarks # add obstacles world.obstacles = [Landmark() for i in range(num_obstacles)] for i, landmark in enumerate(world.obstacles): landmark.name = 'obstacles %d' % i landmark.collide = True landmark.movable = False landmark.size = size_obstacles landmark.boundary = False world.landmarks += world.obstacles # 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 = 1 num_landmarks = 20 world.observing_range = 0.7 world.min_corridor = 0.06 world.collaborative = True # add agents world.agents = [Agent() for _ 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.03 # add landmarks world.landmarks = [Landmark() for _ in range(num_landmarks)] for i, landmark in enumerate(world.landmarks): landmark.name = 'landmark %d' % i landmark.collide = False landmark.movable = False landmark.size = np.random.uniform(0.1, 0.2) if i == (len(world.landmarks) - 1): landmark.size = 0.03 # make initial conditions self.reset_world(world) return world
def make_world(self): world = World() # set any world properties first world.dim_c = 3 num_landmarks = 5 world.collaborative = True # this will be the furthest any agent can move in any direction world.size = 5 # 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 agent.size = 0.075 # I think this is irrelevant? # speaker world.agents[0].movable = False # listener (discrete) world.agents[1].silent = True world.agents[1].hopper = True # 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.04 # I think this is irrelevant? # make initial conditions self.reset_world(world) return world
def make_world(self, n_agents=3, use_dense_rewards=False): world = World() world.use_dense_rewards = use_dense_rewards # set any world properties first num_agents = n_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.clip_positions = np.array([[-world.scale, -world.scale], [world.scale, world.scale]]) agent.is_colliding = { other_agent.name: False for other_agent in world.agents if agent is not other_agent } # 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 *= 3 # 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 = 5 num_adversaries = 3 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 if i < num_adversaries: agent.adversary = True else: agent.adversary = 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.collide = False landmark.movable = False # make initial conditions self.reset_world(world) return world
def make_world(self, size=6.0, n_preds=3, pred_vel=1.2, prey_vel=1.0, tax=0.1, discrete=True, partial=False, symmetric=False, action_penalty=0.0): world = World() # set any world properties world.n_steps = 500 world.torus = True world.dim_c = 2 world.size = size world.origin = np.array([world.size / 2, world.size / 2]) world.use_sensor_range = False world.partial = partial world.tax = tax world.symmetric = symmetric world.action_penalty = action_penalty print('world size = {}'.format(world.size)) print('pred vel = {}'.format(pred_vel)) print('prey vel = {}'.format(prey_vel)) print('tax = {}'.format(world.tax)) print('action penalty = {}'.format(world.action_penalty)) num_good_agents = 1 self.n_preds = num_adversaries = n_preds 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 {}'.format(i) agent.id = i agent.active = True agent.captured = False 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 = 20.0 if agent.adversary else 20.0 if agent.adversary: if isinstance(pred_vel, list): agent.max_speed = pred_vel[i] else: agent.max_speed = pred_vel else: agent.max_speed = prey_vel # discrete actions world.discrete_actions = discrete # 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 = 4 num_landmarks = 4 print("NUMBER OF AGENTS:", num_agents) print("NUMBER OF LANDMARKS:", num_landmarks) 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.size = 0.15 #was 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 # make initial conditions self.reset_world(world) return world
def make_world(self, mode=0): world = World() self.mode = mode # set any world properties first world.dim_c = 2 num_agents = 2 num_landmarks = 2 world.collaborative = True assert num_agents == 2, "This env is only for two agents" # 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 # 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) return world
def make_world(self, num_agents_inpt=2, num_adversaries_inpt=1): world = World() # set any world properties first world.dim_c = 2 num_agents = num_agents_inpt world.num_agents = num_agents_inpt num_adversaries = num_adversaries_inpt num_landmarks = num_agents - num_adversaries_inpt # 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.color = np.array([0.0, 0.0, 0.0]) if i < num_adversaries else np.array([1.0, 1.0, 0.0]) 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