Skip to content

Instantly share code, notes, and snippets.

@foxx
Created January 24, 2018 14:02
Show Gist options
  • Save foxx/e01a65470b6e0b024c70c3ee74efabf6 to your computer and use it in GitHub Desktop.
Save foxx/e01a65470b6e0b024c70c3ee74efabf6 to your computer and use it in GitHub Desktop.

Revisions

  1. Max created this gist May 19, 2013.
    17 changes: 17 additions & 0 deletions gistfile1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    def comParsing():
    global comDist,n,nodeCoordinates
    n = int(graph.split('\n')[0].split())
    for i in graph.split('\n')[1:]:
    nodeCoordinates.append((int(i.split()[0]), int(i.split()[1])))
    for i,index in zip(nodeCoordinates,range(n)):
    for j,index2 in zip(nodeCoordinates,range(n)):
    comDist[index][index2]=math.sqrt((nodeCoordinates[j][0]-nodeCoordinates[i][0])**2+(nodeCoordinates[j][1]-nodeCoordinates[i][1])**2) #rasstoyanie ot i do vseh j

    def commivoyager():
    curr=0
    comPath=[]
    comPath.push(curr)
    while(!len(comPath)==n):
    curr=comDist[curr].index(min(comDist[curr]))
    comPath.push(curr)
    print comPath