def test_global_update(): nodes = [Node(x=0, y=0), Node(x=0, y=1), Node(x=1, y=1), Node(x=1, y=0)] graph = Graph(nodes) ant_colony = mock.Mock(min_distance=4) ant_colony.ants = [ mock.Mock( path=[0, 1, 2, 3], get_passes=lambda: [(1, 0), (2, 1), (3, 2), (3, 0)] ), mock.Mock(path=[0, 2, 3, 1]) ] graph.update_pheromones(ant_colony=ant_colony) assert graph.get_pheromone(3, 1) < graph.get_pheromone(2, 3)
def test_local_update(): nodes = [Node(x=0, y=0), Node(x=0, y=1), Node(x=1, y=1), Node(x=1, y=0)] graph = Graph(nodes) graph.local_update_pheromones([(3, 2), (2, 1), (1, 0), (3, 0)]) assert graph.get_pheromone(3, 1) == graph.min_pheromone assert graph.get_pheromone(2, 3) > graph.min_pheromone
def test_get_pheromone(): nodes = [Node(x=0, y=1), Node(x=1, y=0), Node(x=0, y=0)] graph = Graph(nodes) assert graph.get_pheromone(0, 1) == graph.min_pheromone