Пример #1
0
    def test_paint_map(self):
        file = WorldMap.open_map(file_map_9)
        my_map = WorldMap(None, map_file=file)

        optimal = painter.paint_map(my_map, True)
        optimal_algo = painter.graph_coloring_optimal(my_map.neighbors)
        self.assertEqual(optimal, optimal_algo)

        appromeximate = painter.paint_map(my_map, False)
        appromeximate_algo = painter.graph_coloring_approximate(
            my_map.neighbors)
        self.assertEqual(appromeximate, appromeximate_algo)
Пример #2
0
    def create_map_widget(self):
        try:
            if self.params_dialog.file:
                current_map = WorldMap(None, map_file=self.params_dialog.file)
            else:
                current_map = WorldMap(self.params_dialog.settings)

            self.mapWidget = MapWidget(current_map)
            self.layout.addWidget(self.mapWidget, 1, 0)

            self.update_window()
        except Exception as e:
            print(e)
Пример #3
0
 def open_map(self):
     directory = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'maps'))
     openfile = QtWidgets.QFileDialog.getOpenFileName(
         self, "Open File", directory, "Text files(*.txt)")[0]
     self.file = WorldMap.open_map(openfile)
     self.ok_button.setEnabled(True)
Пример #4
0
    def assert_algorithms(self, map_file, expected_result):
        my_map = WorldMap(None, map_file=map_file)
        used_colors_optimal, used_colors_appromeximate = prepare_for_algs(
            my_map)

        self.assertEqual(expected_result, used_colors_optimal)
        self.assertEqual(used_colors_optimal <= used_colors_appromeximate,
                         True)
Пример #5
0
    def test_find_neighbors(self):
        my_map = WorldMap(None, map_file=self.map_6)
        my_map.find_countries()
        my_map.find_neighbors()

        self.assertEqual({1: [2, 4], 2: [1, 3, 5], 3: [2, 6], 4: [1, 5],
                             5: [2, 4, 6], 6: [3, 5]}, my_map.neighbors)
Пример #6
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)
Пример #7
0
 def test_index_and_len(self):
     self.one_country_map = WorldMap.open_map(file_one_country_map)
     my_map = WorldMap(None, map_file=self.one_country_map)
     self.assertEqual(my_map[1][1], -1)
     self.assertEqual(len(my_map), 9)
Пример #8
0
    def test_find_neighbors(self):
        my_map = WorldMap(None, map_file=self.no_countries_map)
        my_map.find_countries()
        my_map.find_neighbors()

        self.assertEqual({}, my_map.neighbors)
Пример #9
0
 def test_find_countries(self):
     my_map = WorldMap(None, map_file=self.no_countries_map)
     my_map.find_countries()
     self.assertEqual(0, my_map.countries)
Пример #10
0
 def setUp(self):
     self.no_countries_map = WorldMap.open_map(file_no_countries_map)
Пример #11
0
 def setUp(self):
     self.one_country_map = WorldMap.open_map(file_one_country_map)
Пример #12
0
 def setUp(self):
     self.map_6 = WorldMap.open_map(file_map_6)
Пример #13
0
 def test_find_neighbors(self):
     my_map = WorldMap(None, map_file=self.map_4)
     my_map.find_countries()
     my_map.find_neighbors()
     self.assertEqual({1: [2, 3], 2: [1, 4], 3: [1, 4], 4: [2, 3]},
                      my_map.neighbors)
Пример #14
0
 def test_algorithms_on_no_countries_map(self):
     my_map = WorldMap.open_map(file_no_countries_map)
     self.assert_algorithms(my_map, 1)
Пример #15
0
 def test_algorithms_on_map_6(self):
     my_map = WorldMap.open_map(file_map_6)
     self.assert_algorithms(my_map, 2)
Пример #16
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")