Commit 9d12164d authored by Binara's avatar Binara

get_fare fuction refactored

parent 9b730593
from asyncio.windows_events import NULL
from tokenize import ContStr from tokenize import ContStr
from turtle import distance from turtle import distance
from helpers import load_map_test, load_map_bus, load_map_train,route_177,route_176,route_8717 from helpers import load_map_test, load_map_bus, load_map_train,route_177,route_176,route_8717
...@@ -14,6 +15,7 @@ class PathPlanner(): ...@@ -14,6 +15,7 @@ class PathPlanner():
self.type = type self.type = type
self.range = 0 self.range = 0
self.cost = 0 self.cost = 0
self.allRoutes = [177,176,8717]
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
...@@ -78,7 +80,6 @@ class PathPlanner(): ...@@ -78,7 +80,6 @@ class PathPlanner():
self.record_best_path_to(current, neighbor) self.record_best_path_to(current, neighbor)
#self.range += self.dis #self.range += self.dis
print("No Path Found")
self.path = None self.path = None
return False return False
...@@ -218,32 +219,23 @@ class PathPlanner(): ...@@ -218,32 +219,23 @@ class PathPlanner():
for n in self.path[1:]: for n in self.path[1:]:
self.range = self.range+ distance(lastNode, n ) self.range = self.range+ distance(lastNode, n )
lastNode = n lastNode = n
return self.range return self.range
def get_fare(self,path): def get_fare(self,path):
currentRouteNo = self.map.routeNo[self.start] routeNumbers = []
for each in path:
temp = 0 routeNumbers.append(self.map.routeNo[each])
for x in path: #routeNumbers
if self.map.routeNo[x] == currentRouteNo:
#print('path is(x) =' + str(x)+ ' ,temp =' + str(temp))
temp+=1
currentRouteNo = self.map.routeNo[x]
else :
print("eeeeeeeeeeeeeeeeeeee")
self.func(currentRouteNo, temp)
currentRouteNo = self.map.routeNo[x]
temp = 0
print('cost = ', self.cost) for n in self.allRoutes:
val = routeNumbers.count(n)
if val >= 0:
self.funcc(n, val)
#cost = cost + route_177.get(temp)
return self.cost return self.cost
def func(self, no, nodes): def funcc(self, no, nodes):
print('fuction')
if(no == 177): if(no == 177):
self.cost = self.cost + route_177.get(nodes) self.cost = self.cost + route_177.get(nodes)
elif(no == 176): elif(no == 176):
...@@ -254,35 +246,27 @@ class PathPlanner(): ...@@ -254,35 +246,27 @@ class PathPlanner():
pass pass
# Get route # Get route
def main( a, start, destination): def main( val, start, destination):
if a == 3: if val == 3:
map = load_map_train() map = load_map_train()
elif a == 2: elif val == 2:
map = load_map_bus() map = load_map_bus()
else: else:
map = load_map_test() map = load_map_test()
planner = PathPlanner(map,start,destination) planner = PathPlanner(map,start,destination)
print(map.roads) #print(map.roads)
path = planner.path path = planner.path
print("Genarated path")
if path == False: if path == False:
print("No path Found", path) print("No path Found", path)
return return False
else: else:
print(path) print(path)
print('distance =' , planner.get_traveled_distance()) print('distance = ' , planner.get_traveled_distance()/10)
print(planner.get_fare(path)) fare = planner.get_fare(path)
print('trip RS.' , fare)
main( 1, 0, 3) main( 1, 1, 18)
\ No newline at end of file \ No newline at end of file
...@@ -8,6 +8,8 @@ from plotly.graph_objs import * ...@@ -8,6 +8,8 @@ from plotly.graph_objs import *
route_177 = { route_177 = {
0:0,
1: 34, 1: 34,
2: 42, 2: 42,
3: 54, 3: 54,
...@@ -26,12 +28,16 @@ route_177 = { ...@@ -26,12 +28,16 @@ route_177 = {
} }
route_176 = { route_176 = {
0:0,
1: 34, 1: 34,
2: 42, 2: 42,
3: 54, 3: 54,
} }
route_8717 = { route_8717 = {
0:0,
1: 20, 1: 20,
2: 20, 2: 20,
3: 20, 3: 20,
...@@ -40,7 +46,7 @@ route_8717 = { ...@@ -40,7 +46,7 @@ route_8717 = {
} }
map_test = { map_test = {
0: {'pos': (6.911034627182109, 79.84918916006576), 'connections': [1], 'name' : 'Kollupitiya','type': 0,'routeNo': 177, 'hValue': 1}, 0: {'pos': (6.911034627182109, 79.84918916006576), 'connections': [1,16], 'name' : 'Kollupitiya','type': 0,'routeNo': 177, 'hValue': 1},
1: {'pos': (6.911751932322411, 79.86194701315071), 'connections': [0,2], 'name' : 'Viharamahadevi Park', 'type': 0, 'routeNo': 177, 'hValue': 1}, 1: {'pos': (6.911751932322411, 79.86194701315071), 'connections': [0,2], 'name' : 'Viharamahadevi Park', 'type': 0, 'routeNo': 177, 'hValue': 1},
2: {'pos': (6.911385550864001, 79.87682791026592), 'connections': [1,3], 'name' : 'House Of Fashion', 'type': 0, 'routeNo': 177, 'hValue': 1}, 2: {'pos': (6.911385550864001, 79.87682791026592), 'connections': [1,3], 'name' : 'House Of Fashion', 'type': 0, 'routeNo': 177, 'hValue': 1},
3: {'pos': (6.911031363415147, 79.88498429384545), 'connections': [2,4], 'name' : 'Castle Street', 'type': 0, 'routeNo': 177, 'hValue': 1}, 3: {'pos': (6.911031363415147, 79.88498429384545), 'connections': [2,4], 'name' : 'Castle Street', 'type': 0, 'routeNo': 177, 'hValue': 1},
......
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