Пример #1
0
 def test_prepare_for_painting_and_regions(self):
     file = WorldMap.open_map(file_map_9)
     my_map = WorldMap(None, map_file=file)
     my_map.regions = [[(4, 4), (10, 4)], [(3, 4), (7, 4)]]
     my_map.prepare_for_painting()
     self.assertEqual(my_map.neighbors,
                      {1: [2, 5, 7], 2: [3, 1, 5], 3: [2, 4, 5], 4: [3, 6],
                       5: [3, 1, 6, 2, 7], 6: [4, 5, 8], 7: [5, 1, 8],
                       8: [6, 7]})
     self.assertEqual(my_map.countries, 8)
     used_colors_optimal = max(
         painter.graph_coloring_optimal(my_map.neighbors).values())
     used_colors_appromeximate = max(
         painter.graph_coloring_approximate(my_map.neighbors).values())
     self.assertEqual(3, used_colors_optimal)
     self.assertEqual(used_colors_optimal <= used_colors_appromeximate,
                      True)
Пример #2
0
        result[1] = 1
    else:
        sorted_edges = sort_edges(graph)
        coloring()
    return result


def paint_map(my_map, optimal):
    my_map.prepare_for_painting()
    if optimal:
        return graph_coloring_optimal(my_map.neighbors)
    return graph_coloring_approximate(my_map.neighbors)


def main(filename):z
    import os
    filepath = os.path.abspath(os.path.join(
        os.path.dirname(__file__), "..", filename))
    file = WorldMap.open_map(filepath)
    my_map = WorldMap(None, map_file=file)
    my_map.prepare_for_painting()
    print(my_map)
    print()
    print('Countries count:', my_map.countries)
    print('Optimal algorithm result:', paint_map(my_map, True))
    print('Approximate algorithm result:', paint_map(my_map, False))


if __name__ == "__main__":
    main("MapEditor/maps/map.txt")