def generate_case(n_nodes, n_nets, x_min=X_MIN, x_max=X_MAX, y_min=Y_MIN, y_max=Y_MAX, label_prefix="", seed=None, pairs=False): if label_prefix != '': label_prefix += '_' if seed is not None: random.seed(seed) rectangles, contours = [], [] if pairs: n_nodes = 2 * n_nets for i in range(n_nodes): # pick material mat = random.choice(MAT) # width width = dr.material_width[mat] # spacing spacing = 4 overlapping = True iteration = 0 while overlapping or iteration == LIMIT: iteration += 1 # generate position pos = (random.randint(x_min, x_max), random.randint(y_min, y_max)) # net net = i // 2 if pairs else random.randint(0, n_nets) net_name = "{}{}".format(label_prefix, net) # generate rectangle rect = ds.Rect(pos[0], pos[1], width, width, mat, net_name) overlapping = False for contour in contours: if contour.overlaps(rect): overlapping = True if not overlapping: rectangles.append(rect) contour = ds.Rect(rect.x - spacing, rect.y - spacing, rect.w + 2 * spacing, rect.h + 2 * spacing, rect.m, rect.l) contours.append(contour) print("Done generating.") return rectangles
def test_route(): cp1 = ds.Component('cp1') n1 = ds.Rect(0,0,4,4,'pc','net') cp1.add_node(n1) cp2 = ds.Component('cp2') n2 = ds.Rect(0,10,4,4,'pc','net') cp2.add_node(n2) pr.route_components(cp1,cp2)
def test_generate(): cp1 = ds.Component('cp1') n1 = ds.Rect(0,0,4,4,'pc','net') cp1.add_node(n1) cp2 = ds.Component('cp2') n2 = ds.Rect(0,10,4,4,'pc','net') cp2.add_node(n2) for r in pr.generate_routes(cp1,cp2,False): print(r.cost)
def get_mbb_rect(label, layout): """Wrap the manhattan bounding box as a rect """ bottom_left, top_right = get_mbb(label, layout) return ds.Rect(bottom_left[0], bottom_left[1], top_right[0] - bottom_left[0], top_right[1] - bottom_left[1], None)
def get_mbb(pair): """Returns manhattan bounding box of the pair as a Rect """ cp1, cp2 = pair x0, x1 = min(cp1.x0, cp2.x0), max(cp1.x1, cp2.x1) y0, y1 = min(cp1.y0, cp2.y0), max(cp1.y1, cp2.y1) return ds.Rect(x0, y0, x1 - x0, y1 - y0, None)
def get_bounding_box(self): """Returns bounding box of layout (as rect) """ x0, x1 = None, None y0, y1 = None, None # get bounding box for r in self.rects: if x0 is None or r.x < x0: x0 = r.x if x1 is None or r.x1 > x1: x1 = r.x if y0 is None or r.y < y0: y0 = r.y if y1 is None or r.y1 > y1: y1 = r.y1 # expand by scale factor w, h = int((x1 - x0) * Layout.BB_SF), int((y1 - y0) * Layout.BB_SF) return ds.Rect(x0, y0, w, h, None)
#!/usr/bin/env python3 ''' test_elevate.py ''' import sys import os sys.path.append(os.path.abspath('../src')) import data_structures as ds from layout import Layout node = ds.Rect(0, 0, 4, 4, 'm1', 'net') inputs = {'input_mode': 'explicit', 'layers': 10, 'rects': [node]} layout = Layout(inputs) layout.emit_tcl('test_elevate.tcl')