Example #1
0
 def test_order_computation(
         self):  # TODO: to a testclass of basicpermutations
     g = Graph(directed=False, n=6, name='g')
     h = Graph(directed=False, n=6, name='h')
     vg_0, vg_1, vg_2, vg_3, vg_4, vg_5 = g.vertices
     vh_0, vh_1, vh_2, vh_3, vh_4, vh_5 = h.vertices
     # mapping only to itself
     coloring_p = Coloring()
     coloring_p.add([vg_0, vh_0])
     coloring_p.add([vg_1, vh_1])
     p = Permutation(len(g.vertices), coloring=coloring_p)
     H = [p]
     self.assertEqual(1, order_computation(H))
     # mapping to itself and 1 other node
     coloring_p = Coloring()
     coloring_p.add([vg_0, vh_1])
     coloring_p.add([vg_1, vh_0])
     p = Permutation(len(g.vertices), coloring=coloring_p)
     H = [p]
     self.assertEqual(2, order_computation(H))
     # this is the permutation example of the lecture
     coloring_p = Coloring()
     coloring_p.add([vg_0, vh_1])
     coloring_p.add([vg_1, vh_2])
     coloring_p.add([vg_2, vh_0])
     coloring_p.add([vg_4, vh_5])
     coloring_p.add([vg_5, vh_4])
     p = Permutation(6, coloring=coloring_p)
     coloring_q = Coloring()
     coloring_q.add([vg_2, vh_3])
     coloring_q.add([vg_3, vh_2])
     q = Permutation(6, coloring=coloring_q)
     H = [p, q]
     self.assertEqual(48, order_computation(H))
def getStartingPopulation(populationSize, graph):
    solutions = []
    for i in range(populationSize):
        solutions.append(Coloring(graph))
        startingPoint = random.randint(0, graph.numVertices - 1)
        #Greedly color the graph starting at a random point
        solutions[i].colorGreedy(startingPoint)
        solutions[i].restrictedColors
    return solutions
Example #3
0
    def test_permutation_coloring(self):
        g = Graph(directed=False, n=5)
        h = Graph(directed=False, n=5)
        vg_0, vg_1, vg_2, vg_3, vg_4 = g.vertices
        vh_0, vh_1, vh_2, vh_3, vh_4 = h.vertices

        coloring_p = Coloring()
        p = Permutation(0, coloring=coloring_p, g=g)
        self.assertEqual(0, len(p))

        coloring_p.add([vg_0, vh_0])
        coloring_p.add([vg_1, vh_1])
        p = Permutation(2, coloring=coloring_p, g=g)
        self.assertEqual(0, p.P[0])
        self.assertEqual(1, p.P[1])

        coloring_p = Coloring()
        coloring_p.add([vg_0, vh_1])
        coloring_p.add([vg_1, vh_0])
        p = Permutation(2, coloring=coloring_p, g=g)
        self.assertEqual(1, p.P[0])
        self.assertEqual(0, p.P[1])

        # TODO: deze test gaat nog mis...
        coloring_p = Coloring()
        coloring_p.add([vg_0, vh_1])
        coloring_p.add([vg_1, vh_2])
        coloring_p.add([vg_2, vh_3])
        coloring_p.add([vg_3, vh_4])
        coloring_p.add([vg_4, vh_0])

        p = Permutation(5, coloring=coloring_p, g=g)
        self.assertEqual(1, p.P[0])
        self.assertEqual(2, p.P[1])
        self.assertEqual(3, p.P[2])
        self.assertEqual(4, p.P[3])
        self.assertEqual(0, p.P[4])
def art_gallery_problem(interface, points=None, show_decomposition=True):
    if points is None:
        points = ioclass.read_from_file(filename)

    poly = Polygon()
    poly.set_points(points)

    size = len(points)

    list_points = []
    for p in points:
        list_points.append([p.x, p.y])

    seidel_triangalator = seidel.Triangulator(list_points)
    triangles1 = seidel_triangalator.triangles()

    # Now for the GUI. Both the polygon and its triangulation have been scaled,
    # as specified above. Now we need to draw them on a Tkinter Canvas.
    # Setup and init a canvas:
    if show_decomposition:
        interface.draw_triangles(triangles1)

    # The last step is to output the triangulation of the original, non-scaled
    # polygon to the console:
    # ioclass.print_triangles_to_console(triangles1)

    art_gallery_coloring = Coloring()
    art_gallery_coloring.set_triangulation(points, triangles1)
    points_str, res = art_gallery_coloring.colorize()

    list_res = []
    for p in points_str:
        p = p.name
        list_res.append([points[int(p)].x, points[int(p)].y])

    interface.draw_result(list_res)
    interface.set_result(res)