本文整理汇总了Python中networkx.DiGraph.remove_edges_from方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.remove_edges_from方法的具体用法?Python DiGraph.remove_edges_from怎么用?Python DiGraph.remove_edges_from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.remove_edges_from方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_graph
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edges_from [as 别名]
def build_graph(self):
new_graph = DiGraph()
# Rebuild the graph from the LSDB
for lsa in chain(self.routers.values(),
self.networks.values(),
self.ext_networks.values()):
lsa.apply(new_graph, self)
# Contract all IPs to their respective router-id
for lsa in self.routers.values():
lsa.contract_graph(new_graph, self.router_private_address.get(
lsa.routerid, []))
# Figure out the controllers layout
base_net = ip_network(CFG.get(DEFAULTSECT, 'base_net'))
controller_prefix = CFG.getint(DEFAULTSECT, 'controller_prefixlen')
# Group by controller and log them
for ip in new_graph.nodes_iter():
addr = ip_address(ip)
if addr in base_net:
"""1. Compute address diff to remove base_net
2. Right shift to remove host bits
3. Mask with controller mask
"""
id = (((int(addr) - int(base_net.network_address)) >>
base_net.max_prefixlen - controller_prefix) &
((1 << controller_prefix) - 1))
self.controllers[id].append(ip)
# Contract them on the graph
for id, ips in self.controllers.iteritems():
contract_graph(new_graph, ips, 'C_%s' % id)
# Remove generated self loops
new_graph.remove_edges_from(new_graph.selfloop_edges())
self.apply_secondary_addresses(new_graph)
return new_graph
示例2: remove_edges_from
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edges_from [as 别名]
def remove_edges_from(self, ebunch):
temp = self.copy()
DiGraph.remove_edges_from(temp, ebunch)
if not temp._is_connected():
raise ValueError("Removing edges %s creates disconnected graph" %(ebunch, ) )
else:
DiGraph.remove_edges_from(self, ebunch)
示例3: one_way_component
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edges_from [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
示例4: synthesize
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edges_from [as 别名]
def synthesize(tsys, exprtab, init_flags='ALL_ENV_EXIST_SYS_INIT'):
assert init_flags.upper() == 'ALL_ENV_EXIST_SYS_INIT', 'Only the initial condition interpretation ALL_ENV_EXIST_SYS_INIT is supported.'
W, Y_list, X_list = get_winning_set(tsys, return_intermediates=True)
initial_states = get_initial_states(W, tsys, exprtab, init_flags)
if initial_states is None:
return None
goalnames = ['SYSGOAL'+str(i) for i in range(tsys.num_sgoals)]
for goalmode in range(tsys.num_sgoals):
Y_list[goalmode][0] = set([s for s in W if goalnames[goalmode] in tsys.G.node[s]['sat']])
strategy = DiGraph()
next_id = len(initial_states)
workset = list(range(next_id))
strategy.add_nodes_from([(i, {'state': s, 'mode': 0, 'initial': True})
for (i,s) in enumerate(initial_states)])
while len(workset) > 0:
nd = workset.pop()
j = 0
while j < len(Y_list[strategy.node[nd]['mode']]):
if strategy.node[nd]['state'] in Y_list[strategy.node[nd]['mode']][j]:
break
j += 1
if j == 0:
assert goalnames[strategy.node[nd]['mode']] in tsys.G.node[strategy.node[nd]['state']]['sat']
original_mode = strategy.node[nd]['mode']
while goalnames[strategy.node[nd]['mode']] in tsys.G.node[strategy.node[nd]['state']]['sat']:
strategy.node[nd]['mode'] = (strategy.node[nd]['mode'] + 1) % tsys.num_sgoals
if strategy.node[nd]['mode'] == original_mode:
break
if strategy.node[nd]['mode'] != original_mode:
repeat_found = False
for possible_repeat, attr in strategy.nodes_iter(data=True):
if (possible_repeat != nd
and attr['mode'] == strategy.node[nd]['mode']
and attr['state'] == strategy.node[nd]['state']):
repeat_found = True
for (u,v) in strategy.in_edges_iter(nd):
strategy.add_edge(u, possible_repeat)
strategy.remove_edges_from(strategy.in_edges(nd))
strategy.remove_node(nd)
break
if repeat_found:
continue
j = 0
while j < len(Y_list[strategy.node[nd]['mode']]):
if strategy.node[nd]['state'] in Y_list[strategy.node[nd]['mode']][j]:
break
j += 1
if j == 0:
assert goalnames[strategy.node[nd]['mode']] in tsys.G.node[strategy.node[nd]['state']]['sat']
for envpost in tsys.envtrans[strategy.node[nd]['state']]:
next_state = None
for succ_nd in tsys.G.successors(strategy.node[nd]['state']):
if (tuple([succ_nd[i] for i in tsys.ind_uncontrolled]) == envpost
and ((j > 0 and succ_nd in Y_list[strategy.node[nd]['mode']][j-1])
or (j == 0 and succ_nd in W))):
next_state = succ_nd
break
if next_state is None:
assert j > 0
if j == 0:
import pdb; pdb.set_trace()
blocking_index = None
blocking_sets = X_list[strategy.node[nd]['mode']][j-1]
for k in range(len(blocking_sets)):
if strategy.node[nd]['state'] in blocking_sets[k]:
blocking_index = k
break
assert blocking_index is not None
for succ_nd in tsys.G.successors(strategy.node[nd]['state']):
if (tuple([succ_nd[i] for i in tsys.ind_uncontrolled]) == envpost
and succ_nd in blocking_sets[blocking_index]):
next_state = succ_nd
break
assert next_state is not None
foundmatch = False
for candidate, cattr in strategy.nodes_iter(data=True):
if cattr['state'] == next_state and cattr['mode'] == strategy.node[nd]['mode']:
strategy.add_edge(nd, candidate)
foundmatch = True
break
if not foundmatch:
if j == 0:
new_mode = (strategy.node[nd]['mode'] + 1) % tsys.num_sgoals
else:
new_mode = strategy.node[nd]['mode']
workset.append(next_id)
strategy.add_node(next_id, {'state': next_state,
'mode': new_mode,
'initial': False})
strategy.add_edge(nd, next_id)
#.........这里部分代码省略.........
示例5: PulseProgramUi
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import remove_edges_from [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