Generate a listing of each vertex's immedate neighbours in an undirected
    interpretation of a graph.

    Returns
    -------
    {vertex: {vertex: weight, ...}), ...}
488398
def _get_vertices_neighbours(nets):
    
    zero_fn = (lambda: 0)
    vertices_neighbours = defaultdict(lambda: defaultdict(zero_fn))
    for net in nets:
        if net.weight != 0:
            for sink in net.sinks:
                vertices_neighbours[net.source][sink] += net.weight
                vertices_neighbours[sink][net.source] += net.weight
    return vertices_neighbours
1030905
def __calculate_edge_weights(dfs_data):
    """"""
    graph = dfs_data['graph']

    weights = {}
    for edge_id in graph.get_all_edge_ids():
        edge_weight = __edge_weight(edge_id, dfs_data)
        weights[edge_id] = edge_weight

    return weights
190771
def dijkstra(G, start, weight='weight'):
    
    if start not in G.vertices:
        raise GraphInsertError("Vertex %s doesn't exist." % (start,))
    visited = {start: 0}
    path = {}
    vertices = set(G.vertices.keys())
    while vertices:
        min_vertex = None
        for vertex in vertices:
            if vertex in visited:
                if min_vertex is None or visited[vertex] < visited[min_vertex]:
                    min_vertex = vertex
        if min_vertex is None:
            break
        vertices.remove(min_vertex)
        current_weight = visited[min_vertex]
        for edge in G.vertices[min_vertex]:
            edge_weight = current_weight + G.edges[(min_vertex, edge)][weight]
            if edge not in visited or edge_weight < visited[edge]:
                visited[edge] = edge_weight
                path[edge] = min_vertex
    return visited, path
120595
def _SGraphFromJsonTree(json_str):
    
    g = json.loads(json_str)
    vertices = [_Vertex(x['id'],
                dict([(str(k), v) for k, v in _six.iteritems(x) if k != 'id']))
                                                      for x in g['vertices']]
    edges = [_Edge(x['src'], x['dst'],
             dict([(str(k), v) for k, v in _six.iteritems(x) if k != 'src' and k != 'dst']))
                                                      for x in g['edges']]
    sg = _SGraph().add_vertices(vertices)
    if len(edges) > 0:
        sg = sg.add_edges(edges)
    return sg
628091
def edges(self):
        # TODO: check docstring
        
        for i in sorted(self._matrix.keys(), key=lambda x:x.name()):
            for j in sorted(self._matrix[i].keys(), key=lambda x:x.name()):
                if i != j:
                    yield (i, j)
1285814
def get_vertices_from_edge_list(graph, edge_list):
    
    node_set = set()
    for edge_id in edge_list:
        edge = graph.get_edge(edge_id)
        a, b = edge['vertices']
        node_set.add(a)
        node_set.add(b)

    return list(node_set)
229407
def connected_subgraphs(self, directed=True, ordered=False):
    '''
    '''
    num_ccs, labels = self.connected_components(directed=directed)
    # check the trivial case first
    if num_ccs == 1:
      yield self
      raise StopIteration
    if ordered:
      # sort by descending size (num vertices)
      order = np.argsort(np.bincount(labels))[::-1]
    else:
      order = range(num_ccs)

    # don't use self.subgraph() here, because we can reuse adj
    adj = self.matrix('dense', 'csr', 'csc')
    for c in order:
      mask = labels == c
      sub_adj = adj[mask][:,mask]
      yield self.__class__.from_adj_matrix(sub_adj)
680969
def get_adjacent_vertices(source)
      adjacent_array = []
      if @edges.key?(source)
        adjacent_array = @edges[source].map { |dst, _weight| dst }
      end
      Set.new(adjacent_array)
    end
566378
def all_edges_with_verts(self, v_indices, as_boolean=False):
        '''
        
        '''
        included_vertices = np.zeros(self.v.shape[0], dtype=bool)
        included_vertices[v_indices] = True
        edges_with_verts = included_vertices[self.e].all(axis=1)
        if as_boolean:
            return edges_with_verts
        return np.nonzero(edges_with_verts)[0]
980458
def find_neighbors(vertex_array)
      vertex_array_check(vertex_array)
      neighbors = []
      vertex_array.each do |vertex|
        @faces.each do |face|
          neighbors << face if face.vertices.include?(vertex)
        end
      end
      neighbors.uniq
    end
854852
function getSubjectBarycenter(subject){

	var weighted_number_of_edges = 0;
	var number_of_edges = 0;
	for( var o = 1; o <= object_vector.length; o++ ){
	    if( relation_matrix[object_vector[o -1].id()] &&
		relation_matrix[object_vector[o -1].id()][subject.id()]){
		weighted_number_of_edges += o;
		number_of_edges++;
	    }
	}
	// The '-1' is to offset the indexing.
	return ( weighted_number_of_edges / number_of_edges ) -1;
    }
873063
def children(self, vertex):
        
        return [self.head(edge) for edge in self.out_edges(vertex)]
585453
def neighbors(self, node_id):
        """"""
        node = self.get_node(node_id)
        flattened_nodes_list = []
        for a, b in [self.get_edge(edge_id)['vertices'] for edge_id in node['edges']]:
            flattened_nodes_list.append(a)
            flattened_nodes_list.append(b)
        node_set = set(flattened_nodes_list)
        if node_id in node_set:
            node_set.remove(node_id)
        return [nid for nid in node_set]
248973
function () {
        if (!this.vertexCount) {
            return;
        }

        var indices = this.indices;
        var attributes = this.attributes;
        var positions = attributes.position.value;
        var normals = attributes.normal.value;

        if (!normals || normals.length !== positions.length) {
            normals = attributes.normal.value = new vendor.Float32Array(positions.length);
        }
        else {
            // Reset
            for (var i = 0; i < normals.length; i++) {
                normals[i] = 0;
            }
        }

        var p1 = vec3Create();
        var p2 = vec3Create();
        var p3 = vec3Create();

        var v21 = vec3Create();
        var v32 = vec3Create();

        var n = vec3Create();

        var len = indices ? indices.length : this.vertexCount;
        var i1, i2, i3;
        for (var f = 0; f < len;) {
            if (indices) {
                i1 = indices[f++];
                i2 = indices[f++];
                i3 = indices[f++];
            }
            else {
                i1 = f++;
                i2 = f++;
                i3 = f++;
            }

            vec3Set$2(p1, positions[i1*3], positions[i1*3+1], positions[i1*3+2]);
            vec3Set$2(p2, positions[i2*3], positions[i2*3+1], positions[i2*3+2]);
            vec3Set$2(p3, positions[i3*3], positions[i3*3+1], positions[i3*3+2]);

            vec3.sub(v21, p1, p2);
            vec3.sub(v32, p2, p3);
            vec3.cross(n, v21, v32);
            // Already be weighted by the triangle area
            for (var i = 0; i < 3; i++) {
                normals[i1*3+i] = normals[i1*3+i] + n[i];
                normals[i2*3+i] = normals[i2*3+i] + n[i];
                normals[i3*3+i] = normals[i3*3+i] + n[i];
            }
        }

        for (var i = 0; i < normals.length;) {
            vec3Set$2(n, normals[i], normals[i+1], normals[i+2]);
            vec3.normalize(n, n);
            normals[i++] = n[0];
            normals[i++] = n[1];
            normals[i++] = n[2];
        }
        this.dirty();
    }
549315
def _helper(result,
            graph,
            number_edges_remaining: int,
            node_blacklist: Set[BaseEntity],
            invert_degrees: Optional[bool] = None,
            ):
    
    original_node_count = graph.number_of_nodes()

    log.debug('adding remaining %d edges', number_edges_remaining)
    for _ in range(number_edges_remaining):

        source, possible_step_nodes, c = None, set(), 0
        while not source or not possible_step_nodes:
            source = get_random_node(result, node_blacklist, invert_degrees=invert_degrees)

            c += 1
            if c >= original_node_count:
                log.warning('infinite loop happening')
                log.warning('source: %s', source)
                log.warning('no grow: %s', node_blacklist)
                return  # Happens when after exhausting the connected components. Try increasing the number seed edges

            if source is None:
                continue  # maybe do something else?

            # Only keep targets in the original graph that aren't in the result graph
            possible_step_nodes = set(graph[source]) - set(result[source])

            if not possible_step_nodes:
                node_blacklist.add(
                    source)  # there aren't any possible nodes to step to, so try growing from somewhere else

        step_node = random.choice(list(possible_step_nodes))

        # it's not really a big deal which, but it might be possible to weight this by the utility of edges later
        key, attr_dict = random.choice(list(graph[source][step_node].items()))

        result.add_edge(source, step_node, key=key, **attr_dict)
362295
def get_input_nodes(G: nx.DiGraph) -> List[str]:
    
    return [n for n, d in G.in_degree() if d == 0]
131630
def facets_by_vertex(self):
        
        if self._fbv_out is None:
            output = qhalf('Fv', self.halfspaces, self.interior_point)
            facets = []
            for l in output[1:]:
                facets.append([int(i) for i in l.split()[1:]])
            self._fbv_out = facets
        return self._fbv_out