本文整理汇总了Python中networkx.DiGraph.out_edges方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.out_edges方法的具体用法?Python DiGraph.out_edges怎么用?Python DiGraph.out_edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.out_edges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import out_edges [as 别名]
#.........这里部分代码省略.........
If True, the graph is returned (False by default).
Returns:
--------
The graph is saved internally in self.graph.
"""
delimiter = kwargs["delimiter"] if "delimiter" in kwargs.keys() else " "
data = np.genfromtxt(fname, delimiter=delimiter, dtype=int, unpack=False)
source, target = data[:,0], data[:,1]
if data.shape[1] > 2:
flux = data[:,2]
else:
flux = np.ones_like(source)
nodes = set(source) | set(target)
self.nodes = len(nodes)
lines = len(flux)
if set(range(self.nodes)) != nodes:
new_node_ID = {old:new for new,old in enumerate(nodes)}
map_new_node_ID = np.vectorize(new_node_ID.__getitem__)
source = map_new_node_ID(source)
target = map_new_node_ID(target)
if verbose:
print "\nThe node IDs have to run continuously from 0 to Number_of_nodes-1."
print "Node IDs have been changed according to the requirement.\n-----------------------------------\n"
print 'Lines: ',lines , ', Nodes: ', self.nodes
print '-----------------------------------\nData Structure:\n\nsource, target, weight \n'
for ii in range(7):
print "%i, %i, %1.2e" %(source[ii], target[ii], flux[ii])
print '-----------------------------------\n'
G = DiGraph() # Empty, directed Graph
G.add_nodes_from(range(self.nodes))
for ii in xrange(lines):
u, v, w = int(source[ii]), int(target[ii]), float(flux[ii])
if u != v: # ignore self loops
assert not G.has_edge(u,v), "Edge appeared twice - not supported"
G.add_edge(u,v,weight=w)
else:
if verbose:
print "ignore self loop at node", u
symmetric = True
for s,t,w in G.edges(data=True):
w1 = G[s][t]["weight"]
try:
w2 = G[t][s]["weight"]
except KeyError:
symmetric = False
G.add_edge(t,s,weight=w1)
w2 = w1
if w1 != w2:
symmetric = False
G[s][t]["weight"] += G[t][s]["weight"]
G[s][t]["weight"] /= 2
G[t][s]["weight"] = G[s][t]["weight"]
if verbose:
if not symmetric:
print "The network has been symmetricised."
ccs = strongly_connected_component_subgraphs(G)
ccs = sorted(ccs, key=len, reverse=True)
G_GSCC = ccs[0]
if G_GSCC.number_of_nodes() != G.number_of_nodes():
G = G_GSCC
if verbose:
print "\n--------------------------------------------------------------------------"
print "The network has been restricted to the giant strongly connected component."
self.nodes = G.number_of_nodes()
for u, v, data in G.edges(data=True):
weight = G.out_degree(u,weight='weight')
data['transition_rate'] = 1.*data['weight']/weight
for u, v, data in G.edges(data=True):
data['effective_distance'] = 1. - log(data['transition_rate'])
if verbose:
print "\n--------------------------------------------------------------------------"
print "\nnode ID, out-weight, normalized out-weight, sum of effective distances \n "
for ii in range(7):
out_edges = G.out_edges(ii, data=True)
out_weight, effective_distance, transition_rate = 0, 0, 0
for u, v, data in out_edges:
out_weight += data["weight"]
effective_distance += data["effective_distance"]
transition_rate += data["transition_rate"]
print " %i %1.2e %2.3f %1.2e " %(ii,out_weight, transition_rate, effective_distance)
print "\n ... graph is saved in self.graph"
return G
示例2: PulseProgramUi
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import out_edges [as 别名]
#.........这里部分代码省略.........
self.triggerTableModel.contentsChanged.connect( self.updateSaveStatus )
self.setContextMenuPolicy( QtCore.Qt.ActionsContextMenu )
self.autoSaveAction = QtWidgets.QAction("Automatically save configuration", self)
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()