Bu araya matris okuma işlemi yapılmalı, matris dosyasını maalesef burada okutamıyorum,
8000 karakter sorunu var... matrice değişkeni cevap bölümündeki resimde de görülüyor,
içi öyle olacak, aksi halde çalışmaz bu kod...
def CreateWeightMatrix():
for i in range(DIMENSIONONEMINUS):
for j in range(DIMENSIONONEMINUS):
snode=(i*DIMENSION)+j
row,col=i+1,j+1
e1node,e2node=DIMENSION*i+col,DIMENSION*row+j
weight[snode][e1node]=matrice[i][col]
weight[snode][e2node]=matrice[row][j]
#print("i=",i,"j=",j,"start node=",snode,"end node=",e1node,"same row=",i,"next col=",col,matrice[i][col])
#print("i=",i,"j=",j,"start node=",snode,"end node=",e2node,"next row=",row,"same col=",j,matrice[row][j])
i=DIMENSIONONEMINUS
for j in range(DIMENSIONONEMINUS):
snode=(i*DIMENSION)+j
enode=snode+1
weight[snode][enode]=matrice[i][j+1]
j=DIMENSIONONEMINUS
for i in range(DIMENSIONONEMINUS):
snode=(i*DIMENSION)+j
enode=snode+DIMENSION
weight[snode][enode]=matrice[i+1][j]
CreateWeightMatrix()
#print(weight)
distance=[INFINITY]*MAXNODES
distance[0]=0
FINALNODE=MAXNODES-1
def Solve():
used=[0]*MAXNODES
s=0
used[s],distance[s],current=1,0,s
while current!=(FINALNODE):
#print("current=",current)
smalldist=INFINITY
distancecurrent=distance[current]
for i in range(MAXNODES):
if used[i]!=1:
newdistance=distancecurrent+weight[current][i]
if newdistance<distance[i]:
distance[i]=newdistance
if distance[i]<smalldist:
smalldist=distance[i]
#print("smalldist=",smalldist)
k=i
current=k
used[current]=1
#print(distance)
#print(current)
#print(used)
print("Starting Part=")
Solve()
print("Answer is=",distance[FINALNODE]+matrice[0][0])
print(time.time()-time1)