当前位置: 首页>>代码示例>>Python>>正文


Python networkx.descendants方法代码示例

本文整理汇总了Python中networkx.descendants方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.descendants方法的具体用法?Python networkx.descendants怎么用?Python networkx.descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.descendants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mark_not_reaching_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def mark_not_reaching_nodes(ea, source_color=COLOR_SOURCE, other_color=COLOR_NOT_REACHING):
    graph = get_nx_graph(ea)
    graph = graph.reverse()
    block_ea = get_block_start(ea)
    reaching = nx.descendants(graph, block_ea)

    try:
        graph_nodes_iter = graph.nodes()
    except:
        graph_nodes_iter = graph.nodes_iter()

    for node_ea in graph_nodes_iter:
        if node_ea not in reaching:
            CodeBlock(node_ea).color = other_color

    CodeBlock(ea).color = source_color 
开发者ID:tmr232,项目名称:Sark,代码行数:18,代码来源:function_flow.py

示例2: detect_deadlock

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def detect_deadlock(self):
        """
        Detects whether the system is in a deadlocked state,
        that is, is there a knot. Note that this code is taken
        and adapted from the NetworkX Developer Zone Ticket
        #663 knot.py (09/06/2015).
        """
        knots = []
        for c in nx.strongly_connected_components(self.statedigraph):
            subgraph = self.statedigraph.subgraph(c)
            nodes = set(subgraph.nodes())
            if len(nodes) == 1:
                n = nodes.pop()
                nodes.add(n)
                if set(self.statedigraph.successors(n)) == nodes:
                    knots.append(subgraph)
            else:
                for n in nodes:
                    successors = nx.descendants(self.statedigraph, n)
                    if successors <= nodes:
                        knots.append(subgraph)
                        break
        if len(knots) > 0:
            return True
        return False 
开发者ID:CiwPython,项目名称:Ciw,代码行数:27,代码来源:deadlock_detector.py

示例3: _build_multi_instance_node_tree_rec

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def _build_multi_instance_node_tree_rec(node_id,
                                        contained_tree,
                                        ctx,
                                        parent_relationship=None,
                                        parent_relationship_index=None,
                                        parent_node_instance_id=None,
                                        current_host_instance_id=None):
    node = contained_tree.node[node_id]['node']
    containers = _build_and_update_node_instances(
        ctx=ctx,
        node=node,
        parent_node_instance_id=parent_node_instance_id,
        parent_relationship=parent_relationship,
        current_host_instance_id=current_host_instance_id)
    for container in containers:
        node_instance = container.node_instance
        node_instance_id = node_instance['id']
        relationship_instance = container.relationship_instance
        new_current_host_instance_id = container.current_host_instance_id
        ctx.deployment_node_graph.add_node(node_instance_id,
                                           node=node_instance)
        if parent_node_instance_id is not None:
            ctx.deployment_node_graph.add_edge(
                node_instance_id, parent_node_instance_id,
                relationship=relationship_instance,
                index=parent_relationship_index)
        for child_node_id in contained_tree.neighbors_iter(node_id):
            descendants = nx.descendants(contained_tree, child_node_id)
            descendants.add(child_node_id)
            child_contained_tree = contained_tree.subgraph(descendants)
            _build_multi_instance_node_tree_rec(
                node_id=child_node_id,
                contained_tree=child_contained_tree,
                ctx=ctx,
                parent_relationship=ctx.plan_node_graph[
                    child_node_id][node_id]['relationship'],
                parent_relationship_index=ctx.plan_node_graph[
                    child_node_id][node_id]['index'],
                parent_node_instance_id=node_instance_id,
                current_host_instance_id=new_current_host_instance_id) 
开发者ID:cloudify-cosmo,项目名称:cloudify-dsl-parser,代码行数:42,代码来源:rel_graph.py

示例4: descendants

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def descendants(self, element):
        return nx.descendants(self._element_tree, element) 
开发者ID:cloudify-cosmo,项目名称:cloudify-dsl-parser,代码行数:4,代码来源:parser.py

示例5: get_reachable_states

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def get_reachable_states(self, current_state):
        reachable_states = []
        for target_state_str in nx.descendants(self.G, current_state.state_str):
            target_state = self.G.nodes[target_state_str]["state"]
            reachable_states.append(target_state)
        return reachable_states 
