From 49e28d42dd6cfdc1f9f856915bdc1aa624ab66e6 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 16 Aug 2020 18:53:02 +0000 Subject: [PATCH] Documentation for 327a4f57d6d3ea8cc538ea1ffb48fdf60fa07847 --- d3/db7/graph_2dijkstra_8cpp__incl.map | 10 + d3/db7/graph_2dijkstra_8cpp__incl.md5 | 1 + d3/db7/graph_2dijkstra_8cpp__incl.svg | 127 +++++ d4/d86/large__number_8h_source.html | 6 +- d7/d1e/graph_2dijkstra_8cpp.html | 284 +++++++++++ d7/d1e/graph_2dijkstra_8cpp.js | 8 + ...8ec9ad42717780d6caaff9d3d6977f9_cgraph.map | 8 + ...8ec9ad42717780d6caaff9d3d6977f9_cgraph.md5 | 1 + ...8ec9ad42717780d6caaff9d3d6977f9_cgraph.svg | 97 ++++ ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map | 9 + ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 | 1 + ...66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg | 130 ++++++ df/dce/namespacegraph.html | 176 +++++++ ...54891267187a5ec6c6e3f3ad5203ff1_cgraph.map | 4 + ...54891267187a5ec6c6e3f3ad5203ff1_cgraph.md5 | 1 + ...54891267187a5ec6c6e3f3ad5203ff1_cgraph.svg | 37 ++ ...68530bfaed30e57290a76d5b4402d50_cgraph.map | 4 + ...68530bfaed30e57290a76d5b4402d50_cgraph.md5 | 1 + ...68530bfaed30e57290a76d5b4402d50_cgraph.svg | 37 ++ dir_12552d7fa429bf94a2e32e5cf39f7e69.html | 3 + dir_12552d7fa429bf94a2e32e5cf39f7e69.js | 1 + files.html | 7 +- globals_func_i.html | 6 +- globals_func_m.html | 29 +- globals_func_t.html | 13 +- globals_i.html | 6 +- globals_m.html | 57 +-- globals_p.html | 6 +- globals_t.html | 15 +- namespacemembers.html | 6 + namespacemembers_func.html | 6 + navtreedata.js | 6 +- navtreeindex2.js | 22 +- navtreeindex3.js | 16 +- navtreeindex4.js | 34 +- navtreeindex5.js | 6 + search/all_1.js | 2 +- search/all_10.js | 202 ++++---- search/all_11.js | 42 +- search/all_12.js | 204 ++++---- search/all_13.js | 442 +++++++++--------- search/all_14.js | 188 ++++---- search/all_15.js | 122 ++--- search/all_16.js | 78 ++-- search/all_17.js | 158 +++---- search/all_18.js | 12 +- search/all_19.js | 8 +- search/all_1a.js | 4 +- search/all_1b.js | 182 ++++---- search/all_4.js | 126 ++--- search/all_5.js | 130 +++--- search/all_6.js | 240 +++++----- search/all_7.js | 140 +++--- search/all_8.js | 64 +-- search/all_9.js | 366 +++++++-------- search/all_a.js | 10 +- search/all_b.js | 28 +- search/all_c.js | 140 +++--- search/all_d.js | 222 ++++----- search/all_e.js | 128 ++--- search/all_f.js | 134 +++--- search/classes_0.js | 36 +- search/classes_1.js | 78 ++-- search/classes_10.js | 6 +- search/classes_11.js | 80 ++-- search/classes_12.js | 88 ++-- search/classes_13.js | 44 +- search/classes_14.js | 64 +-- search/classes_15.js | 28 +- search/classes_16.js | 62 +-- search/classes_17.js | 4 +- search/classes_18.js | 2 +- search/classes_2.js | 68 +-- search/classes_3.js | 30 +- search/classes_4.js | 34 +- search/classes_5.js | 34 +- search/classes_6.js | 12 +- search/classes_7.js | 14 +- search/classes_8.js | 196 ++++---- search/classes_9.js | 2 +- search/classes_a.js | 4 +- search/classes_b.js | 32 +- search/classes_c.js | 74 +-- search/classes_d.js | 34 +- search/classes_e.js | 24 +- search/classes_f.js | 34 +- search/defines_0.js | 4 +- search/defines_1.js | 4 +- search/defines_2.js | 4 +- search/defines_3.js | 2 +- search/defines_4.js | 4 +- search/defines_5.js | 6 +- search/defines_6.js | 4 +- search/files_0.js | 8 +- search/files_1.js | 26 +- search/files_10.js | 14 +- search/files_11.js | 4 +- search/files_12.js | 28 +- search/files_13.js | 8 +- search/files_14.js | 4 +- search/files_15.js | 2 +- search/files_2.js | 14 +- search/files_3.js | 15 +- search/files_4.js | 6 +- search/files_5.js | 18 +- search/files_6.js | 14 +- search/files_7.js | 10 +- search/files_8.js | 8 +- search/files_9.js | 2 +- search/files_a.js | 8 +- search/files_b.js | 22 +- search/files_c.js | 12 +- search/files_d.js | 8 +- search/files_e.js | 8 +- search/files_f.js | 18 +- search/functions_0.js | 4 +- search/functions_1.js | 160 +++---- search/functions_10.js | 154 +++--- search/functions_11.js | 16 +- search/functions_12.js | 152 +++--- search/functions_13.js | 354 +++++++------- search/functions_14.js | 150 +++--- search/functions_15.js | 80 ++-- search/functions_16.js | 44 +- search/functions_17.js | 146 +++--- search/functions_18.js | 6 +- search/functions_19.js | 2 +- search/functions_1a.js | 2 +- search/functions_1b.js | 182 ++++---- search/functions_2.js | 114 ++--- search/functions_3.js | 144 +++--- search/functions_4.js | 163 +++---- search/functions_5.js | 106 ++--- search/functions_6.js | 204 ++++---- search/functions_7.js | 120 ++--- search/functions_8.js | 34 +- search/functions_9.js | 180 +++---- search/functions_a.js | 6 +- search/functions_b.js | 16 +- search/functions_c.js | 92 ++-- search/functions_d.js | 160 +++---- search/functions_e.js | 98 ++-- search/functions_f.js | 114 ++--- search/groups_0.js | 2 +- search/groups_1.js | 4 +- search/groups_2.js | 2 +- search/namespaces_0.js | 2 +- search/namespaces_1.js | 4 +- search/namespaces_2.js | 4 +- search/namespaces_3.js | 2 +- search/namespaces_4.js | 2 +- search/namespaces_5.js | 2 +- search/namespaces_6.js | 2 +- search/namespaces_7.js | 2 +- search/namespaces_8.js | 4 +- search/namespaces_9.js | 20 +- search/namespaces_a.js | 2 +- search/namespaces_b.js | 2 +- search/pages_0.js | 2 +- search/pages_1.js | 2 +- search/pages_2.js | 2 +- search/pages_3.js | 4 +- search/related_0.js | 10 +- search/typedefs_0.js | 2 +- search/typedefs_1.js | 2 +- search/typedefs_2.js | 2 +- search/variables_0.js | 4 +- search/variables_1.js | 6 +- search/variables_10.js | 4 +- search/variables_11.js | 2 +- search/variables_12.js | 4 +- search/variables_13.js | 2 +- search/variables_14.js | 2 +- search/variables_15.js | 2 +- search/variables_2.js | 4 +- search/variables_3.js | 2 +- search/variables_4.js | 4 +- search/variables_5.js | 6 +- search/variables_6.js | 10 +- search/variables_7.js | 2 +- search/variables_8.js | 2 +- search/variables_9.js | 2 +- search/variables_a.js | 10 +- search/variables_b.js | 6 +- search/variables_c.js | 8 +- search/variables_d.js | 4 +- search/variables_e.js | 2 +- search/variables_f.js | 12 +- 188 files changed, 5038 insertions(+), 4069 deletions(-) create mode 100644 d3/db7/graph_2dijkstra_8cpp__incl.map create mode 100644 d3/db7/graph_2dijkstra_8cpp__incl.md5 create mode 100644 d3/db7/graph_2dijkstra_8cpp__incl.svg create mode 100644 d7/d1e/graph_2dijkstra_8cpp.html create mode 100644 d7/d1e/graph_2dijkstra_8cpp.js create mode 100644 d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.map create mode 100644 d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.md5 create mode 100644 d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.svg create mode 100644 d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map create mode 100644 d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 create mode 100644 d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg create mode 100644 df/dce/namespacegraph_a454891267187a5ec6c6e3f3ad5203ff1_cgraph.map create mode 100644 df/dce/namespacegraph_a454891267187a5ec6c6e3f3ad5203ff1_cgraph.md5 create mode 100644 df/dce/namespacegraph_a454891267187a5ec6c6e3f3ad5203ff1_cgraph.svg create mode 100644 df/dce/namespacegraph_a868530bfaed30e57290a76d5b4402d50_cgraph.map create mode 100644 df/dce/namespacegraph_a868530bfaed30e57290a76d5b4402d50_cgraph.md5 create mode 100644 df/dce/namespacegraph_a868530bfaed30e57290a76d5b4402d50_cgraph.svg diff --git a/d3/db7/graph_2dijkstra_8cpp__incl.map b/d3/db7/graph_2dijkstra_8cpp__incl.map new file mode 100644 index 000000000..9e6e0b4eb --- /dev/null +++ b/d3/db7/graph_2dijkstra_8cpp__incl.map @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/d3/db7/graph_2dijkstra_8cpp__incl.md5 b/d3/db7/graph_2dijkstra_8cpp__incl.md5 new file mode 100644 index 000000000..d81cef578 --- /dev/null +++ b/d3/db7/graph_2dijkstra_8cpp__incl.md5 @@ -0,0 +1 @@ +877fdb92c0ba2d9c99ae6ce6d238974a \ No newline at end of file diff --git a/d3/db7/graph_2dijkstra_8cpp__incl.svg b/d3/db7/graph_2dijkstra_8cpp__incl.svg new file mode 100644 index 000000000..0f1db60a4 --- /dev/null +++ b/d3/db7/graph_2dijkstra_8cpp__incl.svg @@ -0,0 +1,127 @@ + + + + + + +graph/dijkstra.cpp + + + +Node1 + + +graph/dijkstra.cpp + + + + + +Node2 + + +cassert + + + + + +Node1->Node2 + + + + + +Node3 + + +iostream + + + + + +Node1->Node3 + + + + + +Node4 + + +limits + + + + + +Node1->Node4 + + + + + +Node5 + + +queue + + + + + +Node1->Node5 + + + + + +Node6 + + +utility + + + + + +Node1->Node6 + + + + + +Node7 + + +vector + + + + + +Node1->Node7 + + + + + +Node8 + + +memory + + + + + +Node1->Node8 + + + + + diff --git a/d4/d86/large__number_8h_source.html b/d4/d86/large__number_8h_source.html index 550e14814..d05187a62 100644 --- a/d4/d86/large__number_8h_source.html +++ b/d4/d86/large__number_8h_source.html @@ -394,6 +394,7 @@ $(document).ready(function(){initNavTree('d4/d86/large__number_8h_source.html','
trie
Definition: trie_tree.cpp:8
std::srand
T srand(T... args)
main
int main()
Definition: double_factorial.cpp:67
+
graph::addEdge
void addEdge(std::vector< std::vector< std::pair< int, int >>> *adj, int u, int v, int w)
Function that add edge between two nodes or vertices of graph.
Definition: dijkstra.cpp:48
main
int main()
Definition: gcd_of_n_numbers.cpp:28
std::setprecision
T setprecision(T... args)
graph::breadth_first_search
std::vector< bool > breadth_first_search(const std::vector< std::vector< int >> &graph, int start)
Function performs the breadth first search algorithm over the graph.
Definition: breadth_first_search.cpp:95
@@ -460,7 +461,6 @@ $(document).ready(function(){initNavTree('d4/d86/large__number_8h_source.html','
large_number
Definition: large_number.h:24
fib
large_number fib(uint64_t n)
Definition: fibonacci_large.cpp:24
main
int main()
Definition: fibonacci_fast.cpp:51
-
std::iterator
main
int main(int argc, char **argv)
Definition: kohonen_som_topology.cpp:582
Trie::hasChildren
static bool hasChildren(std::shared_ptr< TrieNode > node)
Definition: trie_modern.cpp:41
double_hashing::putProber
bool putProber(const Entry &entry, int key)
Definition: double_hash_hash_table.cpp:120
@@ -491,7 +491,6 @@ $(document).ready(function(){initNavTree('d4/d86/large__number_8h_source.html','
save_nd_data
int save_nd_data(const char *fname, const std::vector< std::valarray< double >> &X)
Definition: kohonen_som_trace.cpp:58
node
struct list node
hash_chain
Chain class with a given modulus.
Definition: chaining.cpp:16
-
std::scanf
T scanf(T... args)
get_clock_diff
double get_clock_diff(clock_t start_t, clock_t end_t)
Definition: kohonen_som_trace.cpp:452
test2
void test2(const std::string &text)
Self test 2 - using 8x8 randomly generated key.
Definition: hill_cipher.cpp:505
graph::add_directed_edge
void add_directed_edge(std::vector< std::vector< int >> *graph, int u, int v)
Adds a directed edge from vertex u to vertex v.
Definition: breadth_first_search.cpp:66
@@ -552,11 +551,13 @@ $(document).ready(function(){initNavTree('d4/d86/large__number_8h_source.html','
Trie::insert
void insert(const std::string &word)
Definition: trie_modern.cpp:109
operator<<
std::ostream & operator<<(std::ostream &out, std::vector< std::vector< T >> const &v)
Definition: ordinary_least_squares_regressor.cpp:22
CycleCheck::isCyclicDFS
static bool isCyclicDFS(Graph const &graph)
Definition: cycle_check_directed_graph.cpp:212
+
tests
void tests()
Definition: dijkstra.cpp:113
test3
void test3()
Definition: kohonen_som_topology.cpp:537
createNode
node * createNode(int data)
Definition: avltree.cpp:21
CycleCheck
Definition: cycle_check_directed_graph.cpp:158
test
static void test()
Definition: fibonacci.cpp:32
graph::RootedTree::parent
std::vector< int > parent
Stores parent of every vertex and for root its own index. The root is technically not its own parent,...
Definition: lowest_common_ancestor.cpp:103
+
graph::dijkstra
int dijkstra(std::vector< std::vector< std::pair< int, int >>> *adj, int s, int t)
Function runs the dijkstra algorithm for some source vertex and target vertex in the graph and return...
Definition: dijkstra.cpp:66
CycleCheck::isCyclicDFSHelper
static bool isCyclicDFSHelper(AdjList const &adjList, std::vector< nodeStates > *state, unsigned int node)
Definition: cycle_check_directed_graph.cpp:170
large_number::operator*=
large_number & operator*=(const T n)
Definition: large_number.h:238
large_number::large_number
large_number()
Definition: large_number.h:27
@@ -742,6 +743,7 @@ $(document).ready(function(){initNavTree('d4/d86/large__number_8h_source.html','
machine_learning::adaline::accuracy
const double accuracy
model fit convergence accuracy
Definition: adaline_learning.cpp:208
main
int main()
Definition: gcd_iterative_euclidean.cpp:47
std::max
T max(T... args)
+
main
int main()
Definition: dijkstra.cpp:152
test_2d_classes
void test_2d_classes(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_topology.cpp:330
graph::RootedTree::root
int root
Index of the root vertex.
Definition: lowest_common_ancestor.cpp:107
std::range_error
STL class.
diff --git a/d7/d1e/graph_2dijkstra_8cpp.html b/d7/d1e/graph_2dijkstra_8cpp.html new file mode 100644 index 000000000..71610b227 --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp.html @@ -0,0 +1,284 @@ + + + + + + + +Algorithms_in_C++: graph/dijkstra.cpp File Reference + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Algorithms_in_C++ +  1.0.0 +
+
Set of algorithms implemented in C++.
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
dijkstra.cpp File Reference
+
+
+ +

Graph Dijkstras Shortest Path Algorithm (Dijkstra's Shortest Path) +More...

+
#include <cassert>
+#include <iostream>
+#include <limits>
+#include <queue>
+#include <utility>
+#include <vector>
+#include <memory>
+
+Include dependency graph for dijkstra.cpp:
+
+
+
+
+
+ + + + +

+Namespaces

 graph
 Graph algorithms.
 
+ + + + + + + + + + + +

+Functions

void graph::addEdge (std::vector< std::vector< std::pair< int, int >>> *adj, int u, int v, int w)
 Function that add edge between two nodes or vertices of graph. More...
 
int graph::dijkstra (std::vector< std::vector< std::pair< int, int >>> *adj, int s, int t)
 Function runs the dijkstra algorithm for some source vertex and target vertex in the graph and returns the shortest distance of target from the source. More...
 
void tests ()
 
int main ()
 
+ + + +

+Variables

+constexpr int64_t INF = std::numeric_limits<int64_t>::max()
 
+

Detailed Description

+

Graph Dijkstras Shortest Path Algorithm (Dijkstra's Shortest Path)

+
Author
Ayaan Khan
+

Dijkstra's Algorithm is used to find the shortest path from a source vertex to all other reachable vertex in the graph. The algorithm initially assumes all the nodes are unreachable from the given source vertex so we mark the distances of all vertices as INF (infinity) from source vertex (INF / infinity denotes unable to reach).

+

in similar fashion with BFS we assume the distance of source vertex as 0 and pushes the vertex in a priority queue with it's distance. we maintain the priority queue as a min heap so that we can get the minimum element at the top of heap

+

Basically what we do in this algorithm is that we try to minimize the distances of all the reachable vertices from the current vertex, look at the code below to understand in better way.

+

Function Documentation

+ +

◆ main()

+ +
+
+ + + + + + + +
int main ()
+
+

Main function

+
152  {
+
153  // running predefined tests
+
154  tests();
+
155 
+
156  int vertices = int(), edges = int();
+
157  std::cout << "Enter the number of vertices : ";
+
158  std::cin >> vertices;
+
159  std::cout << "Enter the number of edges : ";
+
160  std::cin >> edges;
+
161 
+ +
163  vertices, std::vector<std::pair<int, int>>());
+
164 
+
165  int u = int(), v = int(), w = int();
+
166  while (edges--) {
+
167  std::cin >> u >> v >> w;
+
168  graph::addEdge(&adj, u, v, w);
+
169  }
+
170 
+
171  int s = int(), t = int();
+
172  std::cin >> s >> t;
+
173  int dist = graph::dijkstra(&adj, s - 1, t - 1);
+
174  if (dist == -1) {
+
175  std::cout << "Target not reachable from source" << std::endl;
+
176  } else {
+
177  std::cout << "Shortest Path Distance : " << dist << std::endl;
+
178  }
+
179  return 0;
+
180 }
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+ +

◆ tests()

+ +
+
+ + + + + + + +
void tests ()
+
+

Function to test the Algorithm

+
113  {
+
114  std::cout << "Initiatinig Predefined Tests..." << std::endl;
+
115  std::cout << "Initiating Test 1..." << std::endl;
+ + +
118  graph::addEdge(&adj1, 1, 2, 1);
+
119  graph::addEdge(&adj1, 4, 1, 2);
+
120  graph::addEdge(&adj1, 2, 3, 2);
+
121  graph::addEdge(&adj1, 1, 3, 5);
+
122 
+
123  int s = 1, t = 3;
+
124  assert(graph::dijkstra(&adj1, s - 1, t - 1) == 3);
+
125  std::cout << "Test 1 Passed..." << std::endl;
+
126 
+
127  s = 4, t = 3;
+
128  std::cout << "Initiating Test 2..." << std::endl;
+
129  assert(graph::dijkstra(&adj1, s - 1, t - 1) == 5);
+
130  std::cout << "Test 2 Passed..." << std::endl;
+
131 
+ + +
134  graph::addEdge(&adj2, 1, 2, 4);
+
135  graph::addEdge(&adj2, 1, 3, 2);
+
136  graph::addEdge(&adj2, 2, 3, 2);
+
137  graph::addEdge(&adj2, 3, 2, 1);
+
138  graph::addEdge(&adj2, 2, 4, 2);
+
139  graph::addEdge(&adj2, 3, 5, 4);
+
140  graph::addEdge(&adj2, 5, 4, 1);
+
141  graph::addEdge(&adj2, 2, 5, 3);
+
142  graph::addEdge(&adj2, 3, 4, 4);
+
143 
+
144  s = 1, t = 5;
+
145  std::cout << "Initiating Test 3..." << std::endl;
+
146  assert(graph::dijkstra(&adj2, s - 1, t - 1) == 6);
+
147  std::cout << "Test 3 Passed..." << std::endl;
+
148  std::cout << "All Test Passed..." << std::endl << std::endl;
+
149 }
+
+Here is the call graph for this function:
+
+
+
+
+ +
+
+
+
+
std::pair
+
std::vector
STL class.
+
tests
void tests()
Definition: dijkstra.cpp:113
+
graph::dijkstra
int dijkstra(std::vector< std::vector< std::pair< int, int >>> *adj, int s, int t)
Function runs the dijkstra algorithm for some source vertex and target vertex in the graph and return...
Definition: dijkstra.cpp:66
+
std::cout
+
std::endl
T endl(T... args)
+
std::cin
+
graph::addEdge
void addEdge(int, int)
Function that add edge between two nodes or vertices of graph.
Definition: connected_components.cpp:75
+ + + + diff --git a/d7/d1e/graph_2dijkstra_8cpp.js b/d7/d1e/graph_2dijkstra_8cpp.js new file mode 100644 index 000000000..8938a85b2 --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp.js @@ -0,0 +1,8 @@ +var graph_2dijkstra_8cpp = +[ + [ "addEdge", "d7/d1e/graph_2dijkstra_8cpp.html#a454891267187a5ec6c6e3f3ad5203ff1", null ], + [ "dijkstra", "d7/d1e/graph_2dijkstra_8cpp.html#a868530bfaed30e57290a76d5b4402d50", null ], + [ "main", "d7/d1e/graph_2dijkstra_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ], + [ "tests", "d7/d1e/graph_2dijkstra_8cpp.html#a88ec9ad42717780d6caaff9d3d6977f9", null ], + [ "INF", "d7/d1e/graph_2dijkstra_8cpp.html#a330a2b0a904f01802ada1f8f3b28e76c", null ] +]; \ No newline at end of file diff --git a/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.map b/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.map new file mode 100644 index 000000000..f177c2498 --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.map @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.md5 b/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.md5 new file mode 100644 index 000000000..8c21c8ca2 --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.md5 @@ -0,0 +1 @@ +d6f3fed70cd0becde0f0cfcab37fcf23 \ No newline at end of file diff --git a/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.svg b/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.svg new file mode 100644 index 000000000..17d4c33a3 --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp_a88ec9ad42717780d6caaff9d3d6977f9_cgraph.svg @@ -0,0 +1,97 @@ + + + + + + +tests + + + +Node1 + + +tests + + + + + +Node2 + + +graph::addEdge + + + + + +Node1->Node2 + + + + + +Node4 + + +graph::dijkstra + + + + + +Node1->Node4 + + + + + +Node6 + + +std::endl + + + + + +Node1->Node6 + + + + + +Node3 + + +std::vector::push_back + + + + + +Node2->Node3 + + + + + +Node5 + + +std::vector::size + + + + + +Node4->Node5 + + + + + diff --git a/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map new file mode 100644 index 000000000..54f6a90d7 --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 new file mode 100644 index 000000000..dea7a8ac0 --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 @@ -0,0 +1 @@ +8d34466dec6cf64bdcd2917315ec113e \ No newline at end of file diff --git a/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg new file mode 100644 index 000000000..dfac60b5b --- /dev/null +++ b/d7/d1e/graph_2dijkstra_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg @@ -0,0 +1,130 @@ + + + + + + +main + + + +Node1 + + +main + + + + + +Node2 + + +graph::addEdge + + + + + +Node1->Node2 + + + + + +Node4 + + +graph::dijkstra + + + + + +Node1->Node4 + + + + + +Node6 + + +std::endl + + + + + +Node1->Node6 + + + + + +Node7 + + +tests + + + + + +Node1->Node7 + + + + + +Node3 + + +std::vector::push_back + + + + + +Node2->Node3 + + + + + +Node5 + + +std::vector::size + + + + + +Node4->Node5 + + + + + +Node7->Node2 + + + + + +Node7->Node4 + + + + + +Node7->Node6 + + + + + diff --git a/df/dce/namespacegraph.html b/df/dce/namespacegraph.html index 22f830eec..17d4689c9 100644 --- a/df/dce/namespacegraph.html +++ b/df/dce/namespacegraph.html @@ -111,9 +111,16 @@ Functions std::vector< bool > breadth_first_search (const std::vector< std::vector< int >> &graph, int start)  Function performs the breadth first search algorithm over the graph. More...
  +void addEdge (std::vector< std::vector< std::pair< int, int >>> *adj, int u, int v, int w) + Function that add edge between two nodes or vertices of graph. More...
+  +int dijkstra (std::vector< std::vector< std::pair< int, int >>> *adj, int s, int t) + Function runs the dijkstra algorithm for some source vertex and target vertex in the graph and returns the shortest distance of target from the source. More...

Detailed Description

Graph algorithms.

+

Graph Algorithms.

Function Documentation

◆ add_directed_edge()

@@ -214,6 +221,65 @@ Here is the call graph for this function: + + + +

◆ addEdge()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void graph::addEdge (std::vector< std::vector< std::pair< int, int >>> * adj,
int u,
int v,
int w 
)
+
+ +

Function that add edge between two nodes or vertices of graph.

+
Parameters
+ + + +
uany node or vertex of graph
vany node or vertex of graph
+
+
+
49  {
+
50  (*adj)[u - 1].push_back(std::make_pair(v - 1, w));
+
51  // (*adj)[v - 1].push_back(std::make_pair(u - 1, w));
+
52  }
+
+Here is the call graph for this function:
+
+
+
+
+
@@ -285,18 +351,128 @@ Here is the call graph for this function: + + + +

◆ dijkstra()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int graph::dijkstra (std::vector< std::vector< std::pair< int, int >>> * adj,
int s,
int t 
)
+
+ +

Function runs the dijkstra algorithm for some source vertex and target vertex in the graph and returns the shortest distance of target from the source.

+
Parameters
+ + + + +
adjinput graph
ssource vertex
ttarget vertex
+
+
+
Returns
shortest distance if target is reachable from source else -1 in case if target is not reachable from source.
+

n denotes the number of vertices in graph

+

setting all the distances initially to INF

+

creating a min heap using priority queue first element of pair contains the distance second element of pair contains the vertex

+

pushing the source vertex 's' with 0 distance in min heap

+

marking the distance of source as 0

+

second element of pair denotes the node / vertex

+

first element of pair denotes the distance

+

for all the reachable vertex from the currently exploring vertex we will try to minimize the distance

+

minimizing distances

+
66  {
+
67  /// n denotes the number of vertices in graph
+
68  int n = adj->size();
+
69 
+
70  /// setting all the distances initially to INF
+
71  std::vector<int64_t> dist(n, INF);
+
72 
+
73  /// creating a min heap using priority queue
+
74  /// first element of pair contains the distance
+
75  /// second element of pair contains the vertex
+ + +
78  pq;
+
79 
+
80  /// pushing the source vertex 's' with 0 distance in min heap
+
81  pq.push(std::make_pair(0, s));
+
82 
+
83  /// marking the distance of source as 0
+
84  dist[s] = 0;
+
85 
+
86  while (!pq.empty()) {
+
87  /// second element of pair denotes the node / vertex
+
88  int currentNode = pq.top().second;
+
89 
+
90  /// first element of pair denotes the distance
+
91  int currentDist = pq.top().first;
+
92 
+
93  pq.pop();
+
94 
+
95  /// for all the reachable vertex from the currently exploring vertex
+
96  /// we will try to minimize the distance
+
97  for (std::pair<int, int> edge : (*adj)[currentNode]) {
+
98  /// minimizing distances
+
99  if (currentDist + edge.second < dist[edge.first]) {
+
100  dist[edge.first] = currentDist + edge.second;
+
101  pq.push(std::make_pair(dist[edge.first], edge.first));
+
102  }
+
103  }
+
104  }
+
105  if (dist[t] != INF) {
+
106  return dist[t];
+
107  }
+
108  return -1;
+
109  }
+
+Here is the call graph for this function:
+
+
+
+
+
+
std::pair
std::vector< bool >
+
std::vector::size
T size(T... args)
graph::add_directed_edge
void add_directed_edge(std::vector< std::vector< int >> *graph, int u, int v)
Adds a directed edge from vertex u to vertex v.
Definition: breadth_first_search.cpp:66
std::queue
STL class.
std::queue::front
T front(T... args)
std::queue::pop
T pop(T... args)
+
std::priority_queue::top
T top(T... args)
+
std::priority_queue
STL class.
+
std::greater
graph
Graph algorithms.
std::queue::empty
T empty(T... args)
std::queue::push
T push(T... args)
+
std::make_pair
T make_pair(T... args)