Your team was asked to program a self-driving car that reaches its destination with minimum travel time.
Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are given.
(I just need the algorithm for it thanks!)
Given:
velocity of car = v m/s (assumed m/s for more detailed
calculations)
2 routes.
Assuming no acceleration of car and initial velocity is v.
Algorithm:
Divide each route in v meters. Making node at points v meters
apart.
call the function update_neighbours for every node in both paths.
Use of A* algorithm which will give us minimum route and the
path which should be taken for the same.
Call function AStar.
store the path in a list.
\\ This list stores the path that should be taken by car.
function AStar(start, goal, h)
openSet := {start}
cameFrom := an empty map
gScore := map with default value of Infinity
gScore[start] := 0
fScore := map with default value of Infinity
fScore[start] := h(start)
while openSet is not empty
// This operation can occur in O(1) time if openSet is a min-heap
or a priority queue
current := the node in openSet having the lowest fScore[]
value
if current = goal
return True, cameFrom
openSet.Remove(current)
for each neighbor of current
tentative_gScore := gScore[current] + d(current, neighbor)
if tentative_gScore < gScore[neighbor]
cameFrom[neighbor] := current
gScore[neighbor] := tentative_gScore
fScore[neighbor] := gScore[neighbor] + h(neighbor)
if neighbor not in openSet
openSet.add(neighbor)
return failure
function update_neighbours(startnode):
if node next to right of startnode is not barrier
startnode.neighbour = node
if node next to left of startnode is not barrier
startnode.neighbour = node
if node next to above of startnode is not barrier
startnode.neighbour = node
if node next to below of startnode is not barrier
startnode.neighbour = node
Get Answers For Free
Most questions answered within 1 hours.