@@ -144,7 +144,7 @@ int
vertexNum = 0 |
- | greedy_algorithms::Graph::Graph |
+ greedy_algorithms::dijkstra::Graph::Graph |
( |
const int |
V | ) |
@@ -165,29 +165,29 @@ int vertexNum = 0 |
- 42 {
- 43
-
- 45 for (int i = 0; i < V; i++) {
-
- 47 }
- 48
- 49
- 50 for (int i = 0; i < V; i++) {
- 51 for (int j = 0; j < V; j++) {
- 52 edges[i][j] = 0;
- 53 }
- 54 }
- 55
- 56 this->vertexNum = V;
- 57 }
+ 44 {
+ 45
+
+ 47 for (int i = 0; i < V; i++) {
+
+ 49 }
+ 50
+ 51
+ 52 for (int i = 0; i < V; i++) {
+ 53 for (int j = 0; j < V; j++) {
+ 54 edges[i][j] = 0;
+ 55 }
+ 56 }
+ 57
+ 58 this->vertexNum = V;
+ 59 }
-
-◆ add_edge()
+
+◆ add_edge()
| vertexNum = 0 |
- | void greedy_algorithms::Graph::add_edge |
+ void greedy_algorithms::dijkstra::Graph::add_edge |
( |
int |
src, |
@@ -236,9 +236,9 @@ int vertexNum = 0 |
- Returns
- void
- 66 {
- 67 this->edges[src][dst] = weight;
- 68 }
+ 68 {
+ 69 this->edges[src][dst] = weight;
+ 70 }
@@ -250,7 +250,7 @@ int vertexNum = 0 |
diff --git a/d2/daa/classgreedy__algorithms_1_1dijkstra_1_1_graph.js b/d2/daa/classgreedy__algorithms_1_1dijkstra_1_1_graph.js
new file mode 100644
index 000000000..6c5c166f9
--- /dev/null
+++ b/d2/daa/classgreedy__algorithms_1_1dijkstra_1_1_graph.js
@@ -0,0 +1,5 @@
+var classgreedy__algorithms_1_1dijkstra_1_1_graph =
+[
+ [ "Graph", "d2/daa/classgreedy__algorithms_1_1dijkstra_1_1_graph.html#afefaeb247734a7c64bd04e68e3c1c4bc", null ],
+ [ "add_edge", "d2/daa/classgreedy__algorithms_1_1dijkstra_1_1_graph.html#a224b6efacbad55d59e11b046f792fe79", null ]
+];
\ No newline at end of file
diff --git a/d3/d64/classgreedy__algorithms_1_1_graph.js b/d3/d64/classgreedy__algorithms_1_1_graph.js
deleted file mode 100644
index ddcf872b8..000000000
--- a/d3/d64/classgreedy__algorithms_1_1_graph.js
+++ /dev/null
@@ -1,5 +0,0 @@
-var classgreedy__algorithms_1_1_graph =
-[
- [ "Graph", "d3/d64/classgreedy__algorithms_1_1_graph.html#ac0f2ff5759957b72ba5bbad592aa2381", null ],
- [ "add_edge", "d3/d64/classgreedy__algorithms_1_1_graph.html#a0672b080707aaaacf9cc116d69ea4c3f", null ]
-];
\ No newline at end of file
diff --git a/d4/d6d/classgreedy__algorithms_1_1_graph-members.html b/d9/db6/classgreedy__algorithms_1_1dijkstra_1_1_graph-members.html
similarity index 73%
rename from d4/d6d/classgreedy__algorithms_1_1_graph-members.html
rename to d9/db6/classgreedy__algorithms_1_1dijkstra_1_1_graph-members.html
index fa8ce1d53..56f6777d0 100644
--- a/d4/d6d/classgreedy__algorithms_1_1_graph-members.html
+++ b/d9/db6/classgreedy__algorithms_1_1dijkstra_1_1_graph-members.html
@@ -71,7 +71,7 @@ $(function() {
@@ -97,16 +97,16 @@ $(document).ready(function(){initNavTree('d3/d64/classgreedy__algorithms_1_1_gra
- This is the complete list of members for greedy_algorithms::Graph, including all inherited members.
+ This is the complete list of members for greedy_algorithms::dijkstra::Graph, including all inherited members.
diff --git a/da/d74/classgreedy__algorithms_1_1_graph__coll__graph.md5 b/da/d74/classgreedy__algorithms_1_1_graph__coll__graph.md5
deleted file mode 100644
index 6732713d2..000000000
--- a/da/d74/classgreedy__algorithms_1_1_graph__coll__graph.md5
+++ /dev/null
@@ -1 +0,0 @@
-26fbf11aad993f1b7a4afbbba05cdff4
\ No newline at end of file
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp.html b/df/dcb/greedy__algorithms_2dijkstra_8cpp.html
index ad72704ef..a11748596 100644
--- a/df/dcb/greedy__algorithms_2dijkstra_8cpp.html
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp.html
@@ -119,8 +119,8 @@ Include dependency graph for dijkstra.cpp:
|
-| int | greedy_algorithms::minimum_distance (std::vector< int > mdist, std::vector< bool > vset, int V) |
-| | Utility function that finds the vertex with the minimum distance in mdist.
|
-| |
-| void | greedy_algorithms::print (std::vector< int > dist, int V) |
-| | Utility function to print the distances to vertices.
|
-| |
-| void | greedy_algorithms::dijkstra (Graph graph, int src) |
-| | The main function that finds the shortest path from given source to all other vertices using Dijkstra's Algorithm.
|
-| |
+| int | greedy_algorithms::dijkstra::minimum_distance (std::vector< int > mdist, std::vector< bool > vset, int V) |
+| | Utility function that finds the vertex with the minimum distance in mdist.
|
+| |
+| void | greedy_algorithms::dijkstra::print (std::vector< int > dist, int V) |
+| | Utility function to print the distances to vertices.
|
+| |
+| void | greedy_algorithms::dijkstra::dijkstra (Graph graph, int src) |
+| | The main function that finds the shortest path from a given source to all other vertices using Dijkstra's Algorithm.
|
+| |
| static void | tests () |
| | Self-test implementations.
|
| |
@@ -155,6 +155,82 @@ Functions
Arpan Jain
+
+◆ dijkstra()
+
+
+
+
+
+ | void greedy_algorithms::dijkstra::dijkstra |
+ ( |
+ Graph |
+ graph, |
+
+
+ |
+ |
+ int |
+ src |
+
+
+ |
+ ) |
+ | |
+
+
+
+
+ The main function that finds the shortest path from a given source to all other vertices using Dijkstra's Algorithm.
+ - Note
- This doesn't work on negative weights.
+ - Parameters
-
+
+ | graph | the graph to be processed |
+ | src | the source of the given vertex |
+
+
+
+ - Returns
- void
+ 124 {
+ 125 int V = graph.vertexNum;
+
+
+ 128
+ 129
+ 130 for (int i = 0; i < V; i++) {
+ 131 mdist[i] = INT_MAX;
+ 132 vset[i] = false;
+ 133 }
+ 134
+ 135 mdist[src] = 0;
+ 136
+ 137
+ 138 for (int count = 0; count < V - 1; count++) {
+
+ 140
+ 141 vset[u] = true;
+ 142
+ 143 for (int v = 0; v < V; v++) {
+ 144 if (!vset[v] && graph.edges[u][v] &&
+ 145 mdist[u] + graph.edges[u][v] < mdist[v]) {
+ 146 mdist[v] = mdist[u] + graph.edges[u][v];
+ 147 }
+ 148 }
+ 149 }
+ 150
+ 151 print(mdist, V);
+ 152}
+ int minimum_distance(std::vector< int > mdist, std::vector< bool > vset, int V) Utility function that finds the vertex with the minimum distance in mdist. Definition dijkstra.cpp:82
+
+
+
+
+
+
+
◆ main()
@@ -173,10 +249,10 @@ Functions
Main function.
- Returns
- 0 on exit
- 196 {
-
- 198 return 0;
- 199}
+ 199 {
+
+ 201 return 0;
+ 202}
void tests() Definition dijkstra.cpp:113
@@ -184,6 +260,118 @@ Here is the call graph for this function:
+
+
+
+◆ minimum_distance()
+
+
+
+
+
+ | int greedy_algorithms::dijkstra::minimum_distance |
+ ( |
+ std::vector< int > |
+ mdist, |
+
+
+ |
+ |
+ std::vector< bool > |
+ vset, |
+
+
+ |
+ |
+ int |
+ V |
+
+
+ |
+ ) |
+ | |
+
+
+
+
+ Utility function that finds the vertex with the minimum distance in mdist.
+ - Parameters
-
+
+ | mdist | array of distances to each vertex |
+ | vset | array indicating inclusion in the shortest path tree |
+ | V | the number of vertices in the graph |
+
+
+
+ - Returns
- index of the vertex with the minimum distance
+ 82 {
+ 83 int minVal = INT_MAX, minInd = 0;
+ 84 for (int i = 0; i < V; i++) {
+ 85 if (!vset[i] && (mdist[i] < minVal)) {
+ 86 minVal = mdist[i];
+ 87 minInd = i;
+ 88 }
+ 89 }
+ 90
+ 91 return minInd;
+ 92}
+
+
+
+
+
+
+◆ print()
+
+
+
+
+
+ | void greedy_algorithms::dijkstra::print |
+ ( |
+ std::vector< int > |
+ dist, |
+
+
+ |
+ |
+ int |
+ V |
+
+
+ |
+ ) |
+ | |
+
+
+
+
+ Utility function to print the distances to vertices.
+ This function prints the distances to each vertex in a tabular format. If the distance is equal to INT_MAX, it is displayed as "INF".
+ - Parameters
-
+
+ | dist | An array representing the distances to each vertex. |
+ | V | The number of vertices in the graph. |
+
+
+
+ - Returns
- void
+ 104 {
+
+ 106 for (int i = 0; i < V; i++) {
+ 107 if (dist[i] < INT_MAX) {
+ 108 std::cout << i << "\t" << dist[i] << "\n";
+ 109 }
+ 110 else {
+
+ 112 }
+ 113 }
+ 114}
+
+
@@ -211,43 +399,41 @@ Here is the call graph for this function:
Self-test implementations.
- Returns
- void
- 157 {
-
- 159
- 160
- 161 graph.add_edge(6, 2, 4);
- 162 graph.add_edge(2, 6, 4);
- 163
- 164 assert( graph.edges[6][2] == 4);
- 165
- 166
- 167 graph.add_edge(0, 1, 1);
- 168 graph.add_edge(1, 0, 1);
- 169
- 170 assert( graph.edges[0][1] == 1);
- 171
- 172
- 173 graph.add_edge(0, 2, 7);
- 174 graph.add_edge(2, 0, 7);
- 175 graph.add_edge(1, 2, 1);
- 176 graph.add_edge(2, 1, 1);
- 177
- 178 assert( graph.edges[0][2] == 7);
- 179
- 180
- 181 graph.add_edge(1, 3, 3);
- 182 graph.add_edge(3, 1, 3);
- 183 graph.add_edge(1, 4, 2);
- 184 graph.add_edge(4, 1, 2);
- 185 graph.add_edge(2, 3, 2);
- 186
- 187 assert( graph.edges[1][3] == 3);
- 188
- 189 std::cout << "All tests have successfully passed!\n";
- 190}
-
- Wrapper class for storing a graph. Definition dijkstra.cpp:33
-
+ 160 {
+
+ 162
+ 163
+ 164 graph.add_edge(6, 2, 4);
+ 165 graph.add_edge(2, 6, 4);
+ 166
+ 167 assert( graph.edges[6][2] == 4);
+ 168
+ 169
+ 170 graph.add_edge(0, 1, 1);
+ 171 graph.add_edge(1, 0, 1);
+ 172
+ 173 assert( graph.edges[0][1] == 1);
+ 174
+ 175
+ 176 graph.add_edge(0, 2, 7);
+ 177 graph.add_edge(2, 0, 7);
+ 178 graph.add_edge(1, 2, 1);
+ 179 graph.add_edge(2, 1, 1);
+ 180
+ 181 assert( graph.edges[0][2] == 7);
+ 182
+ 183
+ 184 graph.add_edge(1, 3, 3);
+ 185 graph.add_edge(3, 1, 3);
+ 186 graph.add_edge(1, 4, 2);
+ 187 graph.add_edge(4, 1, 2);
+ 188 graph.add_edge(2, 3, 2);
+ 189
+ 190 assert( graph.edges[1][3] == 3);
+ 191
+ 192 std::cout << "All tests have successfully passed!\n";
+ 193}
+ Wrapper class for storing a graph. Definition dijkstra.cpp:35
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp.js b/df/dcb/greedy__algorithms_2dijkstra_8cpp.js
index 3897ed711..8cc887271 100644
--- a/df/dcb/greedy__algorithms_2dijkstra_8cpp.js
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp.js
@@ -1,9 +1,9 @@
var greedy__algorithms_2dijkstra_8cpp =
[
- [ "greedy_algorithms::Graph", "d3/d64/classgreedy__algorithms_1_1_graph.html", "d3/d64/classgreedy__algorithms_1_1_graph" ],
- [ "dijkstra", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#a04a39ac70bceeab6bcd3073da760e88a", null ],
+ [ "greedy_algorithms::dijkstra::Graph", "d2/daa/classgreedy__algorithms_1_1dijkstra_1_1_graph.html", "d2/daa/classgreedy__algorithms_1_1dijkstra_1_1_graph" ],
+ [ "dijkstra", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#af915876d0ca33cc71a6a6191a8cd3ccd", null ],
[ "main", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ],
- [ "minimum_distance", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#ac6731ab96fb83453aff4682d16fe2ea7", null ],
- [ "print", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#a58aba3d694f77ce934f4e94042321649", null ],
+ [ "minimum_distance", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#af6cb29ca6dc5771439f6ea7262058a71", null ],
+ [ "print", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#a7341d7c76a6145e991cdd231f689fca8", null ],
[ "tests", "df/dcb/greedy__algorithms_2dijkstra_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e", null ]
];
\ No newline at end of file
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.map b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.map
new file mode 100644
index 000000000..f48bd259f
--- /dev/null
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.map
@@ -0,0 +1,4 @@
+
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.md5 b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.md5
new file mode 100644
index 000000000..acd497a9f
--- /dev/null
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.md5
@@ -0,0 +1 @@
+8b0cadfc1f880efbf729f96d06db14a3
\ No newline at end of file
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.svg b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.svg
new file mode 100644
index 000000000..69984496b
--- /dev/null
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph.svg
@@ -0,0 +1,56 @@
+
+
+
+
+
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph_org.svg b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph_org.svg
new file mode 100644
index 000000000..58f05c9f4
--- /dev/null
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af6cb29ca6dc5771439f6ea7262058a71_cgraph_org.svg
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+greedy_algorithms::dijkstra::minimum_distance
+
+
+Node1
+
+
+greedy_algorithms::
+dijkstra::minimum_distance
+
+
+
+
+
+Node1->Node1
+
+
+
+
+
+
+
+
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.map b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.map
new file mode 100644
index 000000000..45d372e36
--- /dev/null
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.map
@@ -0,0 +1,6 @@
+
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.md5 b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.md5
new file mode 100644
index 000000000..5274c167a
--- /dev/null
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.md5
@@ -0,0 +1 @@
+493345e972ec158313c96f0090a8b93c
\ No newline at end of file
diff --git a/d2/d90/namespacegreedy__algorithms_a04a39ac70bceeab6bcd3073da760e88a_cgraph.svg b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.svg
similarity index 56%
rename from d2/d90/namespacegreedy__algorithms_a04a39ac70bceeab6bcd3073da760e88a_cgraph.svg
rename to df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.svg
index 5e018911a..301a699f0 100644
--- a/d2/d90/namespacegreedy__algorithms_a04a39ac70bceeab6bcd3073da760e88a_cgraph.svg
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph.svg
@@ -3,9 +3,9 @@
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-
-
+
+
-
-greedy_algorithms::dijkstra
+
+greedy_algorithms::dijkstra::dijkstra
Node1
-
+
greedy_algorithms::
-dijkstra
+dijkstra::dijkstra
Node2
-
-
+
+
greedy_algorithms::
-minimum_distance
+dijkstra::minimum_distance
@@ -42,8 +42,17 @@
Node1->Node2
-
-
+
+
+
+
+
+
+
+Node2->Node2
+
+
+
diff --git a/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph_org.svg b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph_org.svg
new file mode 100644
index 000000000..b504fb9be
--- /dev/null
+++ b/df/dcb/greedy__algorithms_2dijkstra_8cpp_af915876d0ca33cc71a6a6191a8cd3ccd_cgraph_org.svg
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+greedy_algorithms::dijkstra::dijkstra
+
+
+Node1
+
+
+greedy_algorithms::
+dijkstra::dijkstra
+
+
+
+
+
+Node2
+
+
+greedy_algorithms::
+dijkstra::minimum_distance
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node2->Node2
+
+
+
+
+
+
+
+
diff --git a/da/d74/classgreedy__algorithms_1_1_graph__coll__graph.map b/df/dce/classgreedy__algorithms_1_1dijkstra_1_1_graph__coll__graph.map
similarity index 82%
rename from da/d74/classgreedy__algorithms_1_1_graph__coll__graph.map
rename to df/dce/classgreedy__algorithms_1_1dijkstra_1_1_graph__coll__graph.map
index 4e79ad613..b9a1a876d 100644
--- a/da/d74/classgreedy__algorithms_1_1_graph__coll__graph.map
+++ b/df/dce/classgreedy__algorithms_1_1dijkstra_1_1_graph__coll__graph.map
@@ -1,4 +1,4 @@
- |