Input for a subgraph
514764
function GraphInput() {
        this.addOutput("", "");

        this.name_in_graph = "";
        this.properties = {};
        var that = this;

        Object.defineProperty(this.properties, "name", {
            get: function() {
                return that.name_in_graph;
            },
            set: function(v) {
                if (v == "" || v == that.name_in_graph || v == "enabled") {
                    return;
                }
                if (that.name_in_graph) {
                    //already added
                    that.graph.renameInput(that.name_in_graph, v);
                } else {
                    that.graph.addInput(v, that.properties.type);
                }
                that.name_widget.value = v;
                that.name_in_graph = v;
            },
            enumerable: true
        });

        Object.defineProperty(this.properties, "type", {
            get: function() {
                return that.outputs[0].type;
            },
            set: function(v) {
                if (v == "event") {
                    v = LiteGraph.EVENT;
                }
                that.outputs[0].type = v;
                if (that.name_in_graph) {
                    //already added
                    that.graph.changeInputType(
                        that.name_in_graph,
                        that.outputs[0].type
                    );
                }
                that.type_widget.value = v;
            },
            enumerable: true
        });

        this.name_widget = this.addWidget(
            "text",
            "Name",
            this.properties.name,
            function(v) {
                if (!v) {
                    return;
                }
                that.properties.name = v;
            }
        );
        this.type_widget = this.addWidget(
            "text",
            "Type",
            this.properties.type,
            function(v) {
                v = v || "";
                that.properties.type = v;
            }
        );

        this.widgets_up = true;
        this.size = [180, 60];
    }
1122939
private void advance() {
        // If we don't have any simple graphs to return, and there are still
        // more subgraphs, then pick off the next subgraph and decompose it
        if (next.isEmpty() && subgraphIterator.hasNext()) {
            Multigraph<T,E> g = subgraphIterator.next();

            // Find all pairs of edges, checking whether the graph is a simple
            // graph already
            boolean isSimpleAlready = true;
            List<IntPair> connected = new ArrayList<IntPair>();
            for (int i : g.vertices()) {
                for (int j : g.vertices()) {
                    if (i == j)
                        break;
                    Set<E> edges = null;
                    try {
                        edges = g.getEdges(i, j);
                    } catch (NullPointerException npe) {
                        System.out.println("Bad graph? : " + g);
                        throw npe;
                    }
                    int size = edges.size();
                    if (size > 0)
                        connected.add(new IntPair(i, j));
                    if (size > 1)
                        isSimpleAlready = false;
                }
            }
            // If the subgraph was already a simple graph, then just append it
            // to the list
            if (isSimpleAlready) {
                // System.out.println("next graph was already simple: " + g);
                next.add(g);
            }
            // Otherwise, generate a recursive call to enumerate all the
            // simple graphs from this graph
            else {
                // Create an empty graph which will be populated with a new edge
                // and then copied 
                Multigraph<T,E> m = g.copy(Collections.<Integer>emptySet()); //Graphs.asMultigraph(new GenericGraph<E>());
                next.addAll(enumerateSimpleGraphs(g, connected, 0, m));
            }
        }
    }
555928
def _init_using_k_equivalence(self, given_graph, sfa=False):
        
        graph = DFA(self.alphabet)
        graph.init_from_acceptor(given_graph)
        graph.fixminimized(self.alphabet)

        # Access Strings
        self.access_strings_map = self._bfs_path_states(graph, sorted(
            graph.states, key=attrgetter('initial'), reverse=True)[0])

        # Find Q
        set_q = set(self._object_set_to_state_list(graph.states))
        # We will work with states addresses here instead of states stateid for
        # more convenience
        set_f = set(self._object_set_to_state_list(self._get_accepted(graph)))
        # Perform P := {F, Q-F}
        set_nf = set_q.copy() - set_f.copy()
        self.groups = [set_f.copy(), set_nf.copy()]
        self.bookeeping = [(set_f, set_nf, '')]

        done = False
        while not done:
            done = True
            new_groups = []
            for selectgroup in self.groups:
                # _check for each letter if it splits the current group
                for character in self.alphabet:
                    # print 'Testing symbol: ', c
                    target = defaultdict(list)
                    target_states = defaultdict(int)
                    new_g = [set(selectgroup)]
                    for sid in selectgroup:
                        # _check if all transitions using c are going in a state
                        # in the same group. If they are going on a different
                        # group then split
                        deststate = self._delta(graph, graph[sid], character)
                        destgroup = self._get_group_from_state(
                            deststate.stateid)
                        target[destgroup].append(sid)
                        target_states[destgroup] = deststate.stateid
                    if len(target) > 1:

                        inv_target_states = {
                            v: k for k, v in target_states.iteritems()}
                        new_g = [set(selectedstate) for selectedstate in target.values()]
                        done = False
                        # Get all the partitions of destgroups
                        queue = [set([x for x in target_states.values()])]
                        while queue:
                            top = queue.pop(0)
                            (group1, group2, distinguish_string) = self._partition_group(top)
                            ng1 = self._reverse_to_source(
                                target, [inv_target_states[x] for x in group1])
                            ng2 = self._reverse_to_source(
                                target, [inv_target_states[x] for x in group2])
                            dist_string = character + distinguish_string

                            self.bookeeping.append((ng1, ng2, dist_string))

                            if len(group1) > 1:
                                queue.append(group1)
                            if len(group2) > 1:
                                queue.append(group2)
                        break
                new_groups += new_g

            # End of iteration for the k-equivalence
            # Assign new groups and check if any change occured
            self.groups = new_groups

        sm_vector = [
            i for (a, i) in sorted(
                self.access_strings_map.items(),
                key=lambda x: len(x[1]))]
        if not sfa:
            smi_vector = ['{}{}'.format(a, b)
                          for b in self.alphabet for a in sm_vector]
        else:
            smi_vector = self._init_smi(graph, self.access_strings_map)
        em_vector = [distinguish_string for (_, _, distinguish_string) in self.bookeeping]

        return sm_vector, smi_vector, em_vector
