當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.all_simple_paths方法代碼示例

本文整理匯總了Python中networkx.all_simple_paths方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.all_simple_paths方法的具體用法?Python networkx.all_simple_paths怎麽用?Python networkx.all_simple_paths使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.all_simple_paths方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: materialize

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def materialize(self, X, prng, node):
        if self._dgraph.root.id == node.id:
            return X, None

        paths = [path for path in nx.all_simple_paths(self._dgraph.graph, self._dgraph.root.id, node.id)]

        assert len(paths) == 1

        path = paths[0]

        for i in range(len(path)):
            node = self._dgraph.id_node_map[path[i]]

            if util.contains_superclass(node.operator.__class__, 'SplitByPartition'):
                id_node_map = self._dgraph.id_node_map

                Xs = node.operator.transform(X)
                X = Xs[node.idx]
            else:
                X = node.operator.transform(X)
     
        return X, path 
開發者ID:ektelo,項目名稱:ektelo,代碼行數:24,代碼來源:data.py

示例2: _get_nx_paths

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def _get_nx_paths(self, begin, end):
        """
        Get the possible (networkx) simple paths between two nodes or addresses
        corresponding to nodes.
        Input: addresses or node instances
        Return: a list of lists of nodes representing paths.
        """
        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) 
開發者ID:angr,項目名稱:angr,代碼行數:20,代碼來源:vfg.py

示例3: get_path_iter

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def get_path_iter(graph, source, target, path_length, loop):
    """Return a generator of paths with path_length cutoff from source to
    target."""
    path_iter = nx.all_simple_paths(graph, source, target, path_length)
    try:
        for p in path_iter:
            path = deepcopy(p)
            # Remove common target from a path.
            path.remove(target)
            if loop:
                path.append(path[0])
            # A path should contain at least one edge
            if len(path) < 2:
                continue
            yield path
    except nx.NetworkXNoPath:
        pass 
開發者ID:sorgerlab,項目名稱:indra,代碼行數:19,代碼來源:pathfinding.py

示例4: root_to_leaf_paths

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def root_to_leaf_paths(G):
    """Yields root-to-leaf paths in a directed acyclic graph.

    `G` must be a directed acyclic graph. If not, the behavior of this
    function is undefined. A "root" in this graph is a node of in-degree
    zero and a "leaf" a node of out-degree zero.

    When invoked, this function iterates over each path from any root to
    any leaf. A path is a list of nodes.

    """
    roots = (v for v, d in G.in_degree() if d == 0)
    leaves = (v for v, d in G.out_degree() if d == 0)
    all_paths = partial(nx.all_simple_paths, G)
    # TODO In Python 3, this would be better as `yield from ...`.
    return chaini(starmap(all_paths, product(roots, leaves))) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:18,代碼來源:dag.py

示例5: fit_predict

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def fit_predict(self, ebunch):
        res = list()
        betas = np.zeros(self.path_len)
        for i in range(len(betas)):
            betas[i] = np.power(self.beta, i+1)
        for u, v in ebunch:
            paths = np.zeros(self.path_len)
            for path in nx.all_simple_paths(self._G, source=u, target=v, cutoff=self.path_len):
                paths[len(path)-2] += 1     # Simple paths output at most path_len+1, plus -1 because indexing at 0
            res.append(np.sum(betas * paths))
        return np.array(res).reshape(-1, 1) 
開發者ID:Dru-Mara,項目名稱:EvalNE,代碼行數:13,代碼來源:katz.py

示例6: getNetProp

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def getNetProp(inGraph):
    '''
    Function to compute properties
    of a given network.
    '''

    # number of weakly connected components in 
    # reference network
    numCC = len(list(nx.weakly_connected_components(inGraph)))
    
    # number of feedback loop 
    # in reference network
    allCyc = nx.simple_cycles(inGraph)
    cycSet = set()
    for cyc in allCyc:
        if len(cyc) == 3:
            cycSet.add(frozenset(cyc))
    
    numFB = len(cycSet)
    
    # number of feedfwd loops
    # in reference network
    allPaths = []
    allPathsSet = set()   
    for u,v in inGraph.edges():
        allPaths = nx.all_simple_paths(inGraph, u, v, cutoff=2)
        for p in allPaths:
            if len(p) >  2:
                allPathsSet.add(frozenset(p))
                
    numFF= len(allPathsSet)
    
    
    # number of mutual interactions
    numMI = 0.0
    for u,v in inGraph.edges():
        if (v,u) in inGraph.edges():
            numMI += 0.5

    return numCC, numFB, numFF, numMI 
開發者ID:Murali-group,項目名稱:Beeline,代碼行數:42,代碼來源:computePathStats.py

示例7: op

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def op(self, graph, a:NodeSpec, b:NodeSpec):
		return [ids_to_nodes(graph, i) for i in nx.all_simple_paths(graph.gnx, a["id"], b["id"])] 
開發者ID:Octavian-ai,項目名稱:clevr-graph,代碼行數:4,代碼來源:functional.py

示例8: find_longest_path

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def find_longest_path(self):
        if len(self.cfg.nodes()) == 1:
            return [self.offset]
        
        longest_len = 0
        longest_path = None
        
        for addr in self.exit_blocks:
            for path in nx.all_simple_paths(self.cfg, self.offset, addr):
                if len(path) >= longest_len:
                    longest_len = len(path)
                    longest_path = path
                    
        return longest_path 
