-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbellman-ford-visual.html
336 lines (335 loc) · 12.7 KB
/
bellman-ford-visual.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="breadth first search path finding algorithm"
/>
<meta
name="keywords"
content="Bellman ford's single source shortest path algorithm, shortest path algorithm, bellman ford's path finding, graph algorithms, algorithms, visualization, visual, graphs, graph traversal, traversal"
/>
<meta name="author" content="lumunge" />
<meta name="HandheldFriendly" content="True" />
<meta
property="og:site_name"
content="OpenGenus IQ: Computing Expertise & Legacy"
/>
<meta property="og:type" content="article" />
<meta
property="og:title"
content="Bellman Ford's Single Source Shortest Path Algorithm Visualization"
/>
<meta
property="og:description"
content="data structures and algorithms visualization, bellmand ford's single source shortest path shortest path algorithm visualization, path finding algorithms, graph algorithms visualization, visual, graphs, graph traversal, traversal"
/>
<meta
property="og:url"
content="https://iq.opengenus.org/algorithm-visualization/"
/>
<meta
property="article:published_time"
content="2021-12-08T10:39:05.000Z"
/>
<meta property="article:modified_time" content="2021-12-08T19:39:45.000Z" />
<meta property="article:tag" content="Algorithms" />
<meta property="article:tag" content="Data Structures" />
<meta property="article:tag" content="Visualization" />
<meta
property="article:publisher"
content="https://www.facebook.com/opengenus"
/>
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Visualization" />
<meta
name="twitter:description"
content="A visualization of bellmand ford's single source shortest path algorithm, graph algorithms, path finding"
/>
<meta
name="twitter:url"
content="https://iq.opengenus.org/algorithm-siaualization/"
/>
<meta name="twitter:label1" content="Written by" />
<meta name="twitter:data1" content="Erick Lumunge" />
<meta name="twitter:label2" content="Filed under" />
<meta
name="twitter:data2"
content="Visualization, Algorithms, Data Structures"
/>
<meta name="twitter:site" content="@OpenGenus" />
<link
rel="shortcut icon"
type="image/png"
href="./src/assets/images/fav1.ico"
/>
<link rel="stylesheet" href="./src/assets/css/index.min.css" />
<link rel="stylesheet" href="./src/assets/css/pathFinding.min.css" />
<title>Bellman Ford's Single Source Shortest Path Algorithm.</title>
</head>
<body>
<div class="menu">
<div class="nav">
<div class="logo">
<a href="index.html">OpenGenus Visuals</a>
</div>
<div class="nav-links">
<a href="bfs-visual.html">bfs</a>
<a href="dfs-visual.html">dfs</a>
<a href="dijkstra-visual.html">dijkstra's</a>
<a href="bellman-ford-visual.html">bellman-ford's</a>
<a href="islands-visual.html">num islands</a>
<a href="max-Island-visual.html">max island</a>
<a
href="https://github.com/lumunge/Graph-Algorithms-Visualization/wiki"
>docs</a
>
</div>
</div>
<div class="hamburger">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
</div>
<header>
<div class="heading">
<h2 class="algorithm bellman-ford">
Bellman ford's single source shortest path algorithm visualization
</h2>
</div>
<div class="controlsContainer">
<div class="visualControls">
<div class="visualSpeed">
<p>Speed</p>
<input
type="range"
min="1"
max="20"
value="10"
class="speedSlider"
/>
</div>
<div class="obstacles">
<p>Obstacles</p>
<div class="obstaclesElements">
<input type="range" min="1" value="50" class="obstacleSlider" />
<button class="setWalls btn">walls</button>
</div>
</div>
<div class="controlBtns">
<select name="" class="islandsAlgo" style="display: none">
<option value="bfs">BFS</option>
<option value="dfs">DFS</option>
</select>
<button class="start btn">start</button>
<button class="findNext btn" style="display: none">
find next
</button>
<button class="manual btn">manual</button>
<button class="clearPath btn">clear path</button>
<button class="reset btn">reload</button>
</div>
<div class="tutorialContainer">
<span
><img
class="info"
src="./src/assets/images/icons8-info-60.png"
alt=""
/></span>
<div class="tutorialContent">
<h4>Controls</h4>
<p>
<span>Speed</span> - increase or decrease the speed of the
visualization
</p>
<p>
<span>Obstacles-</span> - create walls/obstacles, on a map these
can be buildings or structures which hinder a path. You can
adjust the number of obstacles generated per click. <br />
- You can also click on the grid cells to create obstacles.
</p>
<p>
<span>Start</span> - After adjusting the speed and creating
obstacles, you can now start the visualization to see the
workings of the algorithm.
</p>
<p>
<span>Manual</span> - After running the visualization normally
you can run it manually to see how the shortest path was
obtained. After the click you can proceed with pressing enter
key.
</p>
<p>
<span>Clear Path</span> - After visualizing, you may opt to
clear the path and add more obstacles.
</p>
<p>
<span>Speed</span> - If the grid becomes to cluttered you can
reload it and repeat the above steps.
</p>
</div>
</div>
</div>
<!-- not displayed -->
<div class="hide">
<select class="algo">
<option value=""></option>
</select>
<select class="weight">
<option value=""></option>
</select>
</div>
</div>
</header>
<main>
<div class="visualizationContainer">
<div id="gridContainer"></div>
<div class="notification"></div>
<div class="tutorials">
<div class="tutorial">
<div class="emptyPath"><span class="txt">4</span></div>
<div>
This is a node with an assigned weight, which means that from
source to a point it will take 4(km/m/cm/hops...) to get to that
point.
</div>
</div>
<div class="tutorial">
<div class="stedimg"><span class="txt">A</span></div>
<div>
Start Node -> this is the starting point(source), search for a
path starts here.
</div>
</div>
<div class="tutorial">
<div class="stedimg"><span class="txt">B</span></div>
<div>
End Node -> where the search stops when a path to destination has
been found
</div>
</div>
<div class="tutorial">
<div class="obstacle"></div>
<div>
These act as obstacles, walls. On a real map these may be
buildings or structures that may block a shorter path to a
destination.
</div>
</div>
<div class="tutorial">
<div class="selectedPath"><span class="txt">7</span></div>
<div>
After the algorithm is complete, we have arrived at the
destination, now the shortest path is highlighted in green with
the cost of path written in black inside the path.
</div>
</div>
</div>
<div class="algoInfo">
<div>
<div class="infoHeading">
<h3 class="title">Bellman Ford Algorithm.</h3>
</div>
<div class="description">
This is a single source shortest path algorithm that finds the
shortest path in a graph containing negative edge weights but no
negative cycles. It is slower than dijkstra's algorithm but it is
more versatile as it is capable of handling negative weights. It
is based on the principle of <em><b>relaxation</b></em
>, whereby the shortest distance for all vertices is gradually
replaced by more accurate values until eventually reaching the
optimum solution.
</div>
<div class="algo-steps">
<p class="subtitle">Algorithm</p>
<p>
1. Initialize distances from source to all vertices as infinity
ans set source distance to 0. Create an array distance[] of size
|V| with all values as infinite except distance[source].
</p>
<p>
2. Calculate shortest distances by doing the following |V| - 1
times where |V| is the number of vertices.(In this visualization
we dont perform relaxation 800 times as it is time consuming
considering some vertices wont change after n number of
relaxations).
</p>
<p class="nest1">
1. For each edge (u,v) if distance[v] > distance[u] + weight of
edge (u,v), update distance[v]. (distance[v] = distance[u] +
weight(u, v)).
</p>
<p>
3. If distance[v] > distance[u] + weight(u,v) then graph
contains a negative weight cycle therefore terminate the
algorithm and return.
</p>
<em
>Step 2 guarantees the shortest distances if the graph does not
contain negative cycles, which means if the next iteration
produces a shorter path for any vertex then there exists a
negative weight cycle.</em
>
</div>
<div class="complexity">
<p class="subtitle">Computational complexity</p>
The algorithm has <em><b>O(VE)</b></em> time complexity in the
average and best cases and <em><b>O(E)</b></em> time complexity in
the best case. The space complexity is <em><b>O(V)</b></em> as we
store vertices in memory.
</div>
<div class="applications">
<p class="subtitle">Applications</p>
<ul>
<li>Detecting negative cycles.</li>
<li>Network packet routing protocols</li>
<li>telephone networking.</li>
<li>Distributed systems.</li>
<li>maps and gps navigation software.</li>
<li>Drone/robotic path routing.</li>
</ul>
</div>
<div class="reference">
<p>References</p>
<a href="https://iq.opengenus.org/bellman-ford-algorithm/"
>bellman ford algorithm</a
>
</div>
</div>
</div>
</div>
</main>
<footer>
<div class="copy">
<p>
OpenGenus IQ ©
<script>
document.write(/\d{4}/.exec(Date())[0]);
</script>
All rights reserved ™ [email:
<a href="mailto:[email protected]">[email protected]]</a>
</p>
</div>
<div class="links">
<span><a href="https://iq.opengenus.org/"> Top Posts </a></span>
<span
><a href="https://www.linkedin.com/company/opengenus">
LinkedIn</a
></span
>
<span><a href="https://twitter.com/OpenGenus"> Twitter</a></span>
</div>
</footer>
<script src="./dist/main.js"></script>
</body>
</html>