Returns
        -------
        graph
            bidirectional networkx graph of all equivalency relations
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
133889
def get_xref_graph(ont):
    
    g = networkx.MultiGraph()
    for (c,x) in fetchall_xrefs(ont):
        g.add_edge(c,x,source=c)
    return g
936723
def _get_nx_paths(self, begin, end):
        
        if type(begin) is int and type(end) is int:  # pylint:disable=unidiomatic-typecheck
            n_begin = self.get_any_node(begin)
            n_end = self.get_any_node(end)

        elif isinstance(begin, VFGNode) and isinstance(end, VFGNode):  # pylint:disable=unidiomatic-typecheck
            n_begin = begin
            n_end = end
        else:
            raise AngrVFGError("from and to should be of the same type")

        return networkx.all_simple_paths(self.graph, n_begin, n_end)
1294484
def ind_nodes(self):
        
        graph = self.graph

        dependent_nodes = set(
            node for dependents
            in graph.values() for node in dependents)
        return [node_ for node_ in graph if node_ not in dependent_nodes]
457277
def get_digraph(ont, relations=None, writecache=False):
    
    digraph = networkx.MultiDiGraph()
    logging.info("Getting edges (may be cached)")
    for (s,p,o) in get_edges(ont):
        p = map_legacy_pred(p)
        if relations is None or p in relations:
            digraph.add_edge(o,s,pred=p)
    logging.info("Getting labels (may be cached)")
    for (n,label) in fetchall_labels(ont):
        digraph.add_node(n, **{'label':label})
    return digraph
950545
def get_dependency_graph(component):
    
    if component not in DEPENDENCIES:
        raise Exception("%s is not a registered component." % get_name(component))

    if not DEPENDENCIES[component]:
        return {component: set()}

    graph = defaultdict(set)

    def visitor(c, parent):
        if parent is not None:
            graph[parent].add(c)

    walk_dependencies(component, visitor)

    graph = dict(graph)

    # Find all items that don't depend on anything.
    extra_items_in_deps = _reduce(set.union, graph.values(), set()) - set(graph.keys())

    # Add empty dependencies where needed.
    graph.update(dict((item, set()) for item in extra_items_in_deps))

    return graph
530233
def graph(self, ig):
        

        res = copy.copy(self)
        res._edges = ig
        res._nodes = None
        return res
550155
def graph(self):
        
        if not hasattr(self, '_graph') or self._graph is None:
            self._graph = ConjunctiveGraph(store=self.store,
                                           identifier=self.base_uri)
        return self._graph
1323629
def reversed_graph(graph:dict) -> dict:
    """"""
    ret = defaultdict(set)
    for node, succs in graph.items():
        for succ in succs:
            ret[succ].add(node)
    return dict(ret)
694214
def graph_nodes_sorted(self):
        
        return sorted(self._graph.nodes(), key=lambda _: repr(_))
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
1032700
def most_mergeable(self, states):
        

        histories = set(self.get_ref(s.history) for s in states)

        for n in networkx.algorithms.dfs_postorder_nodes(self._graph):
            intersection = histories.intersection(self.all_successors(n))
            if len(intersection) > 1:
                return (
                    [ s for s in states if self.get_ref(s.history) in intersection ],
                    n(),
                    [ s for s in states if self.get_ref(s.history) not in intersection ]
                )

        # didn't find any?
        return set(), None, states
1088241
def to_networkx(self, directed=None):
    ''''''
    import networkx as nx
    directed = directed if directed is not None else self.is_directed()
    cls = nx.DiGraph if directed else nx.Graph
    adj = self.matrix()
    if ss.issparse(adj):
      return nx.from_scipy_sparse_matrix(adj, create_using=cls())
    return nx.from_numpy_matrix(adj, create_using=cls())
459354
def permute_graph(G, order):
  '''
  '''
  adj = G.matrix('dense')
  adj = adj[np.ix_(order, order)]
  return Graph.from_adj_matrix(adj)
1224979
def relations_used(self):
        
        g = self.get_graph()
        types = set()
        for (x,y,d) in g.edges(data=True):
            types.add(d['pred'])
        return list(types)
105725
def graph(self, **kw):
        
        self.name = kw.get('name', 'G')
        self.fillcolor = kw.get('fillcolor', '#ffffff')
        self.fontcolor = kw.get('fontcolor', '#000000')
        self.rankdir = kw.get('rankdir', 'BT' if self.reverse else 'TB')
        if kw.get('concentrate', True):
            self.concentrate = 'concentrate = true;'
        else:
            self.concentrate = ''
        self.dedent("""
            digraph {self.name} {{
                {self.concentrate}
                rankdir = {self.rankdir};
                node [style=filled,fillcolor="{self.fillcolor}",fontcolor="{self.fontcolor}",fontname=Helvetica,fontsize=10];

        """.format(self=self))
        yield
        self.writeln('}')
804868
def repr_tree(self):
        
        import utool as ut
        import networkx as nx
        repr_tree = nx.DiGraph()
        for u, v in ut.itertwo(self.values()):
            if not repr_tree.has_edge(v, u):
                repr_tree.add_edge(u, v)
        return repr_tree