def create_tracks_from_points(name, graph, unique_pos, short, grid_width, grid_height): xs, ys = points.decompose_points_into_tracks( unique_pos, grid_width, grid_height, right_only=True, ) tracks_list, track_connections = tracks.make_tracks( xs, ys, unique_pos, grid_width, grid_height) tracks_model = tracks.Tracks(tracks_list, track_connections) nodes = [] for idx, track in enumerate(tracks_list): nodes.append( graph.add_track( track=track, segment_id=graph.segments[0].id, capacity=1, name="{}{}".format(name, idx), )) for aidx, bidx in track_connections: graph.add_edge( src_node=nodes[aidx], sink_node=nodes[bidx], switch_id=short, ) graph.add_edge( src_node=nodes[bidx], sink_node=nodes[aidx], switch_id=short, ) return nodes, tracks_model
def form_tracks(conn): c = conn.cursor() c.execute('SELECT count(pkey) FROM node WHERE classification == ?;', (NodeClassification.CHANNEL.value, )) num_nodes = c.fetchone()[0] tracks_to_insert = [] with progressbar.ProgressBar(max_value=num_nodes) as bar: bar.update(0) c2 = conn.cursor() for idx, (node, ) in enumerate( c.execute( """ SELECT pkey FROM node WHERE classification == ?; """, (NodeClassification.CHANNEL.value, ))): bar.update(idx) unique_pos = set() for wire_pkey, grid_x, grid_y in c2.execute( """ WITH wires_from_node(wire_pkey, tile_pkey) AS ( SELECT pkey, tile_pkey FROM wire WHERE node_pkey = ? ) SELECT wires_from_node.wire_pkey, tile.grid_x, tile.grid_y FROM tile INNER JOIN wires_from_node ON tile.pkey = wires_from_node.tile_pkey; """, (node, )): unique_pos.add((grid_x, grid_y)) xs, ys = points.decompose_points_into_tracks(unique_pos) tracks_list, track_connections = tracks.make_tracks( xs, ys, unique_pos) tracks_model = tracks.Tracks(tracks_list, track_connections) tracks_to_insert.append( [node, tracks_list, track_connections, tracks_model]) insert_tracks(conn, tracks_to_insert)
def form_tracks(self, grid): connected_tiles = set() for tile, wire in self.node: connected_tiles.add(grid.loc_of_tilename(tile)) unique_pos = set() for tile, wire in self.node: loc = grid.loc_of_tilename(tile) unique_pos.add((loc.grid_x, loc.grid_y)) xs, ys = points.decompose_points_into_tracks(unique_pos) self.tracks, self.track_connections = tracks.make_tracks( xs, ys, unique_pos) self.wire_connections = {} self.tracks_model = tracks.Tracks(self.tracks, self.track_connections) for tile, wire in self.node: loc = grid.loc_of_tilename(tile) connections = list( self.tracks_model.get_tracks_for_wire_at_coord( (loc.grid_x, loc.grid_y))) assert len(connections) > 0 self.wire_connections[(tile, wire)] = connections[0][0]
def create_track(node, unique_pos): xs, ys = points.decompose_points_into_tracks(unique_pos) tracks_list, track_connections = tracks.make_tracks(xs, ys, unique_pos) tracks_model = tracks.Tracks(tracks_list, track_connections) return [node, tracks_list, track_connections, tracks_model]