示例#1
0
 def custom_cmp(self, no_trgts, no_obs, obs_range):
     (no_targets, no_observers, no_obstacles, targets, observers, obstacles,
      observer_strategy) = self.initialize_custom(no_trgts, no_obs,
                                                  obs_range)
     t1 = deepcopy(targets)
     t2 = deepcopy(targets)
     t3 = deepcopy(targets)
     t4 = deepcopy(targets)
     o1 = deepcopy(observers)
     o2 = deepcopy(observers)
     o3 = deepcopy(observers)
     o4 = deepcopy(observers)
     ob1 = deepcopy(obstacles)
     ob2 = deepcopy(obstacles)
     ob3 = deepcopy(obstacles)
     ob4 = deepcopy(obstacles)
     tc = self.run(no_targets, no_observers, no_obstacles, targets,
                   observers, obstacles, observer_strategy)
     strategy1 = strat1()
     c1 = strategy1.run(no_targets, no_observers, no_obstacles, t1, o1, ob1)
     strategy2 = strat2()
     c2 = strategy2.run(no_targets, no_observers, no_obstacles, t1, o1, ob1)
     strategy3 = strat3()
     c3 = strategy3.run(no_targets, no_observers, no_obstacles, t1, o1, ob1)
     strategy4 = strat4()
     c4 = strategy4.run(no_targets, no_observers, no_obstacles, t1, o1, ob1)
     return [tc, c1, c2, c3, c4]
示例#2
0
    def run(self, no_targets, no_observers, no_obstacles, targets, observers,
            obstacles, observer_strategy):
        step = 0
        total_observed = 0
        s1 = strat1()
        s2 = strat2()
        s3 = strat3()
        s4 = strat4()
        while (step <= self.total_steps):
            if (step % self.update_steps == 0):
                for i in range(len(observers)):
                    if observer_strategy[i] == 1:
                        s1.run_obs(no_targets, no_obstacles, targets,
                                   obstacles, observers[i])
                    if observer_strategy[i] == 2:
                        s2.run_obs(no_targets, no_obstacles, targets,
                                   obstacles, observers[i])
                    if observer_strategy[i] == 3:
                        s3.run_obs(no_targets, no_obstacles, targets,
                                   obstacles, observers[i])
                    if observer_strategy[i] == 4:
                        s4.run_obs(no_targets, no_obstacles, targets,
                                   obstacles, observers[i])
                [target_observer_dict, target_obstacle_dict
                 ] = self.update_for_targets(observers, obstacles, targets)
                for i in target_observer_dict:
                    temp_arr_x = []
                    temp_arr_y = []
                    for j in target_observer_dict[i]:
                        temp_arr_x.append(observers[j].x)
                        temp_arr_y.append(observers[j].y)
                    if (len(temp_arr_x) and len(temp_arr_y)):
                        mean_x = mean(temp_arr_x)
                        mean_y = mean(temp_arr_y)
                        targets[i].update_target(self.x_limit, self.y_limit,
                                                 mean_x, mean_y)

            for i in observers:
                i.update(self.x_limit, self.y_limit)
            for i in targets:
                i.update(self.x_limit, self.y_limit)
            [observer_target_dict, observer_obstacle_dict
             ] = self.update_for_observers(observers, obstacles, targets)
            for i in observer_target_dict:
                total_observed += len(observer_target_dict[i])
            step += 1
        print("Heterogeneous strategy: ", total_observed)
        return total_observed
示例#3
0
    def run(self, no_targets, no_observers, no_obstacles, targets, observers,
            obstacles, observer_strategy):
        step = 0
        total_observed = 0
        s1 = strat1()
        s2 = strat2()
        s3 = strat3()
        s4 = strat4()
        while (step <= self.total_steps):
            if (step % self.update_steps == 0):
                for i in range(len(observers)):
                    # RUN FOR THE ONE WHICH WOULD YIELD BEST RESULTS NOW
                    d_obst = {}

                    targets_copy = deepcopy(targets)
                    obstacles_copy = deepcopy(obstacles)
                    o_copy1 = deepcopy(observers[i])
                    d_obst[s1.run_obs(no_targets, no_obstacles, targets_copy,
                                      obstacles_copy, o_copy1)] = 1

                    targets_copy = deepcopy(targets)
                    obstacles_copy = deepcopy(obstacles)
                    o_copy2 = deepcopy(observers[i])
                    d_obst[s2.run_obs(no_targets, no_obstacles, targets_copy,
                                      obstacles_copy, o_copy2)] = 2

                    targets_copy = deepcopy(targets)
                    obstacles_copy = deepcopy(obstacles)
                    o_copy3 = deepcopy(observers[i])
                    d_obst[s3.run_obs(no_targets, no_obstacles, targets_copy,
                                      obstacles_copy, o_copy3)] = 3

                    targets_copy = deepcopy(targets)
                    obstacles_copy = deepcopy(obstacles)
                    o_copy4 = deepcopy(observers[i])
                    d_obst[s4.run_obs(no_targets, no_obstacles, targets_copy,
                                      obstacles_copy, o_copy4)] = 4

                    m = max(d_obst)
                    m = d_obst[m]
                    xyz = [0, o_copy1, o_copy2, o_copy3, o_copy4]
                    observers[i] = deepcopy(xyz[m])
                [target_observer_dict, target_obstacle_dict
                 ] = self.update_for_targets(observers, obstacles, targets)
                for i in target_observer_dict:
                    temp_arr_x = []
                    temp_arr_y = []
                    for j in target_observer_dict[i]:
                        temp_arr_x.append(observers[j].x)
                        temp_arr_y.append(observers[j].y)
                    if (len(temp_arr_x) and len(temp_arr_y)):
                        mean_x = mean(temp_arr_x)
                        mean_y = mean(temp_arr_y)
                        targets[i].update_target(self.x_limit, self.y_limit,
                                                 mean_x, mean_y)

            for i in observers:
                i.update(self.x_limit, self.y_limit)
            for i in targets:
                i.update(self.x_limit, self.y_limit)
            [observer_target_dict, observer_obstacle_dict
             ] = self.update_for_observers(observers, obstacles, targets)
            for i in observer_target_dict:
                total_observed += len(observer_target_dict[i])
            step += 1
        print("Heterogeneous strategy: ", total_observed)
        return total_observed