Example #1
0
def _wire_loc_pair(loc_pair, proto_board):
  """
  Runs a search to connect the given |loc_pair| starting from the given
      |proto_board|. Note that this method sets a very small number of states
      to expand.
  """
  return find_wiring(loc_pairs=[loc_pair], start_proto_board=proto_board,
      mode=MODE_PER_PAIR, order=ORDER_DECREASING, best_first=False,
      filter_wire_lengths=True, max_states_to_expand=70, verbose=False)[0]
Example #2
0
def solve_layout(circuit, resistors_as_components, cost_type, mode, order,
    best_first, filter_wire_lengths, verbose=True):
  """
  Attempts to produce a layout for the given |circuit| and returns a dictionary
      containing data corresponding to the solution, most importantly the key
      'proto_board' mapped to the produced layout. The value will be None if no
      layout could be found. |cost_type| is a parameter for which placement cost
      to use, see circuit_piece_placement.py. |mode| and |order| are parameters
      for how the wiring should be solved, see find_proto_board_wiring.py.
  """
  if verbose:
    print 'Resistors as components: %s' % resistors_as_components
    print 'Placement cost type: %s' % cost_type
    print 'Wiring mode: %s, order: %s' % (mode, order)
    print 'Search: %s' % ('Best First' if best_first else 'A*')
    print 'Filter wire lengths: %s' % filter_wire_lengths
    print
  solve_data = defaultdict(lambda: None)
  try:
    placement_start = clock()
    placement, resistor_node_pairs = get_piece_placement(circuit,
        resistors_as_components, cost_type, verbose)
    solve_data['placement_time'] = clock() - placement_start
    solve_data['placement'] = placement
    solve_data['resistor_node_pairs'] = resistor_node_pairs
    if placement is None:
      print "Pieces don't fit on the board."
      return solve_data
    proto_board, nodes, loc_pairs = _setup(placement, resistor_node_pairs)
    solve_data['nodes'] = nodes
    solve_data['loc_pairs'] = loc_pairs
    wiring_start = clock()
    proto_board, num_expanded = find_wiring(loc_pairs=loc_pairs,
        start_proto_board=proto_board, mode=mode, order=order,
        best_first=best_first, filter_wire_lengths=filter_wire_lengths,
        verbose=verbose)
    solve_data['wiring_time'] = clock() - wiring_start
    solve_data['proto_board'] = proto_board
    solve_data['num_expanded'] = num_expanded
  except:
    print_exc(file=stdout)
  return solve_data