Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-020
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
O.V.B Sewmina
2022-020
Commits
06d339dd
Commit
06d339dd
authored
Oct 09, 2022
by
O.V.B Sewmina
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'IT19186566' into 'master'
It19186566 See merge request
2022-020/2022-020!18
parents
addb6bbe
9b730593
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
42 deletions
+96
-42
routeplanner/AL.py
routeplanner/AL.py
+68
-27
routeplanner/helpers.py
routeplanner/helpers.py
+21
-8
routeplanner/test.py
routeplanner/test.py
+7
-7
No files found.
routeplanner/AL.py
View file @
06d339dd
from
helpers
import
load_map_test
,
load_map_bus
,
load_map_train
,
route_177
from
tokenize
import
ContStr
from
turtle
import
distance
from
helpers
import
load_map_test
,
load_map_bus
,
load_map_train
,
route_177
,
route_176
,
route_8717
import
math
val
=
0
class
PathPlanner
():
def
__init__
(
self
,
M
,
start
=
None
,
goal
=
None
,
type
=
None
):
self
.
map
=
M
self
.
start
=
start
self
.
goal
=
goal
self
.
type
=
type
self
.
dis
=
0
self
.
range
=
0
self
.
cost
=
0
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
.
cameFrom
=
self
.
create_cameFrom
()
if
goal
!=
None
and
start
!=
None
else
None
...
...
@@ -73,9 +74,10 @@ class PathPlanner():
# This path is the best until now. Record it!
global
val
#
val
=
val
+
self
.
dis
self
.
record_best_path_to
(
current
,
neighbor
)
#self.range += self.dis
print
(
"No Path Found"
)
self
.
path
=
None
return
False
...
...
@@ -149,10 +151,6 @@ class PathPlanner():
"""Returns the neighbors of a node"""
return
set
(
self
.
map
.
roads
[
node
])
def
get_traveled_distance
(
self
):
#traveled_distance
return
self
.
dis
#-------------------------------- Calculations --------------------------------#
def
get_gScore
(
self
,
node
):
...
...
@@ -210,12 +208,55 @@ class PathPlanner():
# calculate the result
dist
=
(
c
*
r
)
#print (dist)
self
.
dis
=
dist
#
self.dis = dist
return
dist
def
get_traveled_distance
(
self
):
#traveled_distance
lastNode
=
self
.
start
for
n
in
self
.
path
[
1
:]:
self
.
range
=
self
.
range
+
distance
(
lastNode
,
n
)
lastNode
=
n
return
self
.
range
def
get_fare
(
self
,
path
):
currentRouteNo
=
self
.
map
.
routeNo
[
self
.
start
]
temp
=
0
for
x
in
path
:
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
)
#cost = cost + route_177.get(temp)
return
self
.
cost
def
func
(
self
,
no
,
nodes
):
print
(
'fuction'
)
if
(
no
==
177
):
self
.
cost
=
self
.
cost
+
route_177
.
get
(
nodes
)
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
def
main
(
a
,
node1
,
node2
):
def
main
(
a
,
start
,
destination
):
if
a
==
3
:
map
=
load_map_train
()
elif
a
==
2
:
...
...
@@ -223,25 +264,25 @@ def main( a, node1, node2):
else
:
map
=
load_map_test
()
planner
=
PathPlanner
(
map
,
node1
,
node2
)
planner
=
PathPlanner
(
map
,
start
,
destination
)
print
(
map
.
roads
)
path
=
planner
.
path
print
(
'distance ='
,
val
)
if
path
==
[
5
,
16
,
37
,
12
,
34
]:
print
(
"code works for test path!!!"
)
print
(
path
)
else
:
print
(
"Genarated path"
)
print
(
"Genarated path"
)
if
path
==
False
:
print
(
"No path Found"
,
path
)
return
else
:
print
(
path
)
print
(
'distance ='
,
planner
.
get_traveled_distance
())
print
(
planner
.
get_fare
(
path
))
# for x in path:
# if routeNo
# print (x)
#for each in path:
main
(
1
,
2
,
14
)
\ No newline at end of file
main
(
1
,
0
,
3
)
\ No newline at end of file
routeplanner/helpers.py
View file @
06d339dd
...
...
@@ -4,7 +4,6 @@ import pickle
from
chart_studio
import
plotly
as
py
import
random
from
plotly.graph_objs
import
*
from
plotly.offline
import
init_notebook_mode
,
plot
,
iplot
#init_notebook_mode(connected=True)
...
...
@@ -26,13 +25,27 @@ route_177 = {
15
:
163
,
}
route_176
=
{
1
:
34
,
2
:
42
,
3
:
54
,
}
route_8717
=
{
1
:
20
,
2
:
20
,
3
:
20
,
4
:
20
,
5
:
40
}
map_test
=
{
0
:
{
'pos'
:
(
6.911034627182109
,
79.84918916006576
),
'connections'
:
[
1
],
'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
},
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
},
4
:
{
'pos'
:
(
6.908462881966912
,
79.89338919261249
),
'connections'
:
[
3
,
5
],
'name'
:
'Rajagiriya'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
5
:
{
'pos'
:
(
6.906663916178293
,
79.90205413217801
),
'connections'
:
[
4
,
6
],
'name'
:
'H
sbc
Rajagiriya'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
5
:
{
'pos'
:
(
6.906663916178293
,
79.90205413217801
),
'connections'
:
[
4
,
6
],
'name'
:
'H
SBC
Rajagiriya'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
6
:
{
'pos'
:
(
6.90333333857459
,
79.90747047529919
),
'connections'
:
[
5
,
7
],
'name'
:
'Ethulkotte New'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
7
:
{
'pos'
:
(
6.903185701293392
,
79.91168232658337
),
'connections'
:
[
6
,
8
],
'name'
:
'Parliament Junction'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
8
:
{
'pos'
:
(
6.902102452411621
,
79.91741047710077
),
'connections'
:
[
7
,
9
],
'name'
:
'Battaramulla Junction'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
...
...
@@ -41,12 +54,12 @@ map_test = {
11
:
{
'pos'
:
(
6.9084657304543455
,
79.9383708894408
),
'connections'
:
[
10
,
12
],
'name'
:
'Kotte-Bope'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
12
:
{
'pos'
:
(
6.9085023402918155
,
79.94425286198016
),
'connections'
:
[
11
,
13
],
'name'
:
'Thalahena Junction'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
13
:
{
'pos'
:
(
6.903962700873259
,
79.95430199947661
),
'connections'
:
[
12
,
14
],
'name'
:
'Malabe'
,
'type'
:
0
,
'routeNo'
:
177
,
'hValue'
:
1
},
14
:
{
'pos'
:
(
6.933539686667202
,
79.85005389798111
),
'connections'
:
[
15
],
'name'
:
'Fort'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
15
:
{
'pos'
:
(
6.923619774894732
,
79.84965509086771
),
'connections'
:
[
14
,
16
],
'name'
:
'Kompannavidiya'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
16
:
{
'pos'
:
(
6.911282166657041
,
79.84821747831087
),
'connections'
:
[
15
,
1
,
17
],
'name'
:
'Kollupitiya'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
17
:
{
'pos'
:
(
6.893710110662125
,
79.85300590028642
),
'connections'
:
[
16
,
18
],
'name'
:
'Bambalapitiya'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
18
:
{
'pos'
:
(
6.875030063532378
,
79.85744793142631
),
'connections'
:
[
17
,
19
],
'name'
:
'Wellawatte'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
19
:
{
'pos'
:
(
6.850915755796403
,
79.8620969312958
),
'connections'
:
[
18
],
'name'
:
'Dehiwala
'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
14
:
{
'pos'
:
(
6.933539686667202
,
79.85005389798111
),
'connections'
:
[
15
],
'name'
:
'Fort
_TR
'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
15
:
{
'pos'
:
(
6.923619774894732
,
79.84965509086771
),
'connections'
:
[
14
,
16
],
'name'
:
'Kompannavidiya
_TR
'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
16
:
{
'pos'
:
(
6.911282166657041
,
79.84821747831087
),
'connections'
:
[
15
,
1
,
17
],
'name'
:
'Kollupitiya
_TR
'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
17
:
{
'pos'
:
(
6.893710110662125
,
79.85300590028642
),
'connections'
:
[
16
,
18
],
'name'
:
'Bambalapitiya
_TR
'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
18
:
{
'pos'
:
(
6.875030063532378
,
79.85744793142631
),
'connections'
:
[
17
,
19
],
'name'
:
'Wellawatte
_TR
'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
19
:
{
'pos'
:
(
6.850915755796403
,
79.8620969312958
),
'connections'
:
[
18
],
'name'
:
'Dehiwala
_TR
'
,
'type'
:
1
,
'routeNo'
:
8717
,
'hValue'
:
1
},
}
...
...
routeplanner/test.py
View file @
06d339dd
from
helpers
import
load_map_
40
from
helpers
import
load_map_
test
MAP_
40_
ANSWERS
=
[
MAP_ANSWERS
=
[
(
5
,
34
,
[
5
,
16
,
37
,
12
,
34
]),
(
5
,
5
,
[
5
]),
(
8
,
24
,
[
8
,
14
,
16
,
37
,
12
,
17
,
10
,
24
])
]
def
test
(
shortest_path_function
):
map
_40
=
load_map_40
()
map
=
load_map_test
()
correct
=
0
for
start
,
goal
,
answer_path
in
MAP_
40_
ANSWERS
:
path
=
shortest_path_function
(
map
_40
,
start
,
goal
)
.
path
for
start
,
goal
,
answer_path
in
MAP_ANSWERS
:
path
=
shortest_path_function
(
map
,
start
,
goal
)
.
path
if
path
==
answer_path
:
correct
+=
1
print
(
"For start:"
,
start
,
...
...
@@ -19,8 +19,8 @@ def test(shortest_path_function):
"Correct: "
,
answer_path
)
else
:
print
(
"Error Testing faild !!!"
)
if
correct
==
len
(
MAP_
40_
ANSWERS
):
if
correct
==
len
(
MAP_ANSWERS
):
print
(
"All tests pass "
)
else
:
print
(
"Only passed"
,
correct
,
"/"
,
len
(
MAP_
40_
ANSWERS
),
"test cases"
)
print
(
"Only passed"
,
correct
,
"/"
,
len
(
MAP_ANSWERS
),
"test cases"
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment