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)
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()
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()
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)
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))
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()
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)
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)
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()