开发者ID:honeynet,项目名称:droidbot,代码行数:8,代码来源:utg.py

示例6: OnClick

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def OnClick(self, node_id):
        self.color_nodes()
        self._current_node_id = node_id
        node_ea = self[node_id]

        self._remove_target_handler.unregister()
        self._disable_source_handler.unregister()
        self._enable_source_handler.unregister()

        if node_ea in self._targets:
            self._remove_target_handler.register()
            self._attach_to_popup(self._remove_target_handler.get_name())

            for ea in nx.ancestors(self._lca_graph, node_ea):
                if ea not in self._targets and ea not in self._sources:
                    self._set_node_bg_color(self._node_ids[ea], COLOR_PATH)

        if node_ea in self._sources:
            if node_ea in self._disabled_sources:
                self._enable_source_handler.register()
                self._attach_to_popup(self._enable_source_handler.get_name())
            else:
                self._disable_source_handler.register()
                self._attach_to_popup(self._disable_source_handler.get_name())

                for ea in nx.descendants(self._lca_graph, node_ea):
                    if ea not in self._targets and ea not in self._sources:
                        self._set_node_bg_color(self._node_ids[ea], COLOR_PATH)

        return False 
开发者ID:tmr232,项目名称:Sark,代码行数:32,代码来源:lca.py

示例7: mark_reaching_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def mark_reaching_nodes(ea, source_color=COLOR_SOURCE, other_color=COLOR_REACHING):
    graph = get_nx_graph(ea)
    graph = graph.reverse()
    block_ea = get_block_start(ea)
    for descendant in nx.descendants(graph, block_ea):
        CodeBlock(descendant).color = other_color

    CodeBlock(ea).color = source_color 
开发者ID:tmr232,项目名称:Sark,代码行数:10,代码来源:function_flow.py

示例8: mark_unreachable_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def mark_unreachable_nodes(ea, source_color=COLOR_SOURCE, other_color=COLOR_UNREACHABLE):
    graph = get_nx_graph(ea)
    block_ea = get_block_start(ea)
    descendants = nx.descendants(graph, block_ea)
    for block in FlowChart(ea):
        if block.start_ea not in descendants:
            block.color = other_color

    CodeBlock(ea).color = source_color 
开发者ID:tmr232,项目名称:Sark,代码行数:11,代码来源:function_flow.py

示例9: mark_reachable_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def mark_reachable_nodes(ea, source_color=COLOR_SOURCE, other_color=COLOR_REACHABLE):
    graph = get_nx_graph(ea)
    block_ea = get_block_start(ea)
    for descendant in nx.descendants(graph, block_ea):
        CodeBlock(descendant).color = other_color

    CodeBlock(ea).color = source_color 
开发者ID:tmr232,项目名称:Sark,代码行数:9,代码来源:function_flow.py

示例10: verify_nx_algorithm_equivalence

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def verify_nx_algorithm_equivalence(self, tree, g):
        for root in tree.roots:
            self.assertTrue(nx.is_directed_acyclic_graph(g))

            # test descendants
            self.assertSetEqual(
                {u for u in tree.nodes() if tree.is_descendant(u, root)},
                set(nx.descendants(g, root)) | {root},
            )

            # test MRCA
            if tree.num_nodes < 20:
                for u, v in itertools.combinations(tree.nodes(), 2):
                    mrca = nx.lowest_common_ancestor(g, u, v)
                    if mrca is None:
                        mrca = -1
                    self.assertEqual(tree.mrca(u, v), mrca)

            # test node traversal modes
            self.assertEqual(
                list(tree.nodes(root=root, order="breadthfirst")),
                [root] + [v for u, v in nx.bfs_edges(g, root)],
            )
            self.assertEqual(
                list(tree.nodes(root=root, order="preorder")),
                list(nx.dfs_preorder_nodes(g, root)),
            ) 
开发者ID:tskit-dev,项目名称:tskit,代码行数:29,代码来源:test_highlevel.py

