This is a C++ project based on the Boost Graph Library (BGL) which solves a path planning and optimization problem. The problem presents a situation where an agent needs to traverse an elevation map in the least time possible with constraints including different obstacle types and variable speed over elevation gradients. This project proposes and develops an agent motion model with realistic constants, and uses it for path optimization.
$ git clone https://github.com/jimdsouza/fastestpath.git
$ cd fastestpath
$ mkdir build && cd build
$ cmake ..
$ make
$ ./Bachelor
A bachelor stranded on an island (BACHELOR_X, BACHELOR_Y)
, needs to get to his wedding location (WEDDING_X, WEDDING_Y)
using an AUDI rover (ROVER_X, ROVER_Y)
; both located in the same island.
The island map has 2048x2048
cells, each of which have a terrain type and elevation index.
The terrain types are:
- Rivers
- Marsh land
- Water basin
- Land
The rover can only traverse on land. Additionally, every cell on land has an elevation value between 1
to 255
. The rover travels with a constant speed of 1 cell per island second
. It is faster on slopes going down and slower on positive slopes.
-
Build a rover speed model with plausible assumptions.
-
Find the fastest path from
ROVER
toBACHELOR
toWEDDING
.
-
1 island second = 1 second.
-
The rover can traverse any gradient on
elvevation > 0
on the island. -
Maximum angle of slope between two adjacent cells is
45 $\degrees$
, since it's assumed the rover cannot physically climp a steeper slope without slipping. -
The car model assumed to be the AUDI Q5 with the following parameters:
- Kerb weight or mass =
1850 kg
- Maximum power =
200 kW
- Top speed (at maximum power) =
200 kph
or55.5 m/s
Given that the code is required to be production grade, I decided to employ the help of one of the most highly regarded C++ libraries, the Boost Graph Library (BGL). It's a header-only library, so its effects on compilation time are negligible. Plus, only the relevant dependencies are included in this repo.
The cells of the island map are modelled as nodes of a grid graph. I've removed the subset of nodes from the grid which correspond to non-traversible cells of the map such as water and marsh lands.
A maze (grid class) member function m_timeWeight(vertex A, vertex B, elevation)
takes in two vertices and the elevation amp, and uses equations for t_aup t_adn t_dup tddn
(derived in #rover-time), to determine the time taken by the rover to travel from A
to B
. The output of the function is modelled as the weight of the edge between the two vertices A
and B
.
I use A-Star search with the a manhattan distance heuristic function to find the path where the rover takes the least time to get from [ROVER_X, ROVER_Y]
to [BACHELOR_X, BACHELOR_Y]
and then to [WEDDING_X, WEDDING_Y]
.
$./Bachelor
Number of non-traversable cells: 2061148
Rover has reached the bachelor!
Time taken by rover to reach the bachelor is 57543.6 island seconds.
The bachelor has reached his wedding!
Time taken by the rover to reach the wedding from the bachelor's position is 5701.29 island seconds.
Total time taken = 63244.8 island seconds.
Or in island time, the entire trip took 17 hours 34 minutes 4 seconds.
You can open the map with $feh pic.bmp or $edisplay pic.bmp on Linux systems.
The dimension of each square cell is
The maximum elevation any cell can have is
According to our third assumption, the maximum angle between two traversible adjacent cells is
It's given that the speed of the rover on level ground on maximum power
Since the max speed of the Audi Q5 is assumed to be 55.5 m/s
(Assumption #4) and one island second is assumed to be one real second (assumption #1), it follows,
The power
When the car, whose weight is
Here
Similarly,
Where
Let time taken for the rover to travel up and down two adjacent cells be
Since,
We get,
Where,
Similar to
Here, the diagonal travel distance on the incline becomes
So, the time taken to travel up (
and,