Esempio n. 1
0
 def testShelfBWFRotation(self):
     """
     Best Bin Fit
     Shelf Bins (best_width_fit)
     Item Sorting == False
     Item Rotation == True
     """
     M = greedypacker.BinManager(10,
                                 5,
                                 pack_algo='shelf',
                                 bin_algo='bin_first_fit',
                                 heuristic='best_width_fit',
                                 sorting=False,
                                 rotation=True)
     ITEM = greedypacker.Item(1, 1)
     ITEM2 = greedypacker.Item(4, 3)
     ITEM3 = greedypacker.Item(2, 2)
     M.add_items(ITEM, ITEM2, ITEM3)
     M.execute()
     correct = [ITEM, ITEM2, ITEM3]
     with self.subTest():
         self.assertEqual(M.items, correct)
     with self.subTest():
         self.assertEqual(ITEM.x, 0)
         self.assertEqual(ITEM.y, 0)
     with self.subTest():
         self.assertEqual(ITEM2.x, 0)
         self.assertEqual(ITEM2.y, 1)
     with self.subTest():
         self.assertEqual(ITEM3.x, 4)
         self.assertEqual(ITEM3.y, 1)
Esempio n. 2
0
    def testSkyline(self):
        """
        Bin First Fit
        Skyline (bottom_left)
        Item Sorting == True
        Item Rotation == True
        """
        M = greedypacker.BinManager(10,
                                    5,
                                    pack_algo='skyline',
                                    heuristic='bottom_left',
                                    bin_algo='bin_first_fit',
                                    sorting=True,
                                    rotation=True)

        ITEM = greedypacker.Item(10, 3)
        ITEM2 = greedypacker.Item(10, 4)
        ITEM3 = greedypacker.Item(1, 1)
        M.add_items(ITEM, ITEM2, ITEM3)
        M.execute()
        correct = [ITEM, ITEM2, ITEM3]
        with self.subTest():
            self.assertCountEqual(M.items, correct)
        with self.subTest():
            self.assertEqual(ITEM.x, 0)
            self.assertEqual(ITEM.y, 0)
        with self.subTest():
            self.assertEqual(ITEM2.x, 0)
            self.assertEqual(ITEM2.y, 0)
        with self.subTest():
            self.assertEqual(ITEM3.x, 0)
            self.assertEqual(ITEM3.y, 4)
Esempio n. 3
0
 def testGuillotineBWFSortingRotation(self):
     """
     Best Bin Fit
     Guillotine Bins (best_area)
     Split Horizontal
     Item Sorting == True
     Item Rotation == True
     """
     M = greedypacker.BinManager(10,
                                 5,
                                 pack_algo='guillotine',
                                 bin_algo="bin_best_fit",
                                 heuristic='best_area',
                                 sorting=True,
                                 rotation=True)
     ITEM = greedypacker.Item(4, 3)
     ITEM2 = greedypacker.Item(5, 3)
     ITEM3 = greedypacker.Item(2, 2)
     M.add_items(ITEM, ITEM2, ITEM3)
     M.execute()
     correct = [ITEM2, ITEM, ITEM3]
     with self.subTest():
         self.assertEqual(M.items, correct)
     with self.subTest():
         self.assertEqual(ITEM.x, 5)
         self.assertEqual(ITEM.y, 0)
     with self.subTest():
         self.assertEqual(ITEM2.x, 0)
         self.assertEqual(ITEM2.y, 0)
     with self.subTest():
         self.assertEqual(ITEM3.x, 0)
         self.assertEqual(ITEM3.y, 3)
Esempio n. 4
0
    def testMaximalRectangleBSS(self):
        """
        Best Bin Fit
        Maximal Rectangle Bins (Best Short Side)
        Split Horizontal
        Item Sorting == False
        Item Rotation == False
        """
        M = greedypacker.BinManager(8,
                                    4,
                                    pack_algo='maximal_rectangle',
                                    bin_algo="bin_best_fit",
                                    heuristic='best_shortside',
                                    sorting=False,
                                    rotation=False)

        I = greedypacker.Item(1, 1)
        I2 = greedypacker.Item(2, 2)
        F0 = greedypacker.maximal_rectangles.FreeRectangle(7, 1, 1, 0)
        F1 = greedypacker.maximal_rectangles.FreeRectangle(8, 1, 0, 3)
        F2 = greedypacker.maximal_rectangles.FreeRectangle(6, 4, 2, 0)
        M.add_items(I, I2)
        M.execute()
        with self.subTest():
            self.assertCountEqual(M.bins[0].freerects, [F0, F1, F2])
        with self.subTest():
            self.assertEqual(I.x, 0)
            self.assertEqual(I.y, 0)
        with self.subTest():
            self.assertEqual(I2.x, 0)
            self.assertEqual(I2.y, 1)
Esempio n. 5
0
 def testReadme(self):
     """
     Example insertion from README.md
     """
     M = greedypacker.BinManager(8,
                                 4,
                                 pack_algo='shelf',
                                 heuristic='next_fit')
     ITEM = greedypacker.Item(4, 2)
     ITEM2 = greedypacker.Item(5, 2)
     ITEM3 = greedypacker.Item(2, 2)
     M.add_items(ITEM, ITEM2, ITEM3)
     M.execute()
     correct = [ITEM2, ITEM, ITEM3]
     with self.subTest():
         self.assertEqual(M.items, correct)
     with self.subTest():
         self.assertEqual(ITEM.x, 0)
         self.assertEqual(ITEM.y, 2)
     with self.subTest():
         self.assertEqual(ITEM2.x, 0)
         self.assertEqual(ITEM2.y, 0)
     with self.subTest():
         self.assertEqual(ITEM3.x, 5)
         self.assertEqual(ITEM3.y, 0)
