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


Python DiGraph.remove_edge方法代码示例

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


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

示例1: remove_edge

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]
 def remove_edge(self, u,  v = None):
     temp = self.copy()
     DiGraph.remove_edge(temp, u, v = v)
     if not temp._is_connected():
         raise ValueError("Removing edge (%s, %s) creates disconnected graph" %(u, v) )
     else:
         DiGraph.remove_edge(self, u, v = v)
开发者ID:mrkwjc,项目名称:ffnet,代码行数:9,代码来源:graphs.py

示例2: filter_edges

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]
	def filter_edges(self,thresh):
		edges=DiGraph.edges(self,data='weight')
		for edge in edges:
			if edge[2]<thresh:
				DiGraph.remove_edge(self,edge[0],edge[1])

				if DiGraph.in_degree(self,edge[0])==0 and DiGraph.out_degree(self,edge[0])==0:
					DiGraph.remove_node(self,edge[0])

				if DiGraph.in_degree(self,edge[1])==0 and DiGraph.out_degree(self,edge[1])==0:
					DiGraph.remove_node(self,edge[1])
开发者ID:Liping90,项目名称:dis_decribe,代码行数:13,代码来源:clique_net.py

示例3: ShapeshifterProxyTest

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]
class ShapeshifterProxyTest(ShapeshifterProxy):
    def __init__(self):
        self.graph = DiGraph()

    def add_edge(self, source, destination, metric):
        log.info("Adding %s-%s @ %s", source, destination, metric)
        self.graph.add_edge(source, destination, cost=metric)

    def remove_edge(self, source, destination):
        log.info("Removing %s-%s", source, destination)
        self.graph.remove_edge(source, destination)

    def boostrap_graph(self, graph):
        log.info("Received graph: %s", graph)
        for u, v, m in graph:
            self.graph.add_edge(u, v, cost=m)
开发者ID:Fibbing,项目名称:FibbingNode,代码行数:18,代码来源:shapeshifterproxytest.py

示例4: one_way_component

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]
def one_way_component(
    graph: nx.DiGraph, target_node: str or int, source_node: str or int
) -> [(str or int, str or int)]:
    graph = cp.deepcopy(graph)
    edges = []
    if target_node == source_node:
        return edges
    out_edges = outcoming_edges(graph, target_node)
    graph.remove_edges_from(out_edges)
    in_edges = incoming_edges(graph, target_node)
    for edge_out, edge_in in in_edges:
        if nx.has_path(graph, source_node, edge_out):
            edges.append((edge_out, edge_in))
            edges.extend(one_way_component(graph, edge_out, source_node))
        else:
            graph.remove_edge(edge_out, edge_in)
    return edges
开发者ID:deniszorinets,项目名称:DigraphPotential,代码行数:19,代码来源:digraph_potential.py

示例5: compute_dependent_cohorts

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]
    def compute_dependent_cohorts(self, objects, deletion):
        n = len(objects)
        r = list(range(n))

        oG = DiGraph()

        for i in r:
            oG.add_node(i)

        try:
            for i0 in range(n):
                for i1 in range(n):
                    if i0 != i1:
                        if deletion:
                            path_args = (objects[i1], objects[i0])
                        else:
                            path_args = (objects[i0], objects[i1])

                        is_connected, edge_type = self.concrete_path_exists(*path_args)
                        if is_connected:
                            try:
                                edge_type = oG[i1][i0]["type"]
                                if edge_type == PROXY_EDGE:
                                    oG.remove_edge(i1, i0)
                                    oG.add_edge(i0, i1, type=edge_type)
                            except KeyError:
                                oG.add_edge(i0, i1, type=edge_type)
        except KeyError:
            pass

        components = weakly_connected_component_subgraphs(oG)
        cohort_indexes = [reversed(list(topological_sort(g))) for g in components]
        cohorts = [
            [objects[i] for i in cohort_index] for cohort_index in cohort_indexes
        ]

        return cohorts
开发者ID:opencord,项目名称:xos,代码行数:39,代码来源:event_loop.py

示例6: range

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]
import math
import itertools as it
import networkx as nx
from networkx import DiGraph

