Returns a copy of this bipartite graph with the given edge and its adjacent nodes removed.
186510
def without_nodes(self, edge: Edge) -> 'BipartiteGraph[TLeft, TRight, TEdgeValue]':
        """"""
        return BipartiteGraph(((n1, n2), v) for (n1, n2), v in self._edges.items() if n1 != edge[0] and n2 != edge[1])
823663
def move_edges(self,n1,n2):
      
      #Traverse edges to find incoming with n1
      incoming = []
      for e in self._edges.values():
         if e.node2.id == n1.id: incoming.append(e)
      #Traverse edges to find outgoing from n1
      outgoing = []
      for e in self._edges.values():
         if e.node1.id == n1.id: outgoing.append(e)
      #Make new edges to the new target
      for e in incoming:
         if e.node1.id == n2.id: continue # skip self
         newedge = Edge(e.node1,n2,payload_list=n2.payload_list+n1.payload_list)
         self.add_edge(newedge)
      for e in outgoing:
         if e.node2.id == n2.id: continue # skip self
         newedge = Edge(n2,e.node2,payload_list=n2.payload_list+n1.payload_list)
         self.add_edge(newedge)
      #now remove the edges that got transfered
      for e in incoming: self.remove_edge(e)
      for e in outgoing: self.remove_edge(e)
1329215
def get_undirected(G):
    

    start_time = time.time()

    # set from/to nodes before making graph undirected
    G = G.copy()
    for u, v, k, data in G.edges(keys=True, data=True):
        G.edges[u, v, k]['from'] = u
        G.edges[u, v, k]['to'] = v
        
        # add geometry if it doesn't already exist, to retain parallel
        # edges' distinct geometries
        if 'geometry' not in data:
            point_u = Point((G.nodes[u]['x'], G.nodes[u]['y']))
            point_v = Point((G.nodes[v]['x'], G.nodes[v]['y']))
            data['geometry'] = LineString([point_u, point_v])

    # update edge keys so we don't retain only one edge of sets of parallel edges
    # when we convert from a multidigraph to a multigraph
    G = update_edge_keys(G)

    # now convert multidigraph to a multigraph, retaining all edges in both
    # directions for now, as well as all graph attributes
    H = nx.MultiGraph()
    H.add_nodes_from(G.nodes(data=True))
    H.add_edges_from(G.edges(keys=True, data=True))
    H.graph = G.graph
    H.name = G.name

    # the previous operation added all directed edges from G as undirected
    # edges in H. this means we have duplicate edges for every bi-directional
    # street. so, look through the edges and remove any duplicates
    duplicate_edges = []
    for u, v, key, data in H.edges(keys=True, data=True):

        # if we haven't already flagged this edge as a duplicate
        if not (u, v, key) in duplicate_edges:

            # look at every other edge between u and v, one at a time
            for key_other in H[u][v]:

                # don't compare this edge to itself
                if not key_other == key:

                    # compare the first edge's data to the second's to see if
                    # they are duplicates
                    data_other = H.edges[u, v, key_other]
                    if is_duplicate_edge(data, data_other):

                        # if they match up, flag the duplicate for removal
                        duplicate_edges.append((u, v, key_other))

    H.remove_edges_from(duplicate_edges)
    log('Made undirected graph in {:,.2f} seconds'.format(time.time() - start_time))

    return H
706637
def remove_duplicate_edges_undirected(udg):
    """"""
    # With undirected edges, we need to hash both combinations of the to-from node ids, since a-b and b-a are equivalent
    # --For aesthetic, we sort the edge ids so that lower edges ids are kept
    lookup = {}
    edges = sorted(udg.get_all_edge_ids())
    for edge_id in edges:
        e = udg.get_edge(edge_id)
        tpl_a = e['vertices']
        tpl_b = (tpl_a[1], tpl_a[0])
        if tpl_a in lookup or tpl_b in lookup:
            udg.delete_edge_by_id(edge_id)
        else:
            lookup[tpl_a] = edge_id
            lookup[tpl_b] = edge_id
986784
def edges_to_path(edges):
    
    if not edges:
        return None

    G = edges_to_graph(edges)
    path = nx.topological_sort(G)
    return path
1019817
def create_copy_without_data(G):
    """"""
    H = nx.Graph()
    for i in H.nodes_iter():
        H.node[i] = {}
    return H
