Example #1
0
 def testThreeItemInsert(self):
     """
     Three Item insertion 
     Rotation = False
     """
     I = item.Item(1, 1)
     I2 = item.Item(4, 2)
     I3 = item.Item(1, 1)
     F0 = maximal_rectangles.FreeRectangle(8, 2, 0, 2)
     F1 = maximal_rectangles.FreeRectangle(3, 4, 5, 0)
     self.M.contact_point(I)
     self.M.contact_point(I2)
     self.M.contact_point(I3)
     with self.subTest():
         self.assertCountEqual(self.M.freerects, [F0, F1])
     with self.subTest():
         self.assertEqual(I.x, 0)
         self.assertEqual(I.y, 0)
     with self.subTest():
         self.assertEqual(I2.x, 1)
         self.assertEqual(I2.y, 0)
     with self.subTest():
         self.assertEqual(I3.x, 0)
         self.assertEqual(I3.y, 1)
     with self.subTest():
         self.assertEqual(self.M.free_area, 22)
Example #2
0
 def testThreeInserts(self):
     """
     Three items across two shelves
     """
     ITEM = item.Item(4, 2)
     ITEM2 = item.Item(5, 2)
     ITEM3 = item.Item(2, 2)
     self.sheet.insert(ITEM, heuristic='best_height_fit')
     self.sheet.insert(ITEM2, heuristic='best_width_fit')
     self.sheet.insert(ITEM3, heuristic='best_width_fit')
     with self.subTest():
         correct = shelf.Shelf(8, 2, 0)
         correct.insert(ITEM)
         correct.available_width = 4
         self.assertEqual(self.sheet.shelves[0].__dict__, correct.__dict__)
     with self.subTest():
         correct = shelf.Shelf(8, 2, 2)
         correct.insert(ITEM2)
         correct.insert(ITEM3)
         correct.available_width = 1
         self.assertEqual(self.sheet.shelves[1].__dict__, correct.__dict__)
     with self.subTest():
         correct = [ITEM, ITEM2, ITEM3]
         self.assertEqual(self.sheet.items, correct)
     with self.subTest():
         self.assertEqual(self.sheet.free_area, 10)
Example #3
0
 def testThreeInserts(self):
     """
     Three items across two shelves
     """
     ITEM = item.Item(4, 2)
     ITEM2 = item.Item(5, 2)
     ITEM3 = item.Item(2, 2)
     self.sheet.insert(ITEM, heuristic='worst_area_fit')
     self.sheet.insert(ITEM2, heuristic='worst_area_fit')
     self.sheet.insert(ITEM3, heuristic='worst_area_fit')
     with self.subTest():
         correct = shelf.Shelf(8, 2, 0)
         correct.items = [ITEM, ITEM3]
         correct.available_width = 2
         self.assertCountEqual(self.sheet.shelves[0].items, correct.items)
     with self.subTest():
         correct = shelf.Shelf(8, 2, 2)
         correct.items = [ITEM2]
         correct.available_width = 3
         self.assertCountEqual(self.sheet.shelves[1].items, correct.items)
     with self.subTest():
         correct = [ITEM, ITEM2, ITEM3]
         self.assertCountEqual(self.sheet.items, correct)
     with self.subTest():
         self.assertEqual(self.sheet.free_area, 10)
Example #4
0
 def testTwoInsertsD(self):
     """
     Manually insert two identical items
     """
     ITEM = item.Item(1, 2)
     ITEM2 = item.Item(1, 2)
     self.sheet.insert(ITEM)
     self.sheet.insert(ITEM2)
     self.assertCountEqual(self.sheet.items, [ITEM, ITEM2])
Example #5
0
 def testMatchingWidths(self):
     """
     Two item
     Split Horizontal
     Rotation == False
     RectMerge == True
     """
     ITEM = item.Item(4, 2)
     ITEM2 = item.Item(4, 3)
     self.BIN.insert(ITEM, 'best_area')
     self.BIN.insert(ITEM2, 'best_area')
     self.assertEqual(self.BIN.freerects, [self.freeRectangle(6, 5, 4, 0)])