for g in range(1, int(input()) + 1):
    N, M = map(int, input().split())
    stars = [input().strip() for _ in range(N)]
    donors = {donor: list(favs) for donor, favs in map(lambda x: (x[0], x[1:]), (input().strip().split() for _ in range(M))) if len(favs) > 0}
    L = math.ceil(sum(1 for _ in filter(lambda x: len(x) > 0, donors.values())) / N)
    G = DiGraph()
    for donor, favs in donors.items():
        G.add_edge(0, donor, capacity=1)
        for fav in favs:
            G.add_edge(donor, fav)
    for l in it.count(L):
        for star in stars:
            G.add_edge(star, 1, capacity=l)
        if nx.maximum_flow_value(G, 0, 1) == len(donors):
            print('Event {}:'.format(g), l)
            break
        for star in stars:
            G.remove_edge(star, 1)
开发者ID:armanbilge,项目名称:COMPSCI320,代码行数:25,代码来源:golf.py

示例7: PulseProgramUi

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]

#.........这里部分代码省略.........
        self.autoSaveAction.setCheckable(True)
        self.autoSaveAction.setChecked( self.configParams.autoSaveContext )
        self.autoSaveAction.triggered.connect( self.onAutoSave )
        self.addAction( self.autoSaveAction )

        #background color context menu
        setBackgroundColorAction = QtGui.QAction("Set Background Color", self)
        setBackgroundColorAction.triggered.connect(self.onSetBackgroundColor)
        self.addAction(setBackgroundColorAction)
        removeBackgroundColorAction = QtGui.QAction("Remove Background Color", self)
        removeBackgroundColorAction.triggered.connect(self.onRemoveBackgroundColor)
        self.addAction(removeBackgroundColorAction)

        self.initMenu()
        self.tabifyDockWidget(self.shutterDock, self.triggerDock)
        self.tabifyDockWidget(self.triggerDock, self.counterDock)
        self.restoreLayout()

    def populateDependencyGraph(self):
        self.dependencyGraph = DiGraph()
        self.dependencyGraph.add_nodes_from(self.contextDict.keys())
        for name, context in self.contextDict.items():
            if context.parentContext is not None:
                try:
                    self.dependencySetParent(name, context.parentContext)
                except CyclicDependencyError as ce:
                    context.parentContext = ce.parent

    def dependencySetParent(self, child, parent):
        parent = parent if parent else None
        oldParentEdges = self.dependencyGraph.out_edges([child])
        _, oldParent = first(oldParentEdges, (None, None))
        if parent != oldParent:
            self.dependencyGraph.remove_edges_from(oldParentEdges)
            if parent:
                self.dependencyGraph.add_edge(child, parent)
                cycles = simple_cycles(self.dependencyGraph)
                try:
                    cycle = next(cycles)
                    # StopIteration is raised if there are cycles
                    self.dependencyGraph.remove_edge(child, parent)
                    self.dependencyGraph.add_edges_from(oldParentEdges)
                    raise CyclicDependencyError(oldParent)
                except StopIteration:
                    pass

    def restoreLayout(self):
        """Restore layout from config settings"""
        windowState = self.config.get(self.configname+".state")
        if windowState: self.restoreState(windowState)
        docSplitterState = self.config.get(self.configname+'.docSplitter')
        if docSplitterState: self.docSplitter.restoreState(docSplitterState)

    def initMenu(self):
        self.menuView.clear()
        dockList = self.findChildren(QtWidgets.QDockWidget)
        for dock in dockList:
            self.menuView.addAction(dock.toggleViewAction())

    def onAutoSave(self, checked):
        self.configParams.autoSaveContext = checked
        if checked:
            self.onSaveContext()

    def loadContext(self, newContext ):
        previousContext = self.currentContext
开发者ID:pyIonControl,项目名称:IonControl,代码行数:70,代码来源:PulseProgramUi.py

示例8: remove_edge

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edge [as 别名]
 def remove_edge(self, node1, node2):
     edge = (node1, node2)
     if self.__debug > 0:
         print "Removing edge: " + str(edge)
     self.__pins.pop(edge)
     digraph.remove_edge(self, node1, node2)
开发者ID:yellekelyk,项目名称:strip,代码行数:8,代码来源:DAGCircuit.py


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