本文整理汇总了Python中networkx.DiGraph.clear方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.clear方法的具体用法?Python DiGraph.clear怎么用?Python DiGraph.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import clear [as 别名]
#.........这里部分代码省略.........
self.addObject(muscle)
return muscle
def findMuscle(self, name = None):
"""
Find the first muscle with the given name.
>>> muscle = network.findMuscle('M1')
Returns a :class:`muscle <Network.Muscle.Muscle>` or None if there are no muscles with the name.
"""
return self.findObject(Muscle, name)
def muscles(self):
"""
Return a list of all :class:`muscles <Network.Muscle.Muscle>` in the network.
>>> for muscle in network.muscles():
... display.setVisibleOpacity(muscle, 0.5)
An empty list will be returned if there are no muscles in the network.
"""
return self.objectsOfClass(Muscle)
def _updateGraph(self, objectToUpdate = None):
if objectToUpdate is None:
# Rebuild the entire graph.
objectsToUpdate = self.objects
self.graph.clear()
else:
# Just rebuild the connections to the one object.
objectsToUpdate = [objectToUpdate]
# Remove the object if it was there before. This will also delete any edges from the node.
objectId = objectToUpdate.networkId
if objectId in self.graph:
self.graph.remove_node(objectId)
# Maintain a temporary cache of weights so that rebuilding the whole graph doesn't take so long.
objectWeights = {}
def weightOfObject(weightedObject):
if weightedObject.networkId in objectWeights:
objectWeight = objectWeights[weightedObject.networkId]
else:
objectWeight = self.weightOfObject(weightedObject)
objectWeights[weightedObject.networkId] = objectWeight
return objectWeight
for objectToUpdate in objectsToUpdate:
objectId = objectToUpdate.networkId
# (Re-)Add the object to the graph.
self.graph.add_node(objectId)
# Get the weight of this object.
objectWeight = weightOfObject(objectToUpdate)
# Add the connections to other objects already in the graph.
# (Each connection to an object not in the graph will be added when that object is added.)
# The weight of each edge is the average of the weights of the two objects it connects.
inputIds = set([objectInput.networkId for objectInput in objectToUpdate.inputs(recurse = False)])
outputIds = set([objectOutput.networkId for objectOutput in objectToUpdate.outputs(recurse = False)])