Example #6
0
 def setUp(self):
     self.S = skyline.Skyline(8, 5)
     I0 = item.Item(2, 2)
     I1 = item.Item(2, 1)
     I2 = item.Item(3, 3)
     I3 = item.Item(3, 2)
     I4 = item.Item(4, 2)
     self.S.insert(I0, 'bottom_left')
     self.S.insert(I1, 'bottom_left')
     self.S.insert(I2, 'bottom_left')
     self.S.insert(I3, 'bottom_left')
     self.S.insert(I4, 'bottom_left')
Example #7
0
 def setUp(self):
     self.S = skyline.Skyline(8, 5, heuristic='bottom_left')
     I0 = item.Item(2, 2)
     I1 = item.Item(2, 1)
     I2 = item.Item(3, 3)
     I3 = item.Item(3, 2)
     I4 = item.Item(4, 2)
     self.S.insert(I0)
     self.S.insert(I1)
     self.S.insert(I2)
     self.S.insert(I3)
     self.S.insert(I4)
Example #8
0
    def testReturn(self):
        ITEM = item.Item(4, 2)
        ITEM2 = item.Item(2, 2)
        self.BIN.insert(ITEM, 'best_area')
        self.BIN.insert(ITEM2, 'best_area')
        correct = {
            'width': 10,
            'height': 5,
            'area': 50,
            'efficiency': 0.24,
            'items': [ITEM, ITEM2],
        }

        self.assertEqual(self.BIN.bin_stats(), correct)
Example #9
0
    def testCalcWaste2(self):
        """
        No wasted Space after insertion
        """
        I0 = item.Item(2, 2)
        I1 = item.Item(2, 1)
        I2 = item.Item(3, 3)
        I3 = item.Item(2, 2)

        self.S.insert(I0, 'bottom_left')
        self.S.insert(I1, 'bottom_left')
        self.S.insert(I2, 'bottom_left')

        wasted_area = self.S.calc_waste(0, I3, 2)
        self.assertEqual(wasted_area, 0)
Example #10
0
    def testCalcWaste2(self):
        """
        No wasted Space after insertion
        """
        I0 = item.Item(2, 2)
        I1 = item.Item(2, 1)
        I2 = item.Item(3, 3)
        I3 = item.Item(2, 2)

        self.S.insert(I0)
        self.S.insert(I1)
        self.S.insert(I2)

        wasted_area = skyline.calc_waste(self.S.skyline, I3, 2, 0)
        self.assertEqual(wasted_area, 0)
Example #11
0
    def testItemInsertionSuccessRotation(self):
        """
        Single item
        Split Horizontal
        Rotation == True
        RectMerge == False
        """
        F0 = self.freeRectangle(2, 1, 0, 0)
        ITEM = item.Item(1, 2)

        self.BIN.rotation = True
        self.BIN.freerects = SortedListWithKey([F0],
                                               key=lambda x: x.area,
                                               load=1000)
        self.BIN.best_shortside(ITEM)

        with self.subTest():
            self.assertCountEqual(self.BIN.freerects, [])
        with self.subTest():
            self.assertEqual(ITEM.x, 0)
            self.assertEqual(ITEM.y, 0)
        with self.subTest():
            self.assertEqual(self.BIN.items, [ITEM])
        with self.subTest():
            self.assertEqual(self.BIN.free_area, 30)
Example #12
0
    def testItemInsertionSuccess(self):
        """
        Single item
        Split Horizontal
        Rotation == False
        RectMerge == False
        """
        F0 = self.freeRectangle(2, 2, 0, 0)
        F1 = self.freeRectangle(3, 3, 2, 0)
        ITEM = item.Item(1, 1)

        self.BIN.freerects = SortedListWithKey([F0, F1], key=lambda x: x.area)
        self.BIN.insert(ITEM)
        with self.subTest():
            correct = [
                self.freeRectangle(2, 2, 0, 0),
                self.freeRectangle(2, 1, 3, 0),
                self.freeRectangle(3, 2, 2, 1)
            ]
            self.assertCountEqual(self.BIN.freerects, correct)
        with self.subTest():
            self.assertEqual(ITEM.x, 2)
            self.assertEqual(ITEM.y, 0)
        with self.subTest():
            self.assertEqual(self.BIN.items, [ITEM])
        with self.subTest():
            self.assertEqual(self.BIN.free_area, 49)
