For each edge, link it to the vertex types it connects to each other.
485776
def _link_vertex_and_edge_types(self):
        """"""
        for edge_class_name in self._edge_class_names:
            edge_element = self._elements[edge_class_name]

            if (EDGE_SOURCE_PROPERTY_NAME not in edge_element.properties or
                    EDGE_DESTINATION_PROPERTY_NAME not in edge_element.properties):
                if edge_element.abstract:
                    continue
                else:
                    raise AssertionError(u'Found a non-abstract edge class with undefined '
                                         u'endpoint types: {}'.format(edge_element))

            from_class_name = edge_element.properties[EDGE_SOURCE_PROPERTY_NAME].qualifier
            to_class_name = edge_element.properties[EDGE_DESTINATION_PROPERTY_NAME].qualifier

            edge_schema_element = self._elements[edge_class_name]

            # Link from_class_name with edge_class_name
            for from_class in self._subclass_sets[from_class_name]:
                from_schema_element = self._elements[from_class]
                from_schema_element.out_connections.add(edge_class_name)
                edge_schema_element.in_connections.add(from_class)

            # Link edge_class_name with to_class_name
            for to_class in self._subclass_sets[to_class_name]:
                to_schema_element = self._elements[to_class]
                edge_schema_element.out_connections.add(to_class)
                to_schema_element.in_connections.add(edge_class_name)
387767
private void connectToNeighbors(int x, int y ) {
		List<LineSegment2D_F32> lines = grid.get(x,y);

		Iterator<LineSegment2D_F32> iter = lines.iterator();
		while( iter.hasNext() )
		{
			LineSegment2D_F32 l = iter.next();
			boolean connected = false;

			if( connectTry(l,x+1,y) )
				connected = true;
			if( !connected && connectTry(l,x+1,y+1) )
				connected = true;
			if( !connected && connectTry(l,x,y+1) )
				connected = true;
			if( !connected && connectTry(l,x-1,y+1) )
				connected = true;

			// the line was added to the connecting grid
			// remove it to avoid double counting the line
			if( connected )
				iter.remove();
		}
	}
1358416
function _addGraphEdges(db, graph, callback) {

  // Counters
  let done = 0;
  let count = graph.vertexCount();

  // Loop through each Vertex in the Graph
  for ( let [stopId, stop] of graph ) {

    // Get the Edges for the Vertex
    _getStopEdges(db, stopId, function(err, edges) {

      // Database Query Error
      if ( err ) {
        return callback(err);
      }

      // Add each edge to the Graph
      for ( let i = 0; i < edges.length; i++ ) {
        graph.ensureEdge(stopId, edges[i]);
        graph.ensureEdge(edges[i], stopId);
      }

      // Finish the Vertex
      _finish();

    });

  }

  // Keep track of finished vertices
  function _finish() {
    done++;
    if ( done === count ) {
      return callback(null, graph);
    }
  }

}
61979
def chk_edges(self):
        """"""
        goids = set(self.go2obj)
        self.chk_edges_nodes(self.edges, goids, "is_a")
        for reltype, edges in self.edges_rel.items():
            self.chk_edges_nodes(edges, goids, reltype)
452541
function(graph, opt) {

        opt = opt || {};

        var glGraphType = joint.util.pick(opt, 'directed', 'compound', 'multigraph');
        var glGraph = new graphlib.Graph(glGraphType);
        var setNodeLabel = opt.setNodeLabel || joint.util.noop;
        var setEdgeLabel = opt.setEdgeLabel || joint.util.noop;
        var setEdgeName = opt.setEdgeName || joint.util.noop;
        var collection = graph.get('cells');

        for (var i = 0, n = collection.length; i < n; i++) {

            var cell = collection.at(i);
            if (cell.isLink()) {

                var source = cell.get('source');
                var target = cell.get('target');

                // Links that end at a point are ignored.
                if (!source.id || !target.id) break;

                // Note that if we are creating a multigraph we can name the edges. If
                // we try to name edges on a non-multigraph an exception is thrown.
                glGraph.setEdge(source.id, target.id, setEdgeLabel(cell), setEdgeName(cell));

            } else {

                glGraph.setNode(cell.id, setNodeLabel(cell));

                // For the compound graphs we have to take embeds into account.
                if (glGraph.isCompound() && cell.has('parent')) {
                    var parentId = cell.get('parent');
                    if (collection.has(parentId)) {
                        // Make sure the parent cell is included in the graph (this can
                        // happen when the layout is run on part of the graph only).
                        glGraph.setParent(cell.id, parentId);
                    }
                }
            }
        }

        return glGraph;
    }