567697
def process_input_graph(func):
    """"""
    @wraps(func)
    def wrapped_func(*args, **kwargs):
        input_graph = args[0]
        if isinstance(input_graph, nx.DiGraph):
            return func(*args, **kwargs)
        else:
            nx_graph = dict_to_nx(args[0], oriented=True)
            args = [nx_graph] + list(args[1:])
            return func(*args, **kwargs)
    return wrapped_func
537549
def predicatesOut(G: Graph, n: Node) -> Set[TriplePredicate]:
    
    return {p for p, _ in G.predicate_objects(n)}
108447
def neighborhood_subgraph(self, start_idx, radius=1, weighted=True,
                            directed=True, return_mask=False):
    ''''''
    adj = self.matrix('dense', 'csr', 'csc')
    dist = ssc.dijkstra(adj, directed=directed, indices=start_idx,
                        unweighted=(not weighted), limit=radius)
    mask = np.isfinite(dist)
    sub_adj = adj[mask][:,mask]
    g = self.__class__.from_adj_matrix(sub_adj)
    if return_mask:
      return g, mask
    return g
778222
def get_vertex_string(self, i):
        """"""
        number = self.numbers[i]
        if number == 0:
            return Graph.get_vertex_string(self, i)
        else:
            # pad with zeros to make sure that string sort is identical to number sort
            return "%03i" % number
1125947
def one_to_one(graph, nodes):
    
    edges = itertools.chain.from_iterable(graph.values())
    return len(graph) == len(nodes) and len(set(edges)) == len(nodes)
220108
def g(number_of_links, size_x, size_y)
      a = (size_x + size_y) ** p
      b = size_x ** p
      c = size_x ** p

      number_of_links / (a - b - c)
    end
525794
def get_subgraph(self, subvertices, normalize=False):
        
        graph = Graph.get_subgraph(self, subvertices, normalize)
        if normalize:
            new_numbers = self.numbers[graph._old_vertex_indexes] # vertices do change
        else:
            new_numbers = self.numbers # vertices don't change!
        if self.symbols is None:
            new_symbols = None
        elif normalize:
            new_symbols = tuple(self.symbols[i] for i in graph._old_vertex_indexes)
        else:
            new_symbols = self.symbols
        new_orders = self.orders[graph._old_edge_indexes]
        result = MolecularGraph(graph.edges, new_numbers, new_orders, new_symbols)
        if normalize:
            result._old_vertex_indexes = graph._old_vertex_indexes
        result._old_edge_indexes = graph._old_edge_indexes
        return result
84136
def with_siblings(graph, outputs):
    """"""
    siblings = set()
    for node in outputs:
        siblings |= graph.siblings(node)
    return siblings
453904
def get_subgraphs(graph=None):
    
    graph = graph or DEPENDENCIES
    keys = set(graph)
    frontier = set()
    seen = set()
    while keys:
        frontier.add(keys.pop())
        while frontier:
            component = frontier.pop()
            seen.add(component)
            frontier |= set([d for d in get_dependencies(component) if d in graph])
            frontier |= set([d for d in get_dependents(component) if d in graph])
            frontier -= seen
        yield dict((s, get_dependencies(s)) for s in seen)
        keys -= seen
        seen.clear()
320971
def kruskal_mst(graph):
    
    edges_accepted = 0
    ds = DisjointSet()
    pq = PriorityQueue()
    accepted_edges = []
    label_lookup = {}

    nodes = graph.get_all_node_ids()
    num_vertices = len(nodes)
    for n in nodes:
        label = ds.add_set()
        label_lookup[n] = label

    edges = graph.get_all_edge_objects()
    for e in edges:
        pq.put(e['id'], e['cost'])

    while edges_accepted < (num_vertices - 1):
        edge_id = pq.get()

        edge = graph.get_edge(edge_id)
        node_a, node_b = edge['vertices']
        label_a = label_lookup[node_a]
        label_b = label_lookup[node_b]

        a_set = ds.find(label_a)
        b_set = ds.find(label_b)

        if a_set != b_set:
            edges_accepted += 1
            accepted_edges.append(edge_id)
            ds.union(a_set, b_set)

    return accepted_edges
729125
private void dfs(int v, int[] cc, int id) {
        cc[v] = id;
        for (Edge edge : graph[v]) {
            int t = edge.v2;
            if (!digraph && t == v) {
                t = edge.v1;
            }

            if (cc[t] == -1) {
                dfs(t, cc, id);
            }
        }
    }
56294
public static List<SubGraph> getSubgraphsMatching(SameDiff sd, SubGraphPredicate p) {
        List<SubGraph> out = new ArrayList<>();
        for (DifferentialFunction df : sd.functions()) {
            if (p.matches(sd, df)) {
                SubGraph sg = p.getSubGraph(sd, df);
                out.add(sg);
            }
        }

        return out;
    }
544975
def sub!(pat, rep)
      each_with_index { |fn, i| self[i] = fn.sub(pat, rep) }
      self
    end
684839
def draw(graph, fname):
    """"""
    ag = networkx.nx_agraph.to_agraph(graph)
    ag.draw(fname, prog='dot')