Example #13
0
 def testInsert(self):
     """
     Item Insertion
     Rotation = False
     """
     I = item.Item(2, 2)
     F0 = maximal_rectangles.FreeRectangle(8, 4, 0, 0)
     self.assertTrue(self.M.insert(I, 'best_shortside'))
Example #14
0
    def testCalcWaste(self):
        """
        2 wasted space after insertion
        """
        I0 = item.Item(2, 2)
        I1 = item.Item(2, 1)
        I2 = item.Item(3, 3)
        I3 = item.Item(3, 2)
        I4 = item.Item(4, 2)

        self.S.insert(I0, 'bottom_left')
        self.S.insert(I1, 'bottom_left')
        self.S.insert(I2, 'bottom_left')
        self.S.insert(I3, 'bottom_left')

        wasted_area = skyline.calc_waste(self.S.skyline, I4, 3, 0)
        self.assertEqual(wasted_area, 2)
Example #15
0
 def testWastemapInsertion(self):
     """
     5 item insertion to match Figure 7 from
     Jukka's article.
     """
     I5 = item.Item(1, 2)
     self.S.insert(I5)
     self.assertEqual(I5.x, 3)
     self.assertEqual(I5.y, 1)
Example #16
0
 def testItemInsertionFailure(self):
     """
     Single Item Fits no FreeRectangles
     Split Horizontal
     Rotation == False
     RectMerge == False
     """
     ITEM = item.Item(5, 11)
     self.assertFalse(self.BIN.insert(ITEM))
Example #17
0
 def testOneItemInsert(self):
     """
     Single Item Fits
     """
     I = item.Item(2, 2)
     self.S.insert(I)
     S1 = skyline.SkylineSegment(0, 2, 2)
     S2 = skyline.SkylineSegment(2, 0, 6)
     self.assertCountEqual(self.S.skyline, [S1, S2])
Example #18
0
    def testClipSegmentExtendsBoth(self):
        """
        Segmented hangs over left
        """
        I = item.Item(2, 1, CornerPoint=[2,0])
        S = skyline.SkylineSegment(0, 0, 6) 
        res = self.S.clip_segment(S, I)

        self.assertCountEqual(res, [skyline.SkylineSegment(0, 0, 2), skyline.SkylineSegment(4,0,2)])
Example #19
0
    def testItemDoesntFitsRect(self):
        """
        Single Item Fits the FreeRectangle
        Rotation == False
        """
        I = item.Item(2, 4)
        F = maximal_rectangles.FreeRectangle(2, 3, 0, 0)

        self.assertFalse(self.M.item_fits_rect(I, F))
Example #20
0
    def testClipSegmentExtendsRight(self):
        """
        Segmented hangs over left
        """
        I = item.Item(4, 1, CornerPoint=[0, 0])
        S = skyline.SkylineSegment(2, 0, 4)
        res = self.S._clip_segment(S, I)

        self.assertEqual(res, [skyline.SkylineSegment(4, 0, 2)])
Example #21
0
    def testClipSegmentFullOverlap(self):
        """
        Segmented fully adjacent to item
        """
        I = item.Item(4, 1, CornerPoint=[0, 0])
        S = skyline.SkylineSegment(0, 0, 4)
        res = self.S._clip_segment(S, I)

        self.assertEqual(res, [])
Example #22
0
 def testTwoInsertsA(self):
     """
     Two items that fit in one shelf
     """
     ITEM = item.Item(3, 2)
     ITEM2 = item.Item(3, 2)
     self.sheet.insert(ITEM, heuristic='first_fit')
     self.sheet.insert(ITEM2, heuristic='first_fit')
     with self.subTest():
         correct = shelf.Shelf(8, 2, 0)
         correct.insert(ITEM)
         correct.insert(ITEM2)
         self.assertEqual(self.sheet.shelves[0].__dict__, correct.__dict__)
     with self.subTest():
         correct = [ITEM, ITEM2]
         self.assertEqual(self.sheet.items, correct)
     with self.subTest():
         self.assertEqual(self.sheet.free_area, 20)
Example #23
0
 def testBadInsert(self):
     """
     Item too Big
     Rotation = False
     """
     I = item.Item(9, 4)
     F0 = maximal_rectangles.FreeRectangle(8, 4, 0, 0)
     self.M.best_shortside(I)
     self.assertCountEqual(self.M.freerects, [F0])
