Commit 9b730593 authored by Binara's avatar Binara

refactoring get_fare fuction

parent 2cc6a52b
...@@ -13,6 +13,7 @@ class PathPlanner(): ...@@ -13,6 +13,7 @@ class PathPlanner():
self.goal = goal self.goal = goal
self.type = type self.type = type
self.range = 0 self.range = 0
self.cost = 0
self.closedSet = self.create_closedSet() if goal != None and start != None else None self.closedSet = self.create_closedSet() if goal != None and start != None else None
self.openSet = self.create_openSet() if goal != None and start != None else None self.openSet = self.create_openSet() if goal != None and start != None else None
self.cameFrom = self.create_cameFrom() if goal != None and start != None else None self.cameFrom = self.create_cameFrom() if goal != None and start != None else None
...@@ -221,31 +222,38 @@ class PathPlanner(): ...@@ -221,31 +222,38 @@ class PathPlanner():
return self.range return self.range
def get_fare(self,path): def get_fare(self,path):
cost = 0
currentRouteNo = self.map.routeNo[self.start] currentRouteNo = self.map.routeNo[self.start]
temp = 0 temp = 0
for x in path: for x in path:
if self.map.routeNo[x] == currentRouteNo: if self.map.routeNo[x] == currentRouteNo:
print('path is(x) =' + str(x)+ ' ,temp =' + str(temp) + ' ,cost =' + str(cost)) #print('path is(x) =' + str(x)+ ' ,temp =' + str(temp))
temp+=1 temp+=1
else: currentRouteNo = self.map.routeNo[x]
if(currentRouteNo == 177): else :
cost = cost + route_177.get(temp) print("eeeeeeeeeeeeeeeeeeee")
temp = 0 self.func(currentRouteNo, temp)
currentRouteNo = self.map.routeNo[x] currentRouteNo = self.map.routeNo[x]
elif(currentRouteNo == 176): temp = 0
cost = cost + route_176.get(temp)
temp = 0 print('cost = ', self.cost)
currentRouteNo = self.map.routeNo[x]
elif(currentRouteNo == 8717): #cost = cost + route_177.get(temp)
cost = cost + route_8717.get(temp) return self.cost
temp = 0
currentRouteNo = self.map.routeNo[x] def func(self, no, nodes):
else: print('fuction')
temp = 0 if(no == 177):
cost = cost + route_177.get(temp) self.cost = self.cost + route_177.get(nodes)
return cost elif(no == 176):
self.cost = self.cost + route_176.get(nodes)
elif(no == 8717):
self.cost = self.cost + route_8717.get(nodes)
else:
pass
# Get route # Get route
def main( a, start, destination): def main( a, start, destination):
...@@ -268,7 +276,7 @@ def main( a, start, destination): ...@@ -268,7 +276,7 @@ def main( a, start, destination):
else: else:
print(path) print(path)
print('distance =' , planner.get_traveled_distance()) print('distance =' , planner.get_traveled_distance())
#print(planner.get_fare(path)) print(planner.get_fare(path))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment