def read_agent_state_for_analysis_file(
        file_path: str) -> typing.List[AgentAnalysisState]:
    #maybe have a type mapping for this
    try:
        with open(file_path) as f:
            reader = csv.reader(f)
            header = next(reader)
            return [
                AgentAnalysisState(Vector3r(row[0], row[1], row[2]),
                                   Vector3r(row[3], row[4],
                                            row[5]), *row[6:-1],
                                   list(row[-1].split('|'))) for row in reader
            ]
    except Exception as e:
        raise e
示例#2
0
 def find_sources(self, max_no_sources):
     '''
     Given an upper limit on the number of sources available in the agent's environment, executes a control loop to locate
     the sources, or return a given number of sources as found. This is not suitable for multi-agent simulations, where agents
     should coordinate across each timestep.
     '''
     self.max_no_sources = max_no_sources
     #the locations of sources of evidence that have already been successfully located
     self.located_sources = []
     while len(self.located_sources) < self.max_no_sources:
         next_source = self.find_source()
         #check if the source is deemed to not be present at all
         #if so, break the loop
         #This is bad practice - try and fix in future
         print("next_source: ", next_source)
         if next_source.grid_loc == Vector3r(-1, -1):
             break
         #given the next located source, append it to the list of located sources and then
         #modify the belief vector to set the probability of subsequent sources to be found at
         #the given location to be zero.
         self.located_sources.append(next_source)
         #
         self.current_belief_map.mark_source_as_located(
             next_source.grid_loc)
     #return the list of located sources to the user
     return self.located_sources
示例#3
0
def _generate_gaussian_prior(
        grid: UE4Grid,
        means: "list of 2 means",
        covariance_matrix: "2x2 covariance matrix",
        initial_belief_sum=0.5
) -> "Tuple(np.array normed prior probs, prior_dict":
    '''A method that returns the normed z vector as well as the prior dict. Given a 2d vector of means, 2X2 covariance matrix, returns a 2D gaussian prior'''
    #maybe should check all dimensions of data here
    prior = {}
    x, y = np.mgrid[0:grid.get_no_points_x() *
                    grid.get_lng_spacing():grid.get_lng_spacing(),
                    0:grid.get_no_points_y() *
                    grid.get_lat_spacing():grid.get_lat_spacing()]
    pos = np.empty(x.shape + (2, ))
    pos[:, :, 0] = x
    pos[:, :, 1] = y
    rv = multivariate_normal(means, covariance_matrix)
    z = rv.pdf(pos)
    normed_z = z * (initial_belief_sum / z.sum())

    #normed_z = normed_z.astype(float)
    #return likelihoods in dict with grid points
    for x_value in [_[0] for _ in x]:
        for y_value in y[0]:
            prior[Vector3r(x_value,
                           y_value)] = float(normed_z[x_value][y_value])

    #place prior into ordered numpy array
    list_of_grid_points = []
    for grid_loc in grid.get_grid_points():
        list_of_grid_points.append(prior[grid_loc])

    list_of_grid_points = np.array(list_of_grid_points)
    numpy_prior = np.append(list_of_grid_points, 1 - list_of_grid_points.sum())
    return numpy_prior
def parse_Vector3r_from_string(string):
    '''
    Given a string with Vector3rs, returns the Vector3r objects in a list in the order that they appeared in the string
    '''
    return [
        Vector3r(int(_.split(',')[0]), int(_.split(',')[1]))
        for _ in re.findall("Vector3r\(([0-9]+ ?, ?[0-9]+)\)", string)
    ]
示例#5
0
 def create_grid_with_no_points(self):
     '''Assuming it's known how many points are desired in x and y direction, 
     creates the grid rooted at the origin'''
     #x,y = np.meshgrid([i for i in range(10)], [i for i in range(10)], indexing = 'xy')
     self.grid = []
     backtrack = False
     for x_counter in range(self.no_x):
         if backtrack:
             for y_counter in range(self.no_y):
                 self.grid.append(self.origin +
                                  Vector3r(x_counter *
                                           self.lng_spacing, y_counter *
                                           self.lat_spacing))
             backtrack = not backtrack
         else:
             for y_counter in range(self.no_y - 1, -1, -1):
                 self.grid.append(self.origin +
                                  Vector3r(x_counter *
                                           self.lng_spacing, y_counter *
                                           self.lat_spacing))
             backtrack = not backtrack
    def get_observations_from(self, other_agent_name, timestep = None):
        '''
        Returns a list of agent observations from another agent given the other agents name.
        '''
        #print("making get request to: ", self.create_request_url(other_agent_name, timestamp))
        response_json = requests.get(self.create_request_url(other_agent_name, timestep)).json()
        return_observations = []
        for row in response_json[1:]:            
            row = row.split(',')
