def perform(self): whole_path = [] pheromone_map = PheromoneMap(n_rows=self.map_size[0], n_cols=self.map_size[1]) colony = Colony(pos=self.agent_pos, pheromone_map=pheromone_map, size=self.colony_size) path, n_iter, satisfies_accuracy = colony.find_target( self.load_pos, proximity_to_standard=self.proximity_to_standard, iter_max=self.iter_max) whole_path = path if path is None or not satisfies_accuracy: return None pheromone_map = PheromoneMap(n_rows=self.map_size[0], n_cols=self.map_size[1]) colony = Colony(pos=self.load_pos, pheromone_map=pheromone_map, size=self.colony_size) path, n_iter, satisfies_accuracy = colony.find_target( self.destination_pos, proximity_to_standard=self.proximity_to_standard, iter_max=self.iter_max) if path is None or not satisfies_accuracy: return None whole_path += path return whole_path
from colony import Colony from pheromone_map import PheromoneMap from window import Window import time if __name__ == '__main__': pheromone_map = PheromoneMap(n_rows=40, n_cols=40) colony = Colony(pos=(0, 0), pheromone_map=pheromone_map, size=1) start = time.time() path, n_iter, satisfies_accuracy = colony.find_target((20, 20), proximity_to_standard=0.6) end = time.time() time_diff = end - start print(time_diff) window = Window(greed_size=(40, 40)) window.visualize_path_search(colony_pos=(0, 0), target_pos=(20, 20), path=path) window.run()