def main(): # load command-line arguments parser = argparse.ArgumentParser() parser.add_argument('--json') parser.add_argument('--units', default='inch') args = parser.parse_args() # read board placement from SMT-PCB with open(args.json, 'r') as f: json_dict = json.load(f) board_edge = json_dict['board_edge'] width, height = BoardTools.get_board_dims(board_edge) # define unit conversion if args.units.lower() in ['in', 'inch', 'inches']: conv = lambda x: 0.0393701 * x area_str = 'in^2' if args.units.lower() in ['mm', 'mms', 'millimeters']: conv = lambda x: x area_str = 'mm^2' if args.units.lower() in ['mil', 'mils']: conv = lambda x: 39.3701 * x area_str = 'mil^2' area = conv(width) * conv(height) # print summary print '############' print 'Summary' print 'Board area: %0.3f %s' % (area, area_str) print '############'
def place_rects(args): # read in SMT input with open(args.json, 'r') as f: json_dict = json.load(f) # create the placer grid width, height = BoardTools.get_board_dims(json_dict['board_edge']) grid = PlaceGrid(width=width, height=height, dx=args.dx, dy=args.dy) fab = design.Fabric(grid.place_dims) # Create the design comps_list = grid.make_comps_list(json_dict['module_dict']) routing_list = grid.make_routing_list(json_dict['routing_list']) d = design.Design(comps_list, routing_list, fab, position.RotIntXY) # Add constraints d.add_constraint_generator('no_overlap', constraints.no_overlap) d.add_pad_cg('max_dist', constraints.pad_max_dists) # create the solver if args.optimize: d.add_pad_opt('min_total_dist', constraints.pad_dists) s = z3.Optimize() else: s = z3.Solver() # add the constraints to the solver s.add(d.constraints) # set up the optimization, if desired if args.optimize: for func in d.r_opt_param: s.minimize(func) with open('freeduino.smt', 'w') as f: f.write(s.to_smt2()) # run the placement start = time.time() result = s.check() end = time.time() place_time = end - start print('Placement took', place_time, 'seconds.') if args.dout: with open(args.dout, 'a+') as f: f.write(str(place_time) + '\n') if result == z3.unsat: raise Exception('Problem is unsat.') return d, s.model()