開發者ID:cylance,項目名稱:winapi-deobfuscation,代碼行數:16,代碼來源:analysis.py

示例9: get_paths

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def get_paths(self):
        paths = []
        for addr in self.exit_blocks:
            paths.extend(nx.all_simple_paths(self.cfg, self.offset, addr))

        if not paths:
            paths = [[self.offset]]            
        return paths

    # TODO: ignore loops! 
開發者ID:cylance,項目名稱:winapi-deobfuscation,代碼行數:12,代碼來源:analysis.py

示例10: test_all_paths

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def test_all_paths(N=1):
    np.random.seed(12345)
    i = 0
    while i < N:
        p = np.random.rand()
        directed = np.random.rand() < 0.5
        G = random_unweighted_graph(n_vertices=5, edge_prob=p, directed=directed)

        nodes = G._I2V.keys()
        G_nx = to_networkx(G)

        # for each graph, test all_paths for all pairs of start and end
        # vertices. note that graph is not guaranteed to be connected, so many
        # paths will be empty
        for s_i in nodes:
            for e_i in nodes:
                if s_i == e_i:
                    continue

                paths = G.all_paths(s_i, e_i)
                paths_nx = nx.all_simple_paths(G_nx, source=s_i, target=e_i, cutoff=10)

                paths = sorted(paths)
                paths_nx = sorted(list(paths_nx))

                for p1, p2 in zip(paths, paths_nx):
                    np.testing.assert_array_equal(p1, p2)

                print("PASSED")
                i += 1 
開發者ID:ddbourgin,項目名稱:numpy-ml,代碼行數:32,代碼來源:test_utils.py

示例11: simple_paths_by_name

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def simple_paths_by_name(self, start_name, end_name):
        """Return a list of paths between start and end functions.
        """
        cfg_start = self.find_function_by_name(start_name)
        cfg_end = self.find_function_by_name(end_name)

        if not cfg_start or not cfg_end:
            raise Exception("Start/End function not found.")

        start_address = cfg_start.start_address
        end_address = cfg_end.start_address

        paths = networkx.all_simple_paths(self._graph, source=start_address, target=end_address)

        return ([self._cfg_by_addr[addr] for addr in path] for path in paths) 
開發者ID:programa-stic,項目名稱:barf-project,代碼行數:17,代碼來源:callgraph.py

示例12: simple_paths_by_address

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def simple_paths_by_address(self, start_address, end_address):
        """Return a list of paths between start and end functions.
        """
        cfg_start = self.find_function_by_address(start_address)
        cfg_end = self.find_function_by_address(end_address)

        if not cfg_start or not cfg_end:
            raise Exception("Start/End function not found.")

        start_address = cfg_start.start_address
        end_address = cfg_end.start_address

        paths = networkx.all_simple_paths(self._graph, source=start_address, target=end_address)

        return ([self._cfg_by_addr[addr] for addr in path] for path in paths) 
開發者ID:programa-stic,項目名稱:barf-project,代碼行數:17,代碼來源:callgraph.py

示例13: all_simple_bb_paths

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def all_simple_bb_paths(self, start_address, end_address):
        """Return a list of path between start and end address.
        """
        bb_start = self._find_basic_block(start_address)
        bb_end = self._find_basic_block(end_address)

        paths = networkx.all_simple_paths(self._graph, source=bb_start.address, target=bb_end.address)

        return ([self._bb_by_addr[addr] for addr in path] for path in paths) 
開發者ID:programa-stic,項目名稱:barf-project,代碼行數:11,代碼來源:controlflowgraph.py

示例14: compute_paths_from_origin_to

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def compute_paths_from_origin_to(self, a: Hit, leafs=None, heads=None):
        if leafs is None and heads is None:
            leafs, heads = self.get_leafs_and_heads()
        all_paths = []
        for l in leafs:
            paths = nx.all_simple_paths(self._p_graph, l, a)
            all_paths.extend(paths)
        return all_paths 
開發者ID:mitdbg,項目名稱:aurum-datadiscovery,代碼行數:10,代碼來源:apiutils.py

示例15: compute_paths_with

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import all_simple_paths [as 別名]
def compute_paths_with(self, a: Hit, leafs=None, heads=None):
        """
        Given a node, a, in the provenance graph, return all paths that contain it.
        :param a:
        :return:
        """
        # FIXME: refactor with compute_paths_from_origin and all that
        if leafs is None and heads is None:
            leafs, heads = self.get_leafs_and_heads()
        all_paths = []
        if a in leafs:
            for h in heads:
                paths = nx.all_simple_paths(self._p_graph, a, h)
                all_paths.extend(paths)
        elif a in heads:
            for l in leafs:
                paths = nx.all_simple_paths(self._p_graph, l, a)
                all_paths.extend(paths)
        else:
            upstreams = []
            for l in leafs:
                paths = nx.all_simple_paths(self._p_graph, l, a)
                upstreams.extend(paths)
            downstreams = []
            for h in heads:
                paths = nx.all_simple_paths(self._p_graph, a, h)
                downstreams.extend(paths)

            if len(downstreams) > len(upstreams):
                for d in downstreams:
                    for u in upstreams:
                        all_paths.append(u + d)
            else:
                for u in upstreams:
                    for d in downstreams:
                        all_paths.append(u + d)
        return all_paths 
開發者ID:mitdbg,項目名稱:aurum-datadiscovery,代碼行數:39,代碼來源:apiutils.py


注:本文中的networkx.all_simple_paths方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。