#            try:
            return_observations.append(AgentObservation(Vector3r(row[1], row[0], row[2]), *row[3:]))
#           except Exception as e:
#                print("found an exception: ", row)
        return return_observations
示例#7
0
def get_agent_observations_from_file(
        file_path: str) -> typing.List[AgentObservation]:
    '''Reads agent observations from a file and returns a list of agent observation objects'''
    #maybe have a type mapping for this
    try:
        with open(file_path) as f:
            reader = csv.reader(f)
            header = next(reader)
            return [
                AgentObservation(Vector3r(row[1], row[0], row[2]), *row[3:])
                for row in reader
            ]
    except Exception as e:
        return []
 def read_all_observations_from_file(self):
     '''
     Returns all observations from file associated with agent as AgentObservations 
     '''
     try:
         self.file_handle.seek(0)
         reader = csv.reader(self.file_handle)
         #header = next(reader)
         #read the header and then throw it away
         next(reader)
         #reset the file handle to it's start position for reading again
         return [
             AgentObservation(Vector3r(row[1], row[0], row[2]), *row[3:])
             for row in reader
         ]
     #not sure how this could be handled for now
     except Exception as e:
         raise e
        return_CI_map.update_from_observations(
            self.get_observation_set(agent_name))

    def get_continuous_belief_map_from_observations(self, grid_bounds):
        '''Given grid bounds, returns a function which returns the likelihood given the 
        continuous position of the RAV. I.E. transform the discrete PDF as above to a 
        continuous one.'''
        pass


#%%

#%%
if __name__ == "__main__":

    test_grid = UE4Grid(1, 1, Vector3r(0, 0), 6, 5)

    test_ObservationSetManager = ObservationSetManager('agent1')
    test_ObservationSetManager.observation_sets

    obs1 = AgentObservation(Vector3r(0, 0), 0.5, 1, 1234, 'agent2')
    obs2 = AgentObservation(Vector3r(0, 0), 0.7, 2, 1235, 'agent2')
    obs3 = AgentObservation(Vector3r(0, 1), 0.95, 3, 1237, 'agent2')
    obs4 = AgentObservation(Vector3r(0, 1), 0.9, 3, 1238, 'agent1')

    test_ObservationSetManager.init_rav_observation_set(
        'agent2', set([obs1, obs2]))
    assert test_ObservationSetManager.get_observation_set('agent2') == set(
        [obs1, obs2])

    test_ObservationSetManager.observation_sets
    try:
        with open(file_path) as f:
            reader = csv.reader(f)
            header = next(reader)
            return [
                AgentAnalysisState(Vector3r(row[0], row[1], row[2]),
                                   Vector3r(row[3], row[4],
                                            row[5]), *row[6:-1],
                                   list(row[-1].split('|'))) for row in reader
            ]
    except Exception as e:
        raise e


if __name__ == "__main__":
    testAgentAnalysisState1 = AgentAnalysisState(Vector3r(10, 20, 30),
                                                 Vector3r(40, 50,
                                                          60), 2, 1.1252,
                                                 'rav_name', 3.1, 2.8, 2.8,
                                                 2.6, ['drone1', 'drone2'])
    testAgentAnalysisState2 = AgentAnalysisState(Vector3r(70, 20, 12),
                                                 Vector3r(12.5, 50, 60.2), 2,
                                                 1.1252, 'rav_name', 3.1, 2.8,
                                                 2.8, 2.1, ['drone1'])
    testAgentAnalysisState3 = AgentAnalysisState(
        Vector3r(0.0, 15.0, 0.0),
        Vector3r(25.0036563873291, -2.3688066005706787,
                 -11.998088836669922), 0, 1542291931.2268043, "Drone2", 15.0,
        0.9784099446151149, 0.02159005538488512, 0.0111930622, ['Drone1'])

    testAgentAnalysisState1._asdict()
    def can_coord_with_other(self, other_rav_name, range_m):
        '''
        Defines the probability with which the current agent can successfully 
        coordinate with other agent as a function of distance
        '''
        #check if any other ravs in comm radius. if so, return which ravs can be communicated with
        #assume communcications randomly drop with probability in proportion to range_m
        #for now 10% communication. This should probably go in a config file
        return random.random() < 0.1


#%%

if __name__ == "__main__":
    from Utils.ClientMock import KinematicsState, MockRavForTesting, ImageType, Vector3r
    grid = UE4Grid(15, 20, Vector3r(0, 0), 60, 45)
    #grid, move_from_bel_map_callable, height, epsilon, multirotor_client, agent_name, performance_csv_path: "file path that agent can write performance to", prior = []
    #grid, initial_pos, move_from_bel_map_callable, height, epsilon, multirotor_client, agent_name, prior = {}
    occupancy_grid_agent = BaseGridAgent(
        grid, Vector3r(0, 0), get_move_from_belief_map_epsilon_greedy, -12,
        0.2, MockRavForTesting(), 'agent1')
    #write some tests for agent here
    occupancy_grid_agent.current_pos_intended = Vector3r(0, 0)
    occupancy_grid_agent.current_pos_measured = None
    occupancy_grid_agent.current_reading = 0.1
    occupancy_grid_agent.get_agent_state_for_analysis()
    occupancy_grid_agent.explore_timestep()

    #belief_map: BeliefMap, current_grid_loc: Vector3r, epsilon: float, eff_radius = None) -> Vector3r:
    dont_move = lambda belief_map, current_grid_loc, epsilon: Vector3r(15, 20)
    print(grid.get_grid_points())
    '''Try and replicate results of Coordinated Search with a Swarm of UAVs'''
    #grid = UE4Grid(10, 10, Vector3r(0,0), 90, 90)
    pass


if __name__ == "__main__":
    #args = parse_args(sys.argv[1:])
    #agent_name = args.agent_name
    #print('args: ',args)
    t1 = time.time()
    agent1_name = 'agent1'
    agent2_name = 'agent2'
    agent3_name = 'agent3'

    #x then y
    grid = UE4Grid(1, 1, Vector3r(0, 0), 10, 10)
    means = [1, 3]
    covariance_matrix = [[7.0, 0], [0, 15]]
    prior = generate_gaussian_prior(grid,
                                    means,
                                    covariance_matrix,
                                    initial_belief_sum=0.5)
    source_location = Vector3r(4, 3)
    agent_start_pos = Vector3r(5, 8)
    saccadic_selection_method = SaccadicActionSelection(grid)

    alpha = 0.2
    beta = 0.1
    cb_single_source_sensor = SingleSourceSensor(alpha, beta, source_location)

    #agent_name: str, grid: UE4Grid, belief_map_components: typing.List[BeliefMapComponent], prior: typing.Dict[Vector3r, float], alpha: 'prob of false pos', beta: 'prob of false neg', apply_blur = False):
示例#13
0
    '''Try and replicate results of Coordinated Search with a Swarm of UAVs'''
    #grid = UE4Grid(10, 10, Vector3r(0,0), 90, 90)
    pass


if __name__ == "__main__":
    #args = parse_args(sys.argv[1:])
    #agent_name = args.agent_name
    #print('args: ',args)
    t1 = time.time()
    agent1_name = 'agent1'
    agent2_name = 'agent2'
    agent3_name = 'agent3'

    #x then y
    grid = UE4Grid(1, 1, Vector3r(0, 0), 10, 8)
    means = [18, 16]
    covariance_matrix = [[7.0, 0], [0, 3]]
    prior = generate_gaussian_prior(grid,
                                    means,
                                    covariance_matrix,
                                    initial_belief_sum=0.5)
    prior = generate_uniform_prior(grid)

    source_locations = [Vector3r(1, 1), Vector3r(5, 6), Vector3r(10, 6)]
    agent_start_pos = Vector3r(10, 8)
    saccadic_selection_method = SaccadicActionSelection(grid)
    #nearest_neighbor_selection = GreedyActionSelection(eff_radius = min([grid.lat_spacing, grid.lng_spacing]))
    sweep_action_selection_method = TSPActionSelection(grid, agent_start_pos)
    #epsilon_greedy_action_selection_method  = EpsilonGreedyActionSelection(0.2, eff_radius = 4 * min([grid.lat_spacing, grid.lng_spacing]))
示例#14
0
    #plt.xlim(0,2200)

    plt.figure()
    plt.plot([i**2 for i in range(100, 2200, 100)], sizes)
    plt.title("Average size in bytes taken to update vs. grid size")
    #plt.xlim(0, 2200)


#%%
if __name__ == '__main__':
    #%%
    from Utils.UE4Grid import UE4Grid
    from Utils.Vector3r import Vector3r
    fpr = 0.1
    fnr = 0.2
    test_grid = UE4Grid(1, 1, Vector3r(0.0), 20, 20)

    initial_state = [0.008 for i in range(len(test_grid.get_grid_points()))]
    initial_state.append(1 - sum(initial_state))
    initial_state = initial_state * np.identity(len(initial_state))
    fpr_matrix = fpr * np.identity(len(initial_state))
    fnr_matrix = fnr * np.identity(len(initial_state))
    identity = np.identity(len(initial_state))
    b0 = fnr_matrix
    a0 = identity - fpr_matrix
    b1 = identity - fnr_matrix
    a1 = fpr_matrix
    #%%
    update_fns = gen_next_estimated_state_functions(initial_state.shape[0], a1,
                                                    b1, a0, b0)
    #%%
            
def run_coordinate_search_with_swarm_UAVs():
    '''Try and replicate results of Coordinated Search with a Swarm of UAVs'''
    #grid = UE4Grid(10, 10, Vector3r(0,0), 90, 90)
    pass


if __name__ == "__main__":
    #args = parse_args(sys.argv[1:])
    #agent_name = args.agent_name
    #print('args: ',args) 
    t1 = time.time()
    agent1_name = 'agent1'
     
    #x then y
    grid = UE4Grid(1, 1, Vector3r(0,0), 3, 3)    
    #means = [1,3]
    #covariance_matrix = [[7.0, 0], [0, 15]]
    #prior = generate_gaussian_prior(grid, means, covariance_matrix, initial_belief_sum = 0.5)
    prior = generate_uniform_prior(grid)
    
    
    source_location = Vector3r(2,2)
    agent_start_pos = Vector3r(5,8)
    saccadic_selection_method = SaccadicActionSelection(grid)
    nearest_neighbor_selection = GreedyActionSelection(eff_radius = min([grid.lat_spacing, grid.lng_spacing]))

    #alpha is the "false alarm" rate (of false positive)
    alpha = 0.2
    #beta is the "missed detection" rate (or false negative)
    beta = 0.25
示例#16
0
#    plt.savefig(file_path)


def is_valid_initial_dist(no_grid_points, initial_dist):
    '''Verifies that the specified initial distribution over a grid is valid. It's assumed that the initial distribution
    represents the probability of evidence being located at a particular grid location.'''
    return math.isclose(
        initial_dist.sum(), 1,
        rel_tol=0.0000001) and len(initial_dist) == no_grid_points + 1


#%%
if __name__ == '__main__':
    #%%

    grid = UE4Grid(1, 1, Vector3r(0, 0), 10, 10)
    grid.get_grid_points()
    means = [1, 3]
    covariance_matrix = [[7.0, 0], [0, 15]]
    initial_belief_sum = 0.5
    gaussian_prior = _generate_gaussian_prior(grid, means, covariance_matrix,
                                              initial_belief_sum)
    assert is_valid_initial_dist(grid.get_no_grid_points(), gaussian_prior)

    prior = generate_gaussian_prior(grid,
                                    means,
                                    covariance_matrix,
                                    initial_belief_sum=0.5)
    assert 0.49 < prior[:-1].sum() < 0.51

    #%%
def main():
    #args = parse_args(sys.argv[1:])
    #agent_name = args.agent_name
    #print('args: ',args)
    #%%
    t1 = time.time()
    agent1_name = 'agent1'
    #    agent2_name = 'agent2'
    #    agent3_name = 'agent3'

    #%%
    #x then y
    grid = get_grid_from_config()
    means = [18, 16]
    covariance_matrix = [[7.0, 0], [0, 3]]
    gaussian_initial = generate_gaussian_prior(grid,
                                               means,
                                               covariance_matrix,
                                               initial_belief_sum=0.5)
    uniform_initial = generate_uniform_prior(grid)

    source_locations = get_source_locations_from_config()
    assert all([
        source_location in grid.get_grid_points()
        for source_location in source_locations
    ])
    agent1_start_pos = get_agent_start_pos_from_config(1)

    saccadic_selection_method = SaccadicActionSelection(grid)
    nearest_neighbor_selection = GreedyActionSelection(
        eff_radius=min([grid.lat_spacing, grid.lng_spacing]))
    if len(grid.get_grid_points()) < 200:
        #this takes a long time to initialize if too many grid points are present
        sweep_action_selection_method = TSPActionSelection(
            grid, agent1_start_pos)
    epsilon_greedy_action_selection_method = EpsilonGreedyActionSelection(
        0.2, eff_radius=4 * min([grid.lat_spacing, grid.lng_spacing]))

    agent1_simulated_sensor = get_simulated_sensor_from_config(1)

    agent1_sensor_model_fpr, agent1_sensor_model_fnr = get_sensor_model_params_from_config(
        1).false_positive_rate, get_sensor_model_params_from_config(
            1).false_negative_rate
    #    grid, initial_pos, move_from_bel_map_callable, height, agent_name, occupancy_sensor_simulator, belief_map_class, search_terminator, other_active_agents = [], prior = {}, comms_radius = 1000, logged = True)
    #estimated_state_map = create_multiple_source_binary_belief_map(grid, uniform_initial, agent1_sensor_model_fpr, agent1_sensor_model_fnr)

    agent1_initial_belief_map = MultipleSourceBinaryBeliefMap(
        grid, uniform_initial, agent1_sensor_model_fpr,
        agent1_sensor_model_fnr)
    #prior_belief_present, probability_of_falsely_rejecting_source_is_present_given_source_is_present:"p(type 1 error)", probability_of_falsely_accepting_source_is_present_given_source_is_not_present:"p(type 2 error)"
    agent1_initial_belief_map.get_probability_source_in_grid()
    agent1_initial_belief_map.current_belief_vector.get_estimated_state()
    search_terminator = SequentialProbRatioTest(
        agent1_initial_belief_map.get_probability_source_in_grid(),
        *get_SPRT_params_from_config(1))

    #%%

    #grid, initial_pos, move_from_bel_map_callable, height, agent_name, occupancy_sensor_simulator, battery_capacity_simulator, belief_map_class, init_belief_map, search_terminator, other_active_agents = [], comms_radius = 1000, logged = True, no_battery_levels = 11, charging_locations = None
    battery_simulator = RAVBatterySimulator(1)
    charging_locations = [Vector3r(0, 0)]
    assert all([
        charging_location in grid.get_grid_points()
        for charging_location in charging_locations
    ])

    agent1 = MultipleSourceDetectingGridAgentWithBattery(
        grid,
        agent1_start_pos,
        epsilon_greedy_action_selection_method.get_move,
        -10,
        agent1_name,
        agent1_simulated_sensor,
        battery_simulator,
        MultipleSourceBinaryBeliefMap,
        agent1_initial_belief_map,
        search_terminator,
        other_active_agents=[],
        comms_radius=2,
        logged=False,
        no_battery_levels=11,
        charging_locations=charging_locations)
    t1 = time.time()
    located_sources = agent1.find_sources(3)
    t2 = time.time()
    print("\n\nSeach took {} seconds.".format(t2 - t1))
    print("\nAgent 1 has terminated the search after {} timesteps".format(
        agent1.timestep))
    print("The sources were at locations {}".format(source_locations))
    print("The agent detected the following locations: {}".format(
        located_sources))
    #print("\nAgent1 state: \n", agent1.current_belief_map.current_belief_vector.get_estimated_state())
    sys.exit(0)

    #run_t_timesteps([agent1, agent2], 60)

    #agent3.current_belief_map.save_visualisation("D:\\ReinforcementLearning\\DetectSourceAgent\\Visualisations\\Agent3BelMapPrior.png")

    max_timesteps = get_max_simulation_steps_from_config()
    print("Running with max {} timesteps".format(max_timesteps))
    no_timesteps_to_discovery = run_t_timesteps([agent3], max_timesteps,
                                                threshold)
    no_timesteps_to_discovery = max_timesteps if not no_timesteps_to_discovery else no_timesteps_to_discovery

    print("\n\nSaving visualisations")
示例#18
0
        with open(file_path) as f:
            reader = csv.reader(f)
            header = next(reader)
            return [
                AgentObservation(Vector3r(row[1], row[0], row[2]), *row[3:])
                for row in reader
            ]
    except Exception as e:
        return []


#%%
if __name__ == "__main__":

    #%%
    test_grid = UE4Grid(1, 1, Vector3r(0, 0), 10, 6)
    test_agent_observations = AgentObservations(test_grid)

    obs1 = AgentObservation(Vector3r(0, 0), 0.5, 1, 1234, 'agent1')
    obs2 = AgentObservation(Vector3r(0, 0), 0.7, 2, 1235, 'agent1')
    obs3 = AgentObservation(Vector3r(0, 1), 0.9, 3, 1237, 'agent1')
    obs4 = AgentObservation(Vector3r(0, 0), 0.7, 2, 1235, 'agent1')

    obs5 = AgentObservation(Vector3r(1.0, 2, 0), 0.4, 1, 1234, 'agent1')

    #%%
    assert obs5.grid_loc == Vector3r(1, 2, 0)

    #check eq method of agent observation
    assert not obs1.__eq__(obs2)
    assert obs2.__eq__(obs4)
示例#19
0
    fnr = 0.25
    binary_sensor_parameter = BinarySensorParameters(fpr, fnr)
    try:
        BinarySensorParameters(2, 3)
        assert False
    except Exception as e:
        assert True

    try:
        BinarySensorParameters(fpr, 0.6)
        assert False
    except Warning as e:
        assert True

#%%
    source_locations = [Vector3r(2, 2)]
    cb_sensor = FalsePosFalseNegBinarySensorSimulator(binary_sensor_parameter,
                                                      source_locations)
    no_samples = 100000
    #check fpr
    assert math.isclose(sum(
        [cb_sensor.get_reading(Vector3r(0, 0)) for i in range(no_samples)]),
                        no_samples * fpr,
                        rel_tol=0.01)
    #check fnr
    assert math.isclose(sum([
        1 - cb_sensor.get_reading(source_locations[0])
        for i in range(no_samples)
    ]),
                        no_samples * (fnr),
                        rel_tol=0.01)
示例#20
0
            for radiation_loc in radiation_locs
        ]
        #returns true if within 0.5 m
        return 1 if sum(strengths) / 800 > 0.95 else (
            (sum(strengths) / 800 + 0.1) * 0.9) + random.gauss(0, 0.005)

    def get_sensor_reading(self):
        return self.rad_model(self.current_pos_intended,
                              self.sources_locations)


#%%

if __name__ == "__main__":
    #%%
    test_grid = UE4Grid(2, 1, Vector3r(0, 0), 10, 6)

    assert test_grid.get_no_points_x() == 6
    assert test_grid.get_no_points_y() == 7

    assert test_grid.get_lat_spacing() == 1
    assert test_grid.get_lng_spacing() == 2

    assert len(test_grid.get_grid_points()
               ) == test_grid.get_no_points_x() * test_grid.get_no_points_y()

    test_grid1 = UE4Grid(1, 1, Vector3r(0, 0), 9, 13)
    assert len(test_grid1.get_grid_points(
    )) == test_grid1.get_no_points_x() * test_grid1.get_no_points_y()

    assert set(test_grid1.get_neighbors(Vector3r(2, 2), 1.9)) == set([
示例#21
0
    '''Try and replicate results of Coordinated Search with a Swarm of UAVs'''
    pass


if __name__ == "__main__":
    #args = parse_args(sys.argv[1:])
    #agent_name = args.agent_name
    #print('args: ',args)
    t1 = time.time()
    agent1_name = 'agent1'
    agent2_name = 'agent2'
    agent3_name = 'agent3'

    #hard code grid for now
    #x then y
    grid = UE4Grid(10, 15, Vector3r(0, 0), 180, 150)

    sources_locations = [Vector3r(140,
                                  150)]  #[Vector3r(25,120),Vector3r(140,15)]
    rad_model = RadModel(sources_locations, grid, 50000)
    #within 8m gives 100% reading
    rad_sensor = RadSensor(rad_model, 10)
    #rad_model.plot_falloff("D:\\ReinforcementLearning\\DetectSourceAgent\\Visualisations\\RadFalloff.png")
    #rad_sensor.plot_falloff("D:\\ReinforcementLearning\\DetectSourceAgent\\Visualisations\\RadSensorFalloff.png")

    #    agent1 = SimpleGridAgentWithSources(grid, Vector3r(20,0), get_move_from_belief_map_epsilon_greedy, -10, 0.1, agent1_name, [Vector3r(80, 120)], other_active_agents = ['agent2'], comms_radius = 2, prior = {grid_loc:0.3 for grid_loc in grid.get_grid_points()})
    #   agent2 = SimpleGridAgentWithSources(grid, Vector3r(40,135), get_move_from_belief_map_epsilon_greedy, -10, 0.1, agent2_name, [Vector3r(80,120)], other_active_agents = ['agent1'], comms_radius = 2, prior = {grid_loc:0.3 for grid_loc in grid.get_grid_points()})

    epsilon = 0.05

    agent_start_pos = Vector3r(30, 60)
示例#22
0
        return return_move
    
    def move_utility(self, belief_map, expected_battery_value, current_grid_loc, next_grid_loc):
        '''
        Returns the utilitiy function associated with moving from current_grid_loc to next_grid_loc
        with the current expected_battery_value and belief_map
        '''
        pass
    
    def get_move(self, belief_map, current_grid_loc: Vector3r, explored_grid_locs: 'list of Vector3r') -> (bool, Vector3r):
        return self.get_move_from_belief_map_epsilon_greedy(belief_map, current_grid_loc, self.epsilon, self.eff_radius)

#%%
if __name__ == "__main__":

    test_grid = UE4Grid(1, 1, Vector3r(0,0), 6, 5)

    tsp = TSPActionSelection(test_grid, Vector3r(0,3))
        
    print(tsp.get_moves())

    
    obs1 = AgentObservation(Vector3r(0,0),0.5, 1, 1234, 'agent2')
    obs2 = AgentObservation(Vector3r(0,0),0.7, 2, 1235, 'agent2')
    obs3 = AgentObservation(Vector3r(0,1),0.95, 3, 1237, 'agent2')
    #(grid, agent_name, prior = {})
    obs_man = ObservationSetManager("agent1")
    obs_man.update_rav_obs_set('agent2', [obs1, obs2, obs3])
    belief_map = obs_man.get_discrete_belief_map_from_observations(test_grid)
    
    epsilon_greedy = EpsilonGreedyActionSelection(0.0, 1.8)

def get_SPRT_params_from_config(agent_number):
    '''
    Returns the type1 and type2 probabilities of error
    '''
    agent_parser = get_agent_config(agent_number)
    return (float(agent_parser['SPRTParameters']['Type1ErrorProb']),
            float(agent_parser['SPRTParameters']['Type2ErrorProb']))


def get_ffmpeg_file_loc():
    env_parser = get_env_config()
    return env_parser["FileLocations"]["FFMPEGBinaryLocation"]


#%%
if __name__ == '__main__':
    #%%
    assert parse_Vector3r_from_string(" Vector3r(0,0) ") == [Vector3r(0, 0)]
    assert parse_Vector3r_from_string(" Vector3r(0,0) Vector3r(5,6)") == [
        Vector3r(0, 0), Vector3r(5, 6)
    ]

    get_simulated_sensor_from_config(1)
    get_grid_from_config()
    get_agent_start_pos_from_config(1)
    get_source_locations_from_config()
    get_max_simulation_steps_from_config()
    get_sensor_model_params_from_config(1)