Commit c46fbaaebb49f83aa16b9954281b1707b8a3b0a3

Authored by Imanol-Mikel Barba Sabariego
1 parent 3449138d

Finished 18

Showing 1 changed file with 11 additions and 22 deletions
1 1 #!/usr/bin/python
2 2  
3 3 import sys
4   -import pdb
5 4  
6 5 class Node:
7   - parentNodes = []
8   - childNodes = []
9   - weight = 0
10   - value = 0
11 6  
12 7 def __init__(self,value):
  8 + self.parentNodes = []
  9 + self.childNodes = []
  10 + self.weight = 0
13 11 self.value = value
14 12  
15 13 def calcWeight(self):
... ... @@ -31,21 +29,20 @@ nodeMap = []
31 29 def buildNodeMap(nodeMap):
32 30 for i in range(0,len(nodeMap)):
33 31 for j in range(0,len(nodeMap[i])):
34   - node = nodeMap[i][j]
  32 + currentNode = nodeMap[i][j]
35 33  
36 34 if(i != len(nodeMap)-1):
37   - node.childNodes.append(nodeMap[i+1][j])
38   - node.childNodes.append(nodeMap[i+1][j+1])
39   -
  35 + currentNode.childNodes.append(nodeMap[i+1][j])
  36 + currentNode.childNodes.append(nodeMap[i+1][j+1])
40 37 if(i != 0):
41 38 if(j == 0):
42   - node.parentNodes.append(nodeMap[i-1][j])
  39 + currentNode.parentNodes.append(nodeMap[i-1][j])
43 40 elif(j == len(nodeMap[i])-1):
44   - node.parentNodes.append(nodeMap[i-1][j-1])
  41 + currentNode.parentNodes.append(nodeMap[i-1][j-1])
45 42 else:
46   - node.parentNodes.append(nodeMap[i-1][j])
47   - node.parentNodes.append(nodeMap[i-1][j-1])
48   -
  43 + currentNode.parentNodes.append(nodeMap[i-1][j])
  44 + currentNode.parentNodes.append(nodeMap[i-1][j-1])
  45 +
49 46  
50 47 def dijkstraReverse(nodeMap):
51 48 for row in nodeMap:
... ... @@ -59,8 +56,6 @@ for line in sys.stdin:
59 56 nodeMap[numRow].append(Node(int(elem)))
60 57 numRow += 1
61 58  
62   -pdb.set_trace()
63   -
64 59 buildNodeMap(nodeMap)
65 60 nodeMap.append([])
66 61 targetNode = Node(0)
... ... @@ -69,12 +64,6 @@ for node in nodeMap[-2]:
69 64  
70 65 nodeMap[-1].append(targetNode)
71 66  
72   -for row in nodeMap:
73   - string = ""
74   - for node in row:
75   - string += str(node) + " "
76   - print string
77   -
78 67 dijkstraReverse(nodeMap)
79 68  
80 69 print "Result is: " + str(targetNode.weight)
... ...