Home > Sample essays > To what extent does each pathfinding algorithm have their own advantage to solve a problem?

Essay: To what extent does each pathfinding algorithm have their own advantage to solve a problem?

Essay details and download:

  • Subject area(s): Sample essays
  • Reading time: 10 minutes
  • Price: Free download
  • Published: 1 April 2019*
  • Last Modified: 23 July 2024
  • File format: Text
  • Words: 3,014 (approx)
  • Number of pages: 13 (approx)

Text preview of this essay:

This page of the essay has 3,014 words.



Extended Essay

To what extent does each pathfinding algorithm have their own advantage to solve a problem?

Subject: Computer Science

Candidate Number:

Supervisor:

Table of Contents

1. Introduction 2

1.1 Background Information 2

1.2 Objective 3

2. Pathfinding Algorithms 4

2.1 General Description 4

2.2 Dijkstra’s 5

2.3 A* 7

2.4 Trace 8

2.5 Heuristics 8

3. Experiment 9

3.1 Overview 9

3.2 Method 11

3.3 Hypothesis 12

3.4 Variables 12

3.5 Results 13

3.6 Analysis 15

4 Conclusion 17

4.1 Evaluation 18

Bibliography 18

1. Introduction

1.1 Background Information

We live in a great era of technological advancement where gadgets of all kinds exist, one of the most influential being the mobile phones which has integrated into everyone’s lives. As well as it being a communication device, it also includes a GPS (Global Positioning System) chip which allows it to act as a navigation system which leads you to your chosen destination. People are less likely to use the traditional method of finding the route on a map as the speed of the action is incomparable to a computer. The GPS consists of two main components; the map and the algorithm.

The average user does not realize how many algorithms take part to make it work. Not only are these algorithms beneficial for humans to find their way around, but also to automated machines operating in industries such as shelving goods in large warehouses. These are also used for space exploration and robots that have been invented whose only purpose is to explore environments unfit for humans, such as the rover on Mars.

However this is not the end of the capabilities of pathfinding algorithms. They are not only used to find a physical path but can find the best route within financial trading systems in order to prevent money loss as well as commonly used in natural language processing and town planning.

However, to make these softwares and to make it successful one must know how to program it to be able to calculate the quickest route possible from location A to B.

1.2 Objective

Due to the progression, it will be almost essential to be able to program in the near future and these pathfinding algorithms will be deeply wired within most softwares. Accordingly, it is necessary to be able to distinguish between these algorithms and thus answer the question;

“To what extent does each pathfinding algorithm have their own advantage to solve a problem?”

To solve the problem of finding the most efficient path, people have developed multiple algorithms each with its own strength and weaknesses, they are called pathfinding algorithms. In this essay I will be investigating the three most popular algorithms; A*, Dijkstra’s, and Trace.

2. Pathfinding Algorithms

2.1 General Description

Pathfinding algorithms are a sequence of steps that create an automated solution to find a path using multiple set points called nodes without colliding into other agents. These agents could be anything obstructing the path, such as walls or buildings. The solution may or may not be the most optimal path depending on the algorithm used. Figure 2.1.1 shows a network which is made up from nodes and links (also called edges), just as how a computer may interpret it.

Each link has a value which is noted as an integer which represents their lengths. These values show the cost if you were to travel up to that node. All pathfinders favours the vertices which are closest to it. Initially all the nodes start off as “unsolved” this means that the computer has not yet visited that node and does not know its value, once it does it will be labeled as “solved” and placed into the according set. This is to make sure that that node will never be visited again.  In the beginning of the search the solved set only has one element; the starting node. Pathfinding algorithms use this information by finding the best sequence of nodes, from start to finish, which will result with the lowest traversal cost. The nodes used to make the paths are stored in a directed tree, starting from the source node.

As an example, in order to find the most optimal route from A to G, you have to compare all the paths.

A → B → D → E → G

4 + 3 + 5 + 8 = 20

A → B → D → F → G

4 + 3 + 7 + 3 = 17

A → C → D → E → G

5 + 2 + 5 + 8 = 20

A → C → D → F → G

5 + 2 + 7 + 3 = 17

A → C → F → G

5 + 8 + 3 = 16

As shown the traversal cost of the path  A, C, F, G is the smallest, however, if this were to be applied to a large-scale map then the equations will get much more complex and it would be practical calculating all the routes even if a computer were to do it. Therefore, not many algorithms will get to the same conclusion as they prioritize different factors such as speed, operations and distance.

2.2 Dijkstra’s

Dijkstra’s (also called Uniform Cost Search) is an uninformed algorithm which means that it searches from a single source so there is no need for heuristics. It was developed in 1956 with the intention of finding more than one destination, due to this Dijkstra searches by expanding equally in each direction. However, the pathfinder will only “see” the values of the nodes that it has visited, therefore, it has to explore and maintain a tree of paths until the least costly path is found.

Once the target node is found, it stops searching. For example if the network diagram given in figure 1 is used to find the shortest route using Dijkstra’s algorithm it will search as following:

It will start on the first node (A), the distance to source vertex is zero and set all other distances to infinity.

The set of visited nodes is initially empty and the initial node is set to current.

The priority queue contains all the unsolved neighbour nodes (B and C). It selects the node with the smallest distance (B) and calculates the tentative distance. This node will be marked as solved.

It will compare this newly calculated cost and compare it with the current cost, the smallest one will be assigned to a list.

Traversal cost = distance to solved node + length of edge

A → B is 0 + 4 = 4 A → C is 0 + 5 = 5

The distance to B through A is smaller than distance A to C. If it is not smaller then it will loop back to step 3.

If there are no more unvisited nodes then it will go back to step 2.

Finally it will repeat this process until the ending node G will be found and end the process.

If it ends up having two nodes with the same length then one of them will be chosen arbitrarily. The end result will be A → B → D → F → G.

2.3 A*

A* was invented in 1968 and it is a more complex version of Dijkstra’s algorithm and has numerous variations. When used properly it can find the shortest route with the lowest traversal cost possible. Considering the information given in figure 2.1.1, it is crucial but not enough for A* to funcion. It is instead an informed search algorithm that depends on heuristic estimates which allows the algorithm to make an “educated guess” of where the ending node is. It is the most widely used pathfinder as it is flexible and can be used in many different situations, mainly in video games.

It works by assigning a weight to each solved node which is proportional to the traversial cost if it were to travel up that edge. This is calculated by adding the weight of the edge of the current node to the approximate distance between that node and the target node.

f(x) = g(x) + h(x)

Where,

x is the last node on the path

g(x) is the movement cost from the starting node to a given available node

h(x) is the estimated movement cost to reach the end node (heuristic value)

The heuristic value is always constant and they do not overestimate the distance to the ending node

2.4 Trace

The Trace algorithm, is like the Dijkstra, chooses the next node with the smallest cost and it too expands in all directions. The minor difference is that the Trace algorithm estimates where the ending node is, this also includes in what direction it lies. If the ending node sits in the east then the pathfinder will most likely travel up the nodes that lead in that directions whereas Dijkstra would’t.

Using Trace on figure 1 we get the following results: A → B → D → E → G

2.5 Heuristics

The objective of a heuristic is to give a rough estimate of the remaining distance to the goal, due to this fact the heuristic value will be based merely on assumptions and will be slightly off the actual value. However, the distance cannot be majorly under or overestimated. If it were to be overestimated then the algorithm may not find the ending node as it would constantly overshoot and if it does find it then it would not be the shortest path, however, if it were underestimated then the frontier would be larger and more time would be spent finding the ending node. To prevent this from happening the grid has x and y values. This allows it to prioritise one computation path over others. If h(x) were to be zero then every single vertex would be visited which is exactly what Dijkstra’s algorithm does. The type of heuristic that is used depends entirely on the nature of the problem. Both A* and Trace need heuristics to work. All of the heuristics work in a similar way by using this function:

There are 4 types given in the simulation; Manhattan, Euclidean, Octile and Chebyshev.

Manhattan

The most common one used is the Manhattan method, where it calculates the number of nodes moved horizontally and vertically to reach the target node from the current position. This method strictly uses only horizontal or vertical orientations, therefore, will avoid using any diagonals and obstacles. Due to this way of moving Manhattan is mostly used for mapes with a grid implemented into it. orthogonal  edge segments

