示例#1
0
 def __init__(self,
              modules: List[Module],
              seed=None,
              random_initial_tree=True):
     self.modules = modules
     if random_initial_tree:
         self.tree = TreeBuilder.random_tree(modules, seed=seed)
     else:
         self.tree = TreeBuilder.balanced_tree(modules)
     random.seed(seed)
示例#2
0
 def test_from_modules(self):
     modules = [
         Module(str(i), ModuleType.HARD, Dimensions(100, 100),
                Vector2(0, 0)) for i in range(20)
     ]
     t = TreeBuilder.random_tree(modules, seed=1)
     t.print()
示例#3
0
    def test_move(self):
        modules = [Module(str(i), ModuleType.HARD, Dimensions(100, 100), Vector2(0, 0)) for i in range(20)]
        t = TreeBuilder.random_tree(modules, seed=1)

        random.seed(1)
        logging.getLogger("pyfloorplanner").setLevel(logging.DEBUG)

        t.move()
示例#4
0
    def test_remove_root(self):
        modules = [Module(str(i), ModuleType.HARD, Dimensions(100, 100), Vector2(0, 0)) for i in range(20)]
        t = TreeBuilder.random_tree(modules, seed=1)

        random.seed(2)
        n = next(x for x in t.nodes if x.id == 19)

        print(f"removing node {n.id}")
        logging.getLogger("pyfloorplanner").setLevel(logging.DEBUG)

        t.remove(n)
示例#5
0
    def test_swap_descendant_root(self):
        modules = [Module(str(i), ModuleType.HARD, Dimensions(100, 100), Vector2(0, 0)) for i in range(20)]
        t = TreeBuilder.random_tree(modules, seed=1)

        random.seed(1)
        logging.getLogger("pyfloorplanner").setLevel(logging.DEBUG)

        u = next(x for x in t.nodes if x.id == 18)
        v = next(x for x in t.nodes if x.id == 19)

        t.apply(Swap(t, u, v))
示例#6
0
    def test_calc_area(self):
        modules = [Module(str(i), ModuleType.HARD, Dimensions(100, 100), Vector2(0, 0)) for i in range(20)]
        t = TreeBuilder.random_tree(modules, seed=1)

        random.seed(1)

        print('T after construction')
        t.print()

        t.calc_area()

        fp = Floorplan(t)
        fp.plot()
示例#7
0
    def test_plot(self, seed=3):
        modules = [
            Module(str(i), ModuleType.HARD, Dimensions(100, 100),
                   Vector2(0, 0)) for i in range(10)
        ]
        t = TreeBuilder.random_tree(modules, seed=seed)

        random.seed(1)

        t.calc_area()

        fp = Floorplan(t)
        fp.plot(draw_tree=True, draw_contour=True, contour_width=5)
示例#8
0
    def test_insert3(self):
        modules = [Module(str(i), ModuleType.HARD, Dimensions(100, 100), Vector2(0, 0)) for i in range(20)]
        t = TreeBuilder.random_tree(modules, seed=1)

        random.seed(1)
        n = Node(Module(str(21), ModuleType.HARD, Dimensions(100, 100), Vector2(0, 0)))
        p = None
        insertLeft = False

        print(f"inserting node {n.id} as root")
        logging.getLogger("pyfloorplanner").setLevel(logging.DEBUG)

        t.nodes.append(n)

        t.insert(n, p, insertLeft)
示例#9
0
    def test_clone(self):
        modules = [Module(str(i), ModuleType.HARD, Dimensions(100, 100), Vector2(0, 0)) for i in range(20)]
        t = TreeBuilder.random_tree(modules, seed=1)

        random.seed(2)
        n = next(x for x in t.nodes if x.id == 18)

        print(f"removing node {n.id}")

        t_clone = t.clone()

        print('T before modification')
        t.print()

        t.remove(n)

        print('T after modification')
        t.print()

        print('T clone')
        t_clone.print()