本文整理汇总了Python中label.Label.expand方法的典型用法代码示例。如果您正苦于以下问题:Python Label.expand方法的具体用法?Python Label.expand怎么用?Python Label.expand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类label.Label
的用法示例。
在下文中一共展示了Label.expand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RouteFinder
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import expand [as 别名]
class RouteFinder():
def __init__(self, graph):
"""
"""
self.graph = graph
self.bridges = []
self.results = []
def expandLabel(self, parentLabel):
"""
"""
expansion = [] # list of labels
newLabel = None #
#out_edges = self.graph.edges(parentLabel.getNode(), self.graph)
#out_edges = [e[2].get('edge') for e in out_edges]
#print "expanding label at" + str(parentLabel.getNode().getAttributes()) + " " + str(len(out_edges))
# for edge in out_edges:
# print edge.getAttributes()
print "------"
print "Length " ,len(parentLabel.getNode().getOutEdges()) , parentLabel.getNode().getAttributes().get("nodecounter")
for e in parentLabel.getNode().getOutEdges():
print "Outedge " , e.getAttributes()
for currentEdge in parentLabel.getNode().getOutEdges():
# check constraints
# import pdb;pdb.set_trace()
length = parentLabel.getLength() + currentEdge.getLength()
print "currentEdge " + str(currentEdge.getAttributes())
# newLabel = Label(currentEdge.getToNode(), parent=parentLabel, back_edge=currentEdge, length=length)
newLabel = Label(currentEdge.getOutNode(parentLabel), parent=parentLabel, back_edge=currentEdge, length=length)
# if len(newLabel.getNode().getOutEdges()) == 1:
# break
# edgeOccurances = newLabel.getOccurancesOfEdge(newLabel)
# isInBridges = True
# try:
# self.bridges.index(newLabel)
# except ValueError:
# isInBridges = False
#
# if (isInBridges) and edgeOccurances > BRIDGE_OVERLAP:
# print "break (isInBridges)"
# break
# path length including this segment longer that MAXIMUM_LENGTH
# constraint
if (length > MAXIMUM_LENGTH):
print "break (MAXLENGTH)"
break
print ".."
# euclidean distance to endNode > maxLength * distancefactor
distanceToEndNode = newLabel.getNode().getGeometry().distance(self.end_node.getGeometry())
totalLength = newLabel.getLength() + distanceToEndNode
if totalLength > (MAXIMUM_LENGTH * DISTANCE_FACTOR):
print "break : euclidian distance greater than max"
break
nodeOccurances = newLabel.getOccurancesOfNode(newLabel.getNode())
if nodeOccurances > NODE_OVERLAP:
print "node occurance break (%d) at %s." % (nodeOccurances, str(currentEdge.getAttributes()))
break
self.num_labels = self.num_labels + 1
expansion.append(newLabel)
return expansion
def checkNodeOverlap(self, label):
nc = label.getOccurancesOfNode(label.getNode())
return nc > NODE_OVERLAP
def iterative_expansion(self, label):
print "Checking Label at " , label.getNode().getAttributes()
if label.getNode() is self.end_node:
self.results.append(label)
return None
else:
print "Expanding Label at " , label.getNode().getAttributes()
labels = self.expandLabel2(label)
for label2 in labels:
print "Checking node overlap for node ", label2.getNode().getAttributes().get("nodecounter")
#.........这里部分代码省略.........