def test_p_cut_Wp_white_cut_G_through_Np_Sl_cut_SSWl_not_cut(self):
        img_depart = [[0, 0, 0, 0, 0, 0],
                      [0, 0, 1, 1, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 0, 1, 0, 1, 0],
                      [0, 0, 0, 0, 1, 0],
                      [0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        img_soluce = [[0, 0, 0, 0, 0, 0],
                      [0, 0, 1, 1, 1, 0],
                      [0, 1, 0, 1, 1, 0],
                      [0, 0, 0, 0, 1, 0],
                      [0, 0, 0, 0, 1, 0],
                      [0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        binary_image = BinaryImage.create_img_from_array(img_depart, BLACK_CONNEXITY, WHITE_CONNEXITY)

        solver = B8W4_Solver(binary_image, BinaryImage.create_img_vertical(binary_image.size))

        solver.resolve_image(binary_image)

        self.assertEqual(img_soluce,
                         binary_image.convert_pixels_to_img(),
                         "In case of p cut vertex and W(p) white cut, g goes to p through N(p)"
                         "and l is cut vertex but SSW(l) is not cut the interchange should be <SSW(l), S(l)>")
        self.assertEqual(1,
                         len(solver.array_interchange),
                         "The number interchange should be 1")
    def test_p_cut_Wp_white_not_cut(self):
        img_depart = [[0, 0, 0, 0, 0, 0],
                      [0, 1, 1, 1, 1, 0],
                      [0, 0, 0, 0, 1, 0],
                      [0, 1, 1, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        img_soluce = [[0, 0, 0, 0, 0, 0],
                      [0, 1, 1, 1, 1, 0],
                      [0, 0, 0, 1, 0, 0],
                      [0, 1, 1, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        binary_image = BinaryImage.create_img_from_array(img_depart, BLACK_CONNEXITY, WHITE_CONNEXITY)

        solver = B8W4_Solver(binary_image, BinaryImage.create_img_vertical(binary_image.size))

        solver.resolve_image(binary_image)

        self.assertEqual(img_soluce,
                         binary_image.convert_pixels_to_img(),
                         "In case of p cut vertex and W(p) white not cut,"
                         " the interchange should be <p, W(p)>")
        self.assertEqual(1,
                         len(solver.array_interchange),
                         "The number interchange should be 1")
示例#3
0
    def statistics_from_random_images(self,
                                      black_connexity=4,
                                      white_connexity=4,
                                      nb_iter=10,
                                      initial_size_image=50,
                                      nb_tick=5,
                                      incr_size_image=10,
                                      seed_min=0,
                                      seed_max=500000):
        size_image = initial_size_image
        for i in range(nb_iter):
            total_interchange = 0
            seeds = []
            for j in range(nb_tick):
                seed = random.randint(seed_min, seed_max)
                binary_image = BinaryImage.create_random_img(
                    n=size_image,
                    black_connexity=black_connexity,
                    white_connexity=white_connexity,
                    seed=seed)
                solver = None

                if black_connexity == white_connexity == 4:
                    solver = B4W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 4 and white_connexity == 8:
                    solver = B4W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 8 and white_connexity == 4:
                    solver = B8W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == white_connexity == 8:
                    solver = B8W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))

                nb_interchange = solver.solve()
                total_interchange += nb_interchange
                seeds.append(seed)

            average_tick_interchange = total_interchange / nb_tick

            self.dic_interchanges[size_image] = [
                seeds, average_tick_interchange
            ]
            size_image += incr_size_image

        print("Total average for solver B", black_connexity, "W",
              white_connexity, " is ", self.dic_interchanges)
示例#4
0
    def statistics_spiral(self,
                          black_connexity=4,
                          white_connexity=4,
                          nb_iter=10,
                          initial_size_image=50,
                          nb_tick=5,
                          incr_size_image=10):
        size_image = initial_size_image
        for i in range(nb_iter):
            total_interchange = 0
            for j in range(nb_tick):
                begin = time.time()
                binary_image = BinaryImage.create_img_spiral(
                    size_image=size_image,
                    black_connexity=black_connexity,
                    white_connexity=white_connexity)
                solver = None

                if black_connexity == white_connexity == 4:
                    solver = B4W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 4 and white_connexity == 8:
                    solver = B4W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 8 and white_connexity == 4:
                    solver = B8W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == white_connexity == 8:
                    solver = B8W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))

                nb_interchange = solver.solve()
                total_interchange += nb_interchange
                print("size : ", size_image, ", timer : ", time.time() - begin)

            self.dic_interchanges[size_image] = [i, total_interchange]
            size_image += incr_size_image

        print("Total average for solver B", black_connexity, "W",
              white_connexity, " is ", self.dic_interchanges)
    def test_p_cut_Wp_white_cut_G_through_Np_Sl_cut_SSWl_cut_z_no_exist_and_path_through_SWg(self):
        img_depart = [[0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 1, 1, 0, 0],
                      [0, 0, 1, 0, 0, 1, 0],
                      [0, 0, 0, 1, 0, 1, 0],
                      [0, 0, 1, 0, 0, 1, 0],
                      [0, 1, 0, 0, 0, 1, 0],
                      [0, 1, 0, 1, 0, 1, 0],
                      [0, 1, 0, 1, 0, 1, 0],
                      [0, 0, 1, 0, 0, 1, 0],
                      [0, 0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0]]

        img_soluce = [[0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 1, 1, 0, 0],
                      [0, 0, 1, 0, 0, 1, 0],
                      [0, 0, 0, 1, 0, 1, 0],
                      [0, 0, 1, 0, 0, 1, 0],
                      [0, 1, 0, 0, 0, 1, 0],
                      [0, 1, 0, 1, 1, 1, 0],
                      [0, 1, 0, 0, 0, 1, 0],
                      [0, 0, 1, 0, 0, 1, 0],
                      [0, 0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0]]

        binary_image = BinaryImage.create_img_from_array(img_depart, BLACK_CONNEXITY, WHITE_CONNEXITY)

        solver = B8W4_Solver(binary_image, BinaryImage.create_img_vertical(binary_image.size))

        solver.resolve_image(binary_image)

        self.assertEqual(img_soluce,
                         binary_image.convert_pixels_to_img(),
                         "In case of p cut vertex and W(p) white cut, g goes to p through N(p)"
                         "and l is cut vertex and SSW(l) is cut. all z exist such as w(z) is white"
                         "if g != h and path is through SW(g) then the interchange is"
                         "<g, NE(g)>")
        self.assertEqual(1,
                         len(solver.array_interchange),
                         "The number interchange should be 1")
def main_b8_w4() -> int:
    image = BinaryImage.create_img_spiral(50, 8, 4)
    image_final = BinaryImage.create_img_vertical(image.size, 8, 4)

    displayer = BinaryImageDisplayer(show_legend=True)

    solver = B8W4_Solver(image, image_final)

    displayer.show(solver.imageStart, subtitle="Image de départ")

    nb_interchange = solver.solve()

    print("Nb interchange = ", nb_interchange)
    print("len interchange = ", len(solver.array_interchange))

    displayer.show(solver.imageStart, subtitle="Image de fin")

    displayer.create_gif(image=solver.get_image_save(),
                         array_interchage=solver.array_interchange, speed=1000, name="B8_W4.gif")

    return 0
    def test_p_cut_Wp_white_cut_G_through_Np_Sl_cut_SSWl_cut_z_exist_Nz_or_NNz_black_and_z_in_south_wssssl(self):
        img_depart = [[0, 0, 0, 0, 0, 0],
                      [0, 0, 1, 1, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 0, 1, 0, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 1, 1, 0, 1, 0],
                      [0, 1, 1, 0, 1, 0],
                      [0, 0, 1, 0, 1, 0],
                      [0, 0, 0, 0, 1, 0],
                      [0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        img_soluce = [[0, 0, 0, 0, 0, 0, 0],
                      [0, 0, 1, 1, 1, 0, 0],
                      [0, 1, 0, 0, 1, 0, 0],
                      [0, 0, 1, 0, 0, 1, 0],
                      [0, 1, 0, 1, 0, 1, 0],
                      [0, 1, 0, 0, 0, 1, 0],
                      [0, 1, 1, 0, 1, 0, 0],
                      [0, 0, 1, 0, 1, 0, 0],
                      [0, 0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 1, 0, 0, 0],
                      [0, 0, 0, 0, 0, 0, 0]]

        binary_image = BinaryImage.create_img_from_array(img_depart, BLACK_CONNEXITY, WHITE_CONNEXITY)

        solver = B8W4_Solver(binary_image, BinaryImage.create_img_vertical(binary_image.size))

        solver.resolve_image(binary_image)

        self.assertEqual(img_soluce,
                         binary_image.convert_pixels_to_img(),
                         "In case of p cut vertex and W(p) white cut, g goes to p through N(p)"
                         "and l is cut vertex and SSW(l) is cut. z exist such as w(z) is black and N(z) or NN(z) is "
                         "black. If z == wssss+(l) the 4-vertical interchange should be "
                         "<EE(z), EEE(z)>, <NEE(z), ZEEE(z), <NNEE(z), NNEEE(z)>, <z, NE(z)>")
        self.assertEqual(4,
                         len(solver.array_interchange),
                         "The number interchange should be 4")
    def test_p_cut_Wp_white_cut_G_through_Np_Sl_cut_SSWl_cut_z_exist_Nz_and_NNz_white(self):
        img_depart = [[0, 0, 0, 0, 0, 0],
                      [0, 0, 1, 1, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 0, 1, 0, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 1, 1, 0, 1, 0],
                      [0, 0, 1, 0, 1, 0],
                      [0, 0, 0, 0, 1, 0],
                      [0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        img_soluce = [[0, 0, 0, 0, 0, 0],
                      [0, 0, 1, 1, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 0, 1, 0, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 1, 0, 1, 1, 0],
                      [0, 1, 0, 0, 1, 0],
                      [0, 0, 1, 0, 1, 0],
                      [0, 0, 0, 0, 1, 0],
                      [0, 0, 0, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        binary_image = BinaryImage.create_img_from_array(img_depart, BLACK_CONNEXITY, WHITE_CONNEXITY)

        solver = B8W4_Solver(binary_image, BinaryImage.create_img_vertical(binary_image.size))

        solver.resolve_image(binary_image)

        self.assertEqual(img_soluce,
                         binary_image.convert_pixels_to_img(),
                         "In case of p cut vertex and W(p) white cut, g goes to p through N(p)"
                         "and l is cut vertex and SSW(l) is cut. z exist such as w(z) is black and N(z) and NN(z) are "
                         "white, the interchange should be <z, NE(z)>")
        self.assertEqual(1,
                         len(solver.array_interchange),
                         "The number interchange should be 1")