Esempio n. 6
0
 def testShelfBWFRotationIdenticalItems(self):
     """
     Manually insert two identical items
     """
     ITEM = greedypacker.Item(1, 2)
     ITEM2 = greedypacker.Item(1, 2)
     M = greedypacker.BinManager(10,
                                 5,
                                 pack_algo='shelf',
                                 bin_algo='bin_first_fit',
                                 heuristic='best_width_fit',
                                 sorting_heuristic='ASCA',
                                 rotation=True)
     M.add_items(ITEM, ITEM2)
     M.execute()
Esempio n. 7
0
 def testItemTooBig(self):
     M = greedypacker.BinManager(8,
                                 4,
                                 pack_algo='skyline',
                                 bin_algo='bin_best_fit')
     I = greedypacker.Item(10, 20)
     with self.assertRaises(ValueError):
         M.add_items(I)
         M.execute()
                    dpi=150)
    else:
        plt.show()
    return


if __name__ == '__main__':
    #M = g.BinManager(10, 6, pack_algo='maximal_rectangle', heuristic='bottom_left', rotation=False, sorting=False, wastemap=False)
    M = g.BinManager(10,
                     6,
                     pack_algo='guillotine',
                     heuristic='best_shortside',
                     rotation=False,
                     sorting=False)
    guillotine = [
        g.Item(2, 3),
        g.Item(2, 2),
        g.Item(2, 1),
        g.Item(2, 3),
        g.Item(2, 2),
        g.Item(3, 2)
    ]
    maximal = [
        g.Item(2, 3),
        g.Item(3, 3),
        g.Item(4, 1),
        g.Item(2, 3),
        g.Item(2, 2),
        g.Item(1, 2)
    ]
    shelf = [
Esempio n. 9
0
    ax.set_ylim(0, M.bin_height)

    plt.legend(handles=handles, bbox_to_anchor=(1.04, 1), loc="upper left")

    if save:
        plt.savefig('%s Algorithm - %r Heuristic' % (M.pack_algo, M.heuristic),
                    bbox_inches="tight",
                    dpi=150)
    else:
        plt.show()
    return


if __name__ == '__main__':
    maximal = [
        g.Item(300, 150, 0, 45, 0, 45),
        g.Item(300, 150, 45, 0, 45, 0),
        g.Item(300, 150, 45, 0, 0, 45),
        g.Item(300, 150, 0, 45, 45, 0)
    ]
    """
    g.Item(270, 150, 0, 45, 0, 45),
    g.Item(270, 150, 45, 0, 45, 0),
    g.Item(270, 150, 45, 0, 0, 45),
    g.Item(270, 150, 0, 45, 45, 0),
    g.Item(250, 150, 0, 45, 0, 45),
    g.Item(250, 150, 45, 0, 45, 0),
    g.Item(250, 150, 45, 0, 0, 45),
    g.Item(250, 150, 0, 45, 45, 0)
    """
Esempio n. 10
0
            points.append(new_point)
        else:
            new_point = create_point(points[i], sizes[i], 1)
            points.append(new_point)
    points = create_array_of_double(two_demention_list_to_list(points))
    ms.AddPolyline(points)
    return points


M = greedypacker.BinManager(20,
                            10,
                            pack_algo='maximal_rectangle',
                            heuristic='bottom_left',
                            rotation=True)

ITEM = greedypacker.Item(5, 6)
ITEM4 = greedypacker.Item(3, 2)
# ITEM2 = greedypacker.Item(1320, 700)
# ITEM3 = greedypacker.Item(1320, 720)
# ITEM5 = greedypacker.Item(1000, 670)

M.add_items(ITEM, ITEM4)

M.execute()


def draw_packs():
    initial_x = 0
    initial_y = 0
    for p_bin in M.bins:
        draw_rectangle(doc, array('d', (initial_x, initial_y, 0)), 20, 10)
Esempio n. 11
0
    mini = create_mini(m)
    if not isinstance(mini, str):
        minis.append(mini)
    else:
        print('{} skipped with error: {}'.format(m, mini))

## optimization algorithm to align images on canvas
M = greedypacker.BinManager(canvas[0], canvas[1], bin_algo='bin_best_fit', pack_algo='shelf', heuristic='best_area_fit',
                            split_heuristic='default', rotation=True, rectangle_merge=True, wastemap=True, sorting=True,
                            sorting_heuristic='DESCA')

its = {}
item_id = 0
for it in minis:
    its[item_id] = it
    item = greedypacker.Item(it.shape[1], it.shape[0])
    item.id = item_id
    M.add_items(item)
    item_id += 1

M.execute()
result = M.bins

## Create sheets
sheet_nr = 1
for r in result:
    img = np.zeros((int(canvas[1]),int(canvas[0]), 3), np.uint8) + 255
    for it in r.items:
        x = int(it.x)
        y = int(it.y)
        w = int(it.width)