0
좋아, 코드를 조금 변경했지만 가장 가까운 신경 기능에 전달해야하는 변수 이름을 혼동스러워합니다. 이 두 가지 기능은 확인 작업 :Dijkstra의 가장 가까운 이웃 확인
infinity = 1000000
invalid_node = -1
startNode = 0
#Values to assign to each node
class Node:
def __init__(self):
self.distFromSource = infinity
self.previous = invalid_node
self.visited = False
#read in all network nodes
#node = the distance values between nodes
def network():
f = open ('network.txt', 'r')
theNetwork = [[int(networkNode) for networkNode in line.split(',')] for line in f.readlines()]
#theNetwork = [[int(node) for node in line.split(',')] for line in f.readlines()]
#print theNetwork
return theNetwork
#for each node assign default values
#populate table with default values
def populateNodeTable():
nodeTable = []
index = 0
f = open('network.txt', 'r')
for line in f:
networkNode = map(int, line.split(','))
nodeTable.append(Node())
#print "The previous node is " ,nodeTable[index].previous
#print "The distance from source is " ,nodeTable[index].distFromSource
#print networkNode
index +=1
nodeTable[startNode].distFromSource = 0
return nodeTable
그래서, 잘 좋은. 그러나, 다음 함수는 나에게 오류를주고있다. 그리고 나에도 불구하고 문제를 해결할 수 없다.
def nearestNeighbour(nodeTable, theNetwork):
listOfNeighbours = []
nodeIndex = 0
for networkNode in nodeTable[currentNode]:
if networkNode != 0 and networkNode.visited == False:
listOfNeighbours.append(nearestNode)
nodeIndex +=1
print listOfNeighbours
## #print node.distFromSource, node.previous, node.visited
##
return listOfNeighbours
for networkNode in nodeTable[currentNode]:
TypeError: iteration over non-sequence
"코드를 조금 변경했습니다"- 무엇에서 변경 했습니까? 후속 질문 인 경우 이전 질문에 대한 링크를 추가하여 모든 사람이 상황을 이해할 수 있도록하십시오. – MAK
이전 코드를 가져 오기 위해 편집을 롤백 할 수없는 것 같습니다. 그렇습니다. 그래서 가장 가까운 Nieigbour 함수에 어떤 진입도하지 않고 있습니다. 왜 그런지 모르겠습니다. – user612041