コード例 #1
0
 def solve(self, presents_to_place):
     if self.make_timer:
         timer = Timer()
         num_total_presents = len(presents_to_place)
     gc_collect_count = 0
     presents_index = 0
     presents_last_index = len(presents_to_place)
     while 1:
         priority_pick = self.priority_pick
         new_layer = MaxRectSolver(self.width, self.height)
         try:
             presents_index = new_layer.solve(presents_to_place, presents_index, self.scorer, priority_pick)
             self._add_layer(new_layer)
             print("{} more presents".format(presents_last_index - presents_index))
             if presents_index == presents_last_index - 1:
                 break
         except NoFit:
             priority_pick -= 10
             assert priority_pick > 1
         if self.make_timer:
             ratio = presents_index / num_total_presents
             print("Time left: {}; End time: {}".format(timer.time_left(ratio), timer.time_end(ratio)))
     print("Solved with total depth {}".format(self.total_depth))
     if self.make_timer:
         print("Time taken: {}".format(timer.time_taken()))
     if self.gc_collect_cycle:
         gc_collect_count += 1
         if gc_collect_count == self.gc_collect_cycle:
             gc_collect_count = 0
             print("GC collect")
             gc.collect()
コード例 #2
0
 def solve(self, presents_to_place):
     if self.make_timer:
         timer = Timer()
         num_total_presents = len(presents_to_place)
     gc_collect_count = 0
     presents_index = 0
     presents_last_index = len(presents_to_place)
     while 1:
         priority_pick = self.priority_pick
         new_layer = MaxRectSolver(self.width, self.height)
         try:
             presents_index = new_layer.solve(presents_to_place,
                                              presents_index, self.scorer,
                                              priority_pick)
             self._add_layer(new_layer)
             print("{} more presents".format(presents_last_index -
                                             presents_index))
             if presents_index == presents_last_index - 1:
                 break
         except NoFit:
             priority_pick -= 10
             assert priority_pick > 1
         if self.make_timer:
             ratio = presents_index / num_total_presents
             print("Time left: {}; End time: {}".format(
                 timer.time_left(ratio), timer.time_end(ratio)))
     print("Solved with total depth {}".format(self.total_depth))
     if self.make_timer:
         print("Time taken: {}".format(timer.time_taken()))
     if self.gc_collect_cycle:
         gc_collect_count += 1
         if gc_collect_count == self.gc_collect_cycle:
             gc_collect_count = 0
             print("GC collect")
             gc.collect()
コード例 #3
0
from maxrect_pack.maxrect_solver import MaxRectSolver
from maxrect_pack.orienter import Orienter
from maxrect_pack.recthelper import random_rects
from maxrect_pack.scorer import scorerBSSF


WIDTH = 1000
HEIGHT = 1000

if __name__ == '__main__':
    rects_to_place = random_rects(WIDTH, HEIGHT, 200, 200, 100)
    solver = MaxRectSolver(WIDTH, HEIGHT)
    solver.solve(Orienter.orient_all(rects_to_place), scorerBSSF, priority_pick=80)
    solver.plot()