本文整理汇总了Python中optimizer.Optimizer.solveSA方法的典型用法代码示例。如果您正苦于以下问题:Python Optimizer.solveSA方法的具体用法?Python Optimizer.solveSA怎么用?Python Optimizer.solveSA使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optimizer.Optimizer
的用法示例。
在下文中一共展示了Optimizer.solveSA方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: salesman
# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import solveSA [as 别名]
def salesman(undirectedgraph, checkpoints):
print("call to salesman")
#TODO: Make a distance Dict
distances = {}
path = {}
#TODO: iterate through all to all checkpoints
for checkpoint in checkpoints:
print("enter iteration")
distances[checkpoint[0]] = {}
distances[checkpoint[0]]['lat'] = checkpoint[1]
distances[checkpoint[0]]['long'] = checkpoint[2]
path[checkpoint[0]] = {}
for check in checkpoints:
if check[0] == checkpoint[0]:
#TODO: is NAN
print("did nothing")
else:
print("made a node")
#TODO: Make nodes
#print (checkpoint[1], checkpoint[2], check[1], check[2])
sourcenode = Node(checkpoint[1], checkpoint[2])
targetnode = Node(check[1], check[2])
#TODO: calculate shortest path with dijkstra
pathstack, distancefromsource = dijkstra(undirectedgraph, sourcenode, targetnode)
#TODO: Add to distance dict
print (distancefromsource)
distances[checkpoint[0]][check[0]] = distancefromsource
path[checkpoint[0]][check[0]] = pathstack
#TODO: Thus we optimize
travellingsolver = Optimizer(distances)
travellingsolution = travellingsolver.solveSA()
print ("made it!")
print(path)
return path, travellingsolution