Euclidean

The Euclidean is similar to Manhattan with the difference being that it is able to move in any angle, therefore, makes all the paths it finds shorter. The problem in this is, that on a map with precise roads that you could take, the estimates would be far off the actual value. This is due to it cutting corners and going through more nodes than it has to, this also slows the search down.

Octile

Chebyshev

It can move in any direction for the same cost

3. Experiment

3.1 Overview

In order to find out what algorithm is the most suitable to use in modern day society, three distinctive algorithms have been chosen; A*, Dijkstra’s and Trace. These algorithms will be executed within an online simulation which will calculate certain factors which affect the quality of the pathfinder. With the help of this program I will be able to determine the speed at which the algorithm completes the maze, the distance travelled and the amount of operations it made in order to find it’s route.

The said program has a node graph of a 64 x 36 grid with two blocks; green (starting node) and red (ending node). This graph will represent a map once all the obstacles have been drawn which too are squares shaded in grey. Each square is equal to one unit which will be used to measure the distance.

Using the image from Figure 1 we can apply it to our grid:

On figure 3.1.2 The blue nodes are part of the path the algorithm created from the green to the red node, green are the unvisited nodes and yellow shows the optimized path

3.2 Method

The settings that will be used, which can be altered on the right hand panel, are that the pathfinders are not allowed to start searching from both ends and they are not allowed to cross corners. These changes have been made in order to make more accurate assumptions which could be applied to real situations.

Why did i use the program

For each trial and map the Manhattan heuristics are used for A* and the Trace algorithm as it is the standard heuristic used for a grid. To make it a fair test, Dijkstra’s algorithm will also not be allowed to travel diagonally.

In order to get the most accurate results, all programs are closed with the exception of the web page where the simulation is open. Due to the timer being inaccurate on the simulation it will be recorded manually with a stopwatch, the time will start when the start button on the simulation is pressed and end when animation of the route is drawn.

5 different maps will be drawn where 3 will be a maze and the remaining two will represent a city map. This will give more diverse results and signify if certain types of placement of the obstacles affect the results. For each experiment all three algorithms will be tested on the same map. During the test a stopwatch will be used in order to time the duration to find a path and the number of operations as well as the length of the path will be given by the simulation.

Below are the graphs being considered:

3.3 Hypothesis

The algorithm which will find the shortest path will be A* this can be supported with the fact that it is used in most programs where a pathfinding algorithm is appropriate. Dijkstra will be less efficient than A* since A* is a modified version of Dijkstra. The Trace algorithm will be the least efficient since it choses any path which might lead to to target node even if it creates detours, however, since it uses heuristics it should be faster than Dijkstra and might be just as fast as A*.

3.4 Variables

The following are variables that will have to be considered during the experiment.

Control:

Maze layout – It would be an unfair test if the layout were to be changed for every test

Computer – The computer can change the speed at which the algorithm works as the processing speed could be either slower or faster which make the algorithms work at a different pace

Heuristics – Heuristics are used for both A* and Trace which if it were to be used inconsistently will alter the chosen path as well as the results produced

Simulation – Different programs could have slightly different versions of the algorithms which could affect the time and operation number

Dependent:

Length

Number of operations

Time

Independent:

Algorithm

Map after each experiment

3.5 Results

Table 1: Results of the experiment

Map 1

Algorithm

Length (units)

Operation

Time (s)+-

Average Time (s)

A*

216

3382

18,23

18,24

18,26

18,19

18,23

18,23

Trace

222

2521

13,67

13,72

13,68

13,67

13,70

13,69

Dijkstra

216

3583

19,48

19,41

19,36

19,46

19,39

19,42

Map 2 (used a lot of energy)

Algorithm

Length (units)

Operation

Time (s)

Average Time (s)

A*

170

1878

10,99

10,93

11,02

11,08

10,99

11,00

Trace

302

1465

8,10

7,86

8,00

7,98

7,88

7,96

Dijkstra

170

1927

13,20

13,12

13,17

13,27

13,11

13,17

Map 3

Algorithm