448138
def links_between(a, b, machine):
    
    ax, ay = a
    bx, by = b
    return set(link for link, (dx, dy) in ((l, l.to_vector()) for l in Links)
               if (ax + dx) % machine.width == bx and
               (ay + dy) % machine.height == by and
               (ax, ay, link) in machine)
38976
private static Graph buildGraph() {
        Graph g = new TinkerGraph();
        //add vertices
        Vertex v1 = g.addVertex("v1");
        Vertex v2 = g.addVertex("v2");
        Vertex v3 = g.addVertex("v3");
        Vertex v4 = g.addVertex("v4");
        Vertex v5 = g.addVertex("v5");
        Vertex v6 = g.addVertex("v6");

        //add edges labeled with costs
        Edge e1 = g.addEdge("e1", v1, v2, "(7, 1)");
        e1.setProperty("c1", 7);
        e1.setProperty("c2", 1);

        Edge e2 = g.addEdge("e2", v1, v3, "(1, 4)");
        e2.setProperty("c1", 1);
        e2.setProperty("c2", 4);

        Edge e3 = g.addEdge("e3", v1, v4, "(2, 1)");
        e3.setProperty("c1", 2);
        e3.setProperty("c2", 1);

        Edge e4 = g.addEdge("e4", v2, v4, "(1, 1)");
        e4.setProperty("c1", 1);
        e4.setProperty("c2", 1);

        Edge e5 = g.addEdge("e5", v2, v6, "(2, 1)");
        e5.setProperty("c1", 2);
        e5.setProperty("c2", 1);

        Edge e6 = g.addEdge("e6", v3, v4, "(1, 1)");
        e6.setProperty("c1", 1);
        e6.setProperty("c2", 1);

        Edge e7 = g.addEdge("e7", v4, v5, "(3, 2)");
        e7.setProperty("c1", 3);
        e7.setProperty("c2", 2);

        Edge e8 = g.addEdge("e8", v4, v6, "(4, 8)");
        e8.setProperty("c1", 4);
        e8.setProperty("c2", 8);

        Edge e9 = g.addEdge("e9", v5, v6, "(1, 1)");
        e9.setProperty("c1", 1);
        e9.setProperty("c2", 1);

        return g;
    }
99643
def link_(a, nodes, b)
      if nodes.empty?
        if a.nil?
          @first = b
        else
          a.instance_variable_set(:@next, b)
        end
        if b.nil?
          @last = a
        else
          b.instance_variable_set(:@prev, a)
        end
      else
        # connect `a' and `b'
        first = nodes.first
        if a.nil?
          @first = first
        else
          a.instance_variable_set(:@next, first)
        end
        last = nodes.last
        if b.nil?
          @last = last
        else
          b.instance_variable_set(:@prev, last)
        end

        # connect `nodes'
        if nodes.length == 1
          node = nodes[0]
          node.instance_variable_set(:@prev, a)
          node.instance_variable_set(:@next, b)
        else
          first.instance_variable_set(:@next, nodes[ 1])
          first.instance_variable_set(:@prev, a)
          last. instance_variable_set(:@prev, nodes[-2])
          last. instance_variable_set(:@next, b)
          (1...nodes.length-1).each do |i|
            n = nodes[i]
            n.instance_variable_set(:@prev, nodes[i-1])
            n.instance_variable_set(:@next, nodes[i+1])
          end
        end
      end
    end
1074961
void connectIntLinks(MeshTile tile) {
        if (tile == null) {
            return;
        }

        long base = getPolyRefBase(tile);

        for (int i = 0; i < tile.data.header.polyCount; ++i) {
            Poly poly = tile.data.polys[i];
            poly.firstLink = DT_NULL_LINK;

            if (poly.getType() == Poly.DT_POLYTYPE_OFFMESH_CONNECTION) {
                continue;
            }

            // Build edge links backwards so that the links will be
            // in the linked list from lowest index to highest.
            for (int j = poly.vertCount - 1; j >= 0; --j) {
                // Skip hard and non-internal edges.
                if (poly.neis[j] == 0 || (poly.neis[j] & DT_EXT_LINK) != 0) {
                    continue;
                }

                int idx = allocLink(tile);
                Link link = tile.links.get(idx);
                link.ref = base | (poly.neis[j] - 1);
                link.edge = j;
                link.side = 0xff;
                link.bmin = link.bmax = 0;
                // Add to linked list.
                link.next = poly.firstLink;
                poly.firstLink = idx;
            }
        }
    }
294876
private void dfs(Visitor visitor, int v, int[] cc, int id) {
        visitor.visit(v);
        cc[v] = id;
        for (Edge edge : graph[v]) {
            int t = edge.v2;
            if (!digraph && t == v) {
                t = edge.v1;
            }

            if (cc[t] == -1) {
                dfs(visitor, t, cc, id);
            }
        }
    }
444035
def add_graph(self, other):
        
        self.add_nodes( n for n in other.nodes() if not n in self.nodes() )
        
        for each_node in other.nodes():
            for each_edge in other.neighbors(each_node):
                if (not self.has_edge((each_node, each_edge))):
                    self.add_edge((each_node, each_edge))
430872
def _build_graph(self):
        
        self._graph.add_nodes_from(self.tasks)
        for node1 in self._graph.nodes:
            for node2 in self._graph.nodes:
                for input_file in node1.inputs:
                    for output_file in node2.outputs:
                        if output_file == input_file:
                            self._graph.add_edge(node2, node1)
        for order, task in enumerate(topological_sort(self._graph)):
            task.predecessors = self._graph.predecessors(task)
            task.order = order
248120
def connect(self, f, t):
        
        if t not in self._vertices:
            raise KeyError(t)
        self._forwards[f].add(t)
        self._backwards[t].add(f)
17411
def connect_edges_pd(graph):
    
    edges = graph.dframe()
    edges.index.name = 'graph_edge_index'
    edges = edges.reset_index()
    nodes = graph.nodes.dframe()
    src, tgt = graph.kdims
    x, y, idx = graph.nodes.kdims[:3]

    df = pd.merge(edges, nodes, left_on=[src.name], right_on=[idx.name])
    df = df.rename(columns={x.name: 'src_x', y.name: 'src_y'})

    df = pd.merge(df, nodes, left_on=[tgt.name], right_on=[idx.name])
    df = df.rename(columns={x.name: 'dst_x', y.name: 'dst_y'})
    df = df.sort_values('graph_edge_index').drop(['graph_edge_index'], axis=1)

    edge_segments = []
    for i, edge in df.iterrows():
        start = edge['src_x'], edge['src_y']
        end = edge['dst_x'], edge['dst_y']
        edge_segments.append(np.array([start, end]))
    return edge_segments
1104538
def connected_edges(G, nodes):
    
    nodes_in_G = collections.deque()
    for node in nodes:
        if not G.has_node(node):
            continue
        nodes_in_G.extend(nx.node_connected_component(G, node))
    edges = G.subgraph(nodes_in_G).edges()
    return edges
522223
def get_connected_components_as_subgraphs(graph):
    
    components = get_connected_components(graph)

    list_of_graphs = []

    for c in components:
        edge_ids = set()
        nodes = [graph.get_node(node) for node in c]
        for n in nodes:
            # --Loop through the edges in each node, to determine if it should be included
            for e in n['edges']:
                # --Only add the edge to the subgraph if both ends are in the subgraph
                edge = graph.get_edge(e)
                a, b = edge['vertices']
                if a in c and b in c:
                    edge_ids.add(e)
        # --Build the subgraph and add it to the list
        list_of_edges = list(edge_ids)
        subgraph = make_subgraph(graph, c, list_of_edges)
        list_of_graphs.append(subgraph)

    return list_of_graphs
1224394
def setedge(delta, is_multigraph, graph, orig, dest, idx, exists):
    """"""
    if is_multigraph(graph):
        delta.setdefault(graph, {}).setdefault('edges', {})\
            .setdefault(orig, {}).setdefault(dest, {})[idx] = bool(exists)
    else:
        delta.setdefault(graph, {}).setdefault('edges', {})\
            .setdefault(orig, {})[dest] = bool(exists)