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


Python DiGraph.delete_edge方法代码示例

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


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

示例1: __init__

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import delete_edge [as 别名]
    def __init__(self, path, version="0"):
        g = DiGraph()
        gaged_reaches = []
        db = openFile(path, "r")
        table = db.getNode("/", "networks/network" + str(version))
        reaches = {}
        # read data out of file
        for row in table:
            if str(row["ComID"]) != "-1":
                reaches[row["ComID"]] = Reach(self, row)
            else:
                reaches[row["ComID"]] = "-1"
                g.add_edge(Reach(self, row), "-1")
            if row["MonitoredFlag"] == "1":
                gaged_reaches.append(row["ComID"])
        db.close()
        # make network
        for comid in reaches.keys():
            to_comID = reaches[comid]._ToComID
            if to_comID != "-1":
                g.add_edge(reaches[comid], reaches[to_comID])
            else:
                g.add_edge(reaches[comid], -1)
        self._g_unbroken = g.copy()
        self._g_unbroken_reverse = self._g_unbroken.reverse()

        # break upstream of monitored reaches
        for i in gaged_reaches:
            if i != "-1":
                up = g.predecessors(reaches[i])
                for j in up:
                    if j != "-1":
                        g.delete_edge(j, reaches[i])
                    else:
                        g.delete_edge(j, "-1")
        self._g = g
        self._g_rev = g.reverse()
        self._version = str(version)
        self._path = str(path)
        self._reaches = reaches
        db.close()
开发者ID:xdansun,项目名称:pysparrow,代码行数:43,代码来源:network.py

示例2: _compute_dependencies

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import delete_edge [as 别名]
    def _compute_dependencies(blocks):
        ''' Given a sequence of blocks, compute the aggregate inputs, outputs,
            and dependency graph.

            Parameters
            ----------
            blocks : List(Block)
              A list of blocks in order of execution to "tie-up" into a larger,
              single block.

            Returns
            -------
            inputs : Set(Str)
              The input parameters to the new block.

            outputs : Set(Str)
              The output parameters to the new block.

            conditional_outputs : Set(Str)
              The conditional output parameters to the new block, i.e. names
              that might or might not be defined by an arbitrary execution of
              the block.

            dep_graph : Instance(Graph)
              The dependency graph (directed, acyclic) relating the blocks from
              the given sequence: block A depends on block B iff an output from
              B is used as an input to A.
              Additionally, the names of the inputs and outputs for the new
              block are included in the graph to capture their dependency
              relations to the contained blocks: name X depends on block A iff
              X is an output of A, and block A depends on name X iff X is an
              input to A.

            (Alternative: make each Block track its own dependencies)
        '''

        # Deferred computations
        deferred = set()

        # Build dep_graph: a not transitively closed dependency graph that
        # relates blocks to the blocks and inputs they depend on, and outputs
        # to the last block that modifies or creates them
        inputs, outputs, conditional_outputs = set(), set(), set()
        dep_graph, env = DiGraph(), {}
        for b in blocks:

            # 'b' depends on the provider for each of its inputs or, if none
            # exists, it depends on the inputs themselves (as inputs to the
            # aggregate block). If a name is provided only conditionally, then
            # 'b' depends on both the provider and the input.
            for i in b.inputs:
                if i in env:
                    dep_graph.add_edge(b, env[i])
                if i not in env or i in conditional_outputs:
                    inputs.add(i)
                    dep_graph.add_edge(b, i)

            for c in b.conditional_outputs:

                # 'b's outputs depend only on 'b'
                if c in dep_graph:
                    for n in dep_graph[c]:
                        dep_graph.delete_edge(c, n)
                dep_graph.add_edge(c, b)

                # 'b' depends on the provider for each of its conditional
                # outputs or, if none exists and the end result has an input of
                # the same name, 'b' depends on that input. (We defer the
                # latter test to check against the final set of inputs rather
                # than just the inputs we've found so far.)
                if c in env:
                    dep_graph.add_edge(b, env[c])
                else:
                    def f(b=b, c=c):
                        if c in inputs:
                            dep_graph.add_edge(b, c)
                    deferred.add(f)

                # 'b' contributes conditional outputs to the aggregate block
                # unless they are already unconditional
                if c not in outputs:
                    conditional_outputs.add(c)

                # 'b' becomes the provider for its conditional outputs
                env[c] = b

            for o in b.outputs:

                # 'b's outputs depend only on 'b'
                if o in dep_graph:
                    for n in dep_graph[o]:
                        dep_graph.delete_edge(o, n)
                dep_graph.add_edge(o, b)

                # 'b' contributes its outputs to the aggregate block -- as
                # unconditional outputs
                outputs.add(o)
                conditional_outputs.discard(o)

                # 'b' becomes the provider for its outputs
#.........这里部分代码省略.........
开发者ID:BabeNovelty,项目名称:blockcanvas,代码行数:103,代码来源:block.py


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