Length (units)

Operation

Time (s)

Average Time (s)

A*

77

1136

6,20

6,08

6,05

6,07

5,97

6,07

Trace

95

486

2,63

2,65

2,54

2,59

2,54

2,59

Dijkstra

77

2961

16,11

16,05

16,04

16,13

16,01

16,07

Map 4

Algorithm

Length (units)

Operation

Time (s)

Average Time (s)

A*

139

2585

15,79

15,89

15,92

15,87

15,85

15,86

Trace

203

2152

11,88

11,71

11,87

11,89

11,85

11,84

Dijkstra

139

2952

19,53

19,46

19,53

19,45

19,50

19,49

Map 5 (uses a lot of memory)

Algorithm

Length (units)

Operation

Time (s)

Average Time (s)

A*

82

1024

5,66

5,91

5,90

5,97

5,84

5,86

Trace

90

305

1,81

1,77

1,80

1,73

1,71

1,76

Dijkstra

82

2618

14,65

14,30

14,54

14,53

14,41

14,49

Processed data

Table 2: all the stuff combined

Algorithm

Total Length (units)

Total Operations

Total Time (s)

A*

684

10,005

57.02

Trace

912

6,929

37.84

Dijkstra

684

14,041

82.64

3.6 Analysis

General trends

The Trace algorithm has the least amount of operations

Dijkstra make the most operations

A* and Dijkstra’s algorithm find the most optimal path

The Trace algorithm takes the least amount of time to find a path

The Trace algorithm takes promising but long paths

Dijkstra and A* follow paths which are not promising

Dijkstra’s algorithm takes the longest time to find a path

The following graph represent the data collected

Graph 1

Graph 1 shows that there is a direct correlation between the number of operations and the time taken to solve the maze. Although there is an outlier at the point (2952, 19.49) this shows that the algorithms with the least amount of operations also take the least amount of time.

The shortest path is not always the best path. It would be much faster to get to your destination if you went on a highway with a higher speed limit than short path and low speed.

Greedy follows promising but long paths

For roads it wouldn't matter the small lengths since there is only one route

4 Conclusion

The data collected indicates that

The shortest path does not always mean the most optimal path. For example if the route were to go through a steep mountain then it will be more practical to go around the mountain than over it.

Overall the A* could be used in

When using a very heavy software one will not want to over complicate it even more by adding a pathfinding algorithm that requires a lot of processing. An example would be a graphically heavy

When Dijkstra’s algorithm is in action, it spreads it’s frontier (the blue ring) over a large area. This is helpful when searching for more than one destination without knowing where it lies as it can’t estimate where the ending node is. This means that it finds all the vertices on the map which can give more information than needed therefore does more work than needed. An example of where this could be used is when searching for the nearest restaurant or gas station.

If the only interest is to find the shortest path between two vertices then A* is the most suitable algorithm.

4.1 Evaluation

Firstly the maps created were on a small scale. This is a enough to make vague predictions and to conclude.

Secondly, only 5 maps were created, this is not enough to have accurate predictions

Thirdly, the time was not recorded in the most reliable way. The systematic error is caused by the reaction time used to press the button. This caused a larger thing and created small outliers. This could be resolved by implementing a timer within the program.

Whilst conducting the experiment, an error message appeared on Map 2 saying that it used too much energy and Map 5 where it used too much memory. The complexity of the map seemed to have had an impact on the speed of the algorithm and decreased the responsiveness of the computer.

Systematic, random error

Bibliography

Websites

Patel, Amit. “Introduction to A*.” Jan Vondrak's Homepage, 26 May 2014, [Accessed 15 August. 2018].

theory.stanford.edu/~amitp/GameProgramming

About this essay:

If you use part of this page in your own work, you need to provide a citation, as follows:

Essay Sauce, To what extent does each pathfinding algorithm have their own advantage to solve a problem?. Available from:<https://www.essaysauce.com/sample-essays/2018-9-2-1535889840-2/> [Accessed 11-04-26].

These Sample essays have been submitted to us by students in order to help you with your studies.

* This essay may have been previously published on EssaySauce.com and/or Essay.uk.com at an earlier date than indicated.