示例11: verify_nx_for_tutorial_algorithms

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def verify_nx_for_tutorial_algorithms(self, tree, g):
        # traversing upwards
        for u in tree.leaves():
            path = []
            v = u
            while v != tskit.NULL:
                path.append(v)
                v = tree.parent(v)

            self.assertSetEqual(set(path), {u} | nx.ancestors(g, u))
            self.assertEqual(
                path,
                [u] + [n1 for n1, n2, _ in nx.edge_dfs(g, u, orientation="reverse")],
            )

        # traversals with information
        def preorder_dist(tree, root):
            stack = [(root, 0)]
            while len(stack) > 0:
                u, distance = stack.pop()
                yield u, distance
                for v in tree.children(u):
                    stack.append((v, distance + 1))

        for root in tree.roots:
            self.assertDictEqual(
                {k: v for k, v in preorder_dist(tree, root)},
                nx.shortest_path_length(g, source=root),
            )

        for root in tree.roots:
            # new traversal: measuring time between root and MRCA
            for u, v in itertools.combinations(nx.descendants(g, root), 2):
                mrca = tree.mrca(u, v)
                tmrca = tree.time(mrca)
                self.assertAlmostEqual(
                    tree.time(root) - tmrca,
                    nx.shortest_path_length(
                        g, source=root, target=mrca, weight="branch_length"
                    ),
                ) 
开发者ID:tskit-dev,项目名称:tskit,代码行数:43,代码来源:test_highlevel.py

示例12: descendants

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def descendants(self, node, relations=None, reflexive=False):
        """
        Returns all descendants of specified node.

        The default implementation is to use networkx, but some
        implementations of the Ontology class may use a database or
        service backed implementation, for large graphs.


        Arguments
        ---------
        node : str
            identifier for node in ontology
        reflexive : bool
            if true, return query node in graph
        relations : list
             relation (object property) IDs used to filter

        Returns
        -------
        list[str]
            descendant node IDs
        """
        seen = set()
        nextnodes = [node]
        while len(nextnodes) > 0:
            nn = nextnodes.pop()
            if not nn in seen:
                seen.add(nn)
                nextnodes += self.children(nn, relations=relations)
        if not reflexive:
            seen -= {node}
        return list(seen) 
开发者ID:biolink,项目名称:ontobio,代码行数:35,代码来源:ontol.py

示例13: traverse_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def traverse_nodes(self, qids, up=True, down=False, **args):
        """
        Traverse (optionally) up and (optionally) down from an input set of nodes

        Arguments
        ---------
        qids : list[str]
            list of seed node IDs to start from
        up : bool
            if True, include ancestors
        down : bool
            if True, include descendants
        relations : list[str]
            list of relations used to filter

        Return
        ------
        list[str]
            nodes reachable from qids
        """
        g = self.get_filtered_graph(**args)
        nodes = set()
        for id in qids:
            # reflexive - always add self
            nodes.add(id)
            if down:
                nodes.update(nx.descendants(g, id))
            if up:
                nodes.update(nx.ancestors(g, id))
        return nodes 
开发者ID:biolink,项目名称:ontobio,代码行数:32,代码来源:ontol.py

示例14: subgraph_needed_for

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def subgraph_needed_for(self, start_at, end_at):
        """Find the subgraph of all dependencies to run these tasks. Returns a
        new graph.
        """
        assert start_at or end_at, "one of {start_at,end_at} must be a task id"
        start, end = map(self.task_dict.get, [start_at, end_at])
        if None in [start, end]:
            graph = self.get_networkx_graph()
            if start:
                task_subset = nx.descendants(graph, start)
                task_subset.add(start)
            elif end:
                task_subset = nx.ancestors(graph, end)
                task_subset.add(end)
        elif start == end:
            task_subset = set([start])
        else:
            graph = self.get_networkx_graph()
            task_subset = set()
            for path in nx.all_simple_paths(graph, start, end):
                task_subset.update(path)

        # make sure the tasks are added to the subgraph in the same
        # order as the original configuration file
        tasks_kwargs_list = [task.yaml_data for task in self.task_list
                             if task in task_subset]
        subgraph = TaskGraph(self.config_path, tasks_kwargs_list)
        return subgraph 
开发者ID:deanmalmgren,项目名称:flo,代码行数:30,代码来源:graph.py

示例15: get_descendants

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import descendants [as 别名]
def get_descendants(self, node_name):
        return set(nx.descendants(self._graph, node_name)) 
开发者ID:microsoft,项目名称:dowhy,代码行数:4,代码来源:causal_graph.py


注:本文中的networkx.descendants方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。