Example #24
0
 def testTwoInsertsC(self):
     """
     Second item doesn't fit remaining vertical space in sheet
     """
     ITEM = item.Item(7, 3)
     ITEM2 = item.Item(3, 2)
     self.sheet.insert(ITEM, heuristic='next_fit')
     res = self.sheet.insert(ITEM2, heuristic='next_fit')
     with self.subTest():
         correct = [ITEM]
         self.assertEqual(self.sheet.items, correct)
     with self.subTest():
         self.assertFalse(res)
     with self.subTest():
         self.assertEqual(ITEM.x, 0)
         self.assertEqual(ITEM.y, 0)
     with self.subTest():
         self.assertEqual(self.sheet.free_area, 11)
Example #25
0
 def testTwoInsertsB(self):
     """
     Two items that fit in two shelves
     """
     ITEM = item.Item(2, 2)
     ITEM2 = item.Item(7, 2)
     self.sheet.insert(ITEM, heuristic='next_fit')
     self.sheet.insert(ITEM2, heuristic='next_fit')
     with self.subTest():
         correct = [ITEM, ITEM2]
         self.assertEqual(self.sheet.items, correct)
     with self.subTest():
         self.assertEqual(ITEM.x, 0)
         self.assertEqual(ITEM.y, 0)
         self.assertEqual(ITEM2.x, 0)
         self.assertEqual(ITEM2.y, 2)
     with self.subTest():
         self.assertEqual(self.sheet.free_area, 14)
Example #26
0
    def testAddToWastemapA(self):
        """
       Manual Triggering of sheet.add_to_wastmap
        Without vertical offest
        """
        self.sheet.use_waste_map = False

        ITEM1 = item.Item(3, 3)
        ITEM2 = item.Item(2, 2)
        ITEM3 = item.Item(2, 2)

        self.sheet.insert(ITEM1, heuristic='next_fit')
        self.sheet.insert(ITEM2, heuristic='next_fit')
        self.sheet.insert(ITEM3, heuristic='next_fit')
        self.sheet.add_to_wastemap(self.sheet.shelves[-1])

        correct = [(1, 3, 7, 0), (4, 1, 3, 2)]
        self.assertEqual(self.sheet.wastemap.freerects, correct)
Example #27
0
 def testCheckFitTrue(self):
     """
     Assert item does fit above line segment
     """
     I = item.Item(2, 2, CornerPoint=[0, 0])
     S1 = skyline.SkylineSegment(0, 1, 2)
     S2 = skyline.SkylineSegment(2, 0, 6)
     self.S.skyline.pop()
     self.S.skyline.update([S1, S2])
     self.assertEqual(self.S._check_fit(I.width, I.height, 0), (True, 1))
Example #28
0
 def testTwoInsertsC(self):
     """
     Second item doesn't fit remaining vertical space in sheet
     """
     ITEM = item.Item(3, 2)
     ITEM2 = item.Item(6, 3)
     self.sheet.insert(ITEM, heuristic='first_fit')
     res = self.sheet.insert(ITEM2, heuristic='first_fit')
     with self.subTest():
         correct = shelf.Shelf(8, 2, 0)
         correct.insert(ITEM)
         self.assertEqual(self.sheet.shelves[0].__dict__, correct.__dict__)
     with self.subTest():
         self.assertFalse(res)
     with self.subTest():
         correct = [ITEM]
         self.assertEqual(self.sheet.items, correct)
     with self.subTest():
         self.assertEqual(self.sheet.free_area, 26)
Example #29
0
 def testItemTooTall(self):
     """
     Manual insertion of oversized (height) object into a shelf
     """
     ITEM = item.Item(6, 5)
     result = self.shelf.insert(ITEM)
     with self.subTest():
         self.assertEqual(self.shelf.items, [])
     with self.subTest():
         self.assertFalse(result)
Example #30
0
 def testItemTooWide(self):
     """
     Manual insertion of oversized (width) object into a shelf
     """
     ITEM = item.Item(9, 2)
     result = self.shelf.insert(ITEM)
     with self.subTest():
         self.assertEqual(self.shelf.items, [])
     with self.subTest():
         self.assertFalse(result)