530233
def graph(self, ig):
        

        res = copy.copy(self)
        res._edges = ig
        res._nodes = None
        return res
794298
def copy(self):
        
        # use the geometries copy method to
        # allow them to handle references to unpickle-able objects
        geometry = {n: g.copy() for n, g in self.geometry.items()}
        # create a new scene with copied geometry and graph
        copied = Scene(geometry=geometry,
                       graph=self.graph.copy())
        return copied
199125
def remove_edge(self, u, v, key=None):
        
        try:
            d = self.adj[u][v]
        except KeyError:
            raise NetworkXError(
                "The edge {}-{} is not in the graph.".format(u, v)
            )
        if key is None:
            d.popitem()
        else:
            try:
                del d[key]
            except KeyError:
                raise NetworkXError(
                    "The edge {}-{} with key {} is not in the graph.".format
                    (u, v, key)
                )
        if len(d) == 0:
            del self.succ[u][v]
473519
def edges
      return_edges = Array.new(3)
      return_edges[0] = FiniteLine.new(self.vertices[0], self.vertices[1])
      return_edges[1] = FiniteLine.new(self.vertices[1], self.vertices[2])
      return_edges[2] = FiniteLine.new(self.vertices[2], self.vertices[0])
      return return_edges
    end
1062136
public static <K, VV, EV> Graph<K, VV, EV> fromDataSet(DataSet<Vertex<K, VV>> vertices,
			DataSet<Edge<K, EV>> edges, ExecutionEnvironment context) {

		return new Graph<>(vertices, edges, context);
	}
422294
def equiv_graph(self):
        
        eg = nx.Graph()
        for (u,v,d) in self.get_graph().edges(data=True):
            if d['pred'] == 'equivalentTo':
                eg.add_edge(u,v)
        return eg
383279
def graph_simplify(G):
    
    spurs = []
    path_nodes = []
    for k, d in G.degree().iteritems():
        if d == 1:
            spurs.append(k)
        elif d == 2:
            path_nodes.append(k)

    logging.debug("Remove {0} spurs.".format(len(spurs)))
    G.remove_nodes_from(spurs)

    SG = G.subgraph(path_nodes)
    cc = nx.connected_components(SG)
    for c in cc:
        if len(c) == 1:
            continue
        c = set(c)
        neighbors = set()
        for x in c:
            neighbors |= set(G.neighbors(x))
        neighbors -= c
        newtag = list(c)[0] + "*"
        for n in neighbors:
            G.add_edge(newtag, n)
        G.remove_nodes_from(c)
    logging.debug("Contract {0} path nodes into {1} nodes.".\
                    format(len(path_nodes), len(cc)))
135876
def delete_edge_by_id(self, edge_id):
        """"""
        edge = self.get_edge(edge_id)

        # Remove the edge from the "from node"
        # --Determine the from node
        from_node_id = edge['vertices'][0]
        from_node = self.get_node(from_node_id)

        # --Remove the edge from it
        from_node['edges'].remove(edge_id)

        # Remove the edge from the "to node"
        to_node_id = edge['vertices'][1]
        to_node = self.get_node(to_node_id)

        # --Remove the edge from it
        to_node['edges'].remove(edge_id)

        # Remove the edge from the edge list
        del self.edges[edge_id]

        self._num_edges -= 1
384686
public Graph<K, VV, EV> union(Graph<K, VV, EV> graph) {
		DataSet<Vertex<K, VV>> unionedVertices = graph
			.getVertices()
			.union(this.getVertices())
				.name("Vertices")
			.distinct()
				.name("Vertices");

		DataSet<Edge<K, EV>> unionedEdges = graph
			.getEdges()
			.union(this.getEdges())
				.name("Edges");

		return new Graph<>(unionedVertices, unionedEdges, this.context);
	}
884978
def new_edge(self, node_a, node_b, cost=1):
        """"""
        edge_id = super(UndirectedGraph, self).new_edge(node_a, node_b, cost)
        self.nodes[node_b]['edges'].append(edge_id)
        return edge_id
1266598
def _create_complete_graph(node_ids):
    
    g = nx.Graph()
    g.add_nodes_from(node_ids)
    for (i, j) in combinations(node_ids, 2):
        g.add_edge(i, j)
    return g