From 4d3723dfc367aee96ded3fb945efb01dc40e71f6 Mon Sep 17 00:00:00 2001 From: realstealthninja Date: Thu, 4 Sep 2025 15:56:54 +0000 Subject: [PATCH] Documentation for 651d622775acd28e2afc8c10cb953c356efb9289 --- ...__and__edmond__karp__algo_8cpp_source.html | 177 +++++++++--------- da/d9a/class_graph.html | 145 +++++++------- 2 files changed, 160 insertions(+), 162 deletions(-) diff --git a/d2/d48/max__flow__with__ford__fulkerson__and__edmond__karp__algo_8cpp_source.html b/d2/d48/max__flow__with__ford__fulkerson__and__edmond__karp__algo_8cpp_source.html index 6a5d3d1cf..6c353f6a8 100644 --- a/d2/d48/max__flow__with__ford__fulkerson__and__edmond__karp__algo_8cpp_source.html +++ b/d2/d48/max__flow__with__ford__fulkerson__and__edmond__karp__algo_8cpp_source.html @@ -145,95 +145,94 @@ $(function(){initNavTree('d2/d48/max__flow__with__ford__fulkerson__and__edmond__
27 visited.reset();
28 std::queue<int> q;
29 q.push(source);
-
30 bool is_path_found = false;
-
31 while (q.empty() == false && is_path_found == false) {
-
32 int current_node = q.front();
-
33 visited.set(current_node);
-
34 q.pop();
-
35 for (int i = 0; i < total_nodes; ++i) {
-
36 if (residual_capacity[current_node][i] > 0 && !visited[i]) {
-
37 visited.set(i);
-
38 parent[i] = current_node;
-
39 if (i == sink) {
-
40 return true;
-
41 }
-
42 q.push(i);
-
43 }
-
44 }
-
45 }
-
46 return false;
-
47 }
-
48
-
49 public:
-
50 void set_graph() {
-
51 std::cin >> total_nodes >> total_edges >> source >> sink;
-
52 parent = std::vector<int>(total_nodes, -1);
-
53 capacity = residual_capacity = std::vector<std::vector<int> >(
-
54 total_nodes, std::vector<int>(total_nodes));
-
55 for (int start = 0, destination = 0, capacity_ = 0, i = 0;
-
56 i < total_edges; ++i) {
-
57 std::cin >> start >> destination >> capacity_;
-
58 residual_capacity[start][destination] = capacity_;
-
59 capacity[start][destination] = capacity_;
-
60 }
-
61 }
-
62 void ford_fulkerson() {
-
63 while (bfs(source, sink)) {
-
64 int current_node = sink;
-
65 int flow = std::numeric_limits<int>::max();
-
66 while (current_node != source) {
-
67 int parent_ = parent[current_node];
-
68 flow = std::min(flow, residual_capacity[parent_][current_node]);
-
69 current_node = parent_;
-
70 }
-
71 current_node = sink;
-
72 max_flow += flow;
-
73 while (current_node != source) {
-
74 int parent_ = parent[current_node];
-
75 residual_capacity[parent_][current_node] -= flow;
-
76 residual_capacity[current_node][parent_] += flow;
-
77 current_node = parent_;
-
78 }
-
79 }
-
80 }
-
81 void print_flow_info() {
-
82 for (int i = 0; i < total_nodes; ++i) {
-
83 for (int j = 0; j < total_nodes; ++j) {
-
84 if (capacity[i][j] &&
-
85 residual_capacity[i][j] < capacity[i][j]) {
-
86 edge_participated.emplace_back(std::make_tuple(
-
87 i, j, capacity[i][j] - residual_capacity[i][j]));
-
88 }
-
89 }
-
90 }
-
91 std::cout << "\nNodes : " << total_nodes << "\nMax flow: " << max_flow
-
92 << "\nEdge present in flow: " << edge_participated.size()
-
93 << '\n';
-
94 std::cout << "\nSource\tDestination\tCapacity\total_nodes";
-
95 for (auto& edge_data : edge_participated) {
-
96 int source = 0, destination = 0, capacity_ = 0;
-
97 std::tie(source, destination, capacity_) = edge_data;
-
98 std::cout << source << "\t" << destination << "\t\t" << capacity_
-
99 << '\t';
-
100 }
-
101 }
-
102};
-
103int main() {
-
104 /*
-
105 Input Graph: (for testing )
-
106 4 5 0 3
-
107 0 1 10
-
108 1 2 1
-
109 1 3 1
-
110 0 2 1
-
111 2 3 10
-
112 */
-
113 Graph graph;
-
114 graph.set_graph();
-
115 graph.ford_fulkerson();
-
116 graph.print_flow_info();
-
117 return 0;
-
118}
+
30 while (q.empty() == false) {
+
31 int current_node = q.front();
+
32 visited.set(current_node);
+
33 q.pop();
+
34 for (int i = 0; i < total_nodes; ++i) {
+
35 if (residual_capacity[current_node][i] > 0 && !visited[i]) {
+
36 visited.set(i);
+
37 parent[i] = current_node;
+
38 if (i == sink) {
+
39 return true;
+
40 }
+
41 q.push(i);
+
42 }
+
43 }
+
44 }
+
45 return false;
+
46 }
+
47
+
48 public:
+
49 void set_graph() {
+
50 std::cin >> total_nodes >> total_edges >> source >> sink;
+
51 parent = std::vector<int>(total_nodes, -1);
+
52 capacity = residual_capacity = std::vector<std::vector<int> >(
+
53 total_nodes, std::vector<int>(total_nodes));
+
54 for (int start = 0, destination = 0, capacity_ = 0, i = 0;
+
55 i < total_edges; ++i) {
+
56 std::cin >> start >> destination >> capacity_;
+
57 residual_capacity[start][destination] = capacity_;
+
58 capacity[start][destination] = capacity_;
+
59 }
+
60 }
+
61 void ford_fulkerson() {
+
62 while (bfs(source, sink)) {
+
63 int current_node = sink;
+
64 int flow = std::numeric_limits<int>::max();
+
65 while (current_node != source) {
+
66 int parent_ = parent[current_node];
+
67 flow = std::min(flow, residual_capacity[parent_][current_node]);
+
68 current_node = parent_;
+
69 }
+
70 current_node = sink;
+
71 max_flow += flow;
+
72 while (current_node != source) {
+
73 int parent_ = parent[current_node];
+
74 residual_capacity[parent_][current_node] -= flow;
+
75 residual_capacity[current_node][parent_] += flow;
+
76 current_node = parent_;
+
77 }
+
78 }
+
79 }
+
80 void print_flow_info() {
+
81 for (int i = 0; i < total_nodes; ++i) {
+
82 for (int j = 0; j < total_nodes; ++j) {
+
83 if (capacity[i][j] &&
+
84 residual_capacity[i][j] < capacity[i][j]) {
+
85 edge_participated.emplace_back(std::make_tuple(
+
86 i, j, capacity[i][j] - residual_capacity[i][j]));
+
87 }
+
88 }
+
89 }
+
90 std::cout << "\nNodes : " << total_nodes << "\nMax flow: " << max_flow
+
91 << "\nEdge present in flow: " << edge_participated.size()
+
92 << '\n';
+
93 std::cout << "\nSource\tDestination\tCapacity\total_nodes";
+
94 for (auto& edge_data : edge_participated) {
+
95 int source = 0, destination = 0, capacity_ = 0;
+
96 std::tie(source, destination, capacity_) = edge_data;
+
97 std::cout << source << "\t" << destination << "\t\t" << capacity_
+
98 << '\t';
+
99 }
+
100 }
+
101};
+
102int main() {
+
103 /*
+
104 Input Graph: (for testing )
+
105 4 5 0 3
+
106 0 1 10
+
107 1 2 1
+
108 1 3 1
+
109 0 2 1
+
110 2 3 10
+
111 */
+
112 Graph graph;
+
113 graph.set_graph();
+
114 graph.ford_fulkerson();
+
115 graph.print_flow_info();
+
116 return 0;
+
117}
int main()
Main function.
Graph Algorithms.
diff --git a/da/d9a/class_graph.html b/da/d9a/class_graph.html index 03ba256c9..fe94abb04 100644 --- a/da/d9a/class_graph.html +++ b/da/d9a/class_graph.html @@ -681,24 +681,23 @@ Private Attributes
27 visited.reset();
28 std::queue<int> q;
29 q.push(source);
-
30 bool is_path_found = false;
-
31 while (q.empty() == false && is_path_found == false) {
-
32 int current_node = q.front();
-
33 visited.set(current_node);
-
34 q.pop();
-
35 for (int i = 0; i < total_nodes; ++i) {
-
36 if (residual_capacity[current_node][i] > 0 && !visited[i]) {
-
37 visited.set(i);
-
38 parent[i] = current_node;
-
39 if (i == sink) {
-
40 return true;
-
41 }
-
42 q.push(i);
-
43 }
-
44 }
-
45 }
-
46 return false;
-
47 }
+
30 while (q.empty() == false) {
+
31 int current_node = q.front();
+
32 visited.set(current_node);
+
33 q.pop();
+
34 for (int i = 0; i < total_nodes; ++i) {
+
35 if (residual_capacity[current_node][i] > 0 && !visited[i]) {
+
36 visited.set(i);
+
37 parent[i] = current_node;
+
38 if (i == sink) {
+
39 return true;
+
40 }
+
41 q.push(i);
+
42 }
+
43 }
+
44 }
+
45 return false;
+
46 }
@@ -725,26 +724,26 @@ Private Attributes
-

Definition at line 62 of file max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp.

-
62 {
-
63 while (bfs(source, sink)) {
-
64 int current_node = sink;
-
65 int flow = std::numeric_limits<int>::max();
-
66 while (current_node != source) {
-
67 int parent_ = parent[current_node];
-
68 flow = std::min(flow, residual_capacity[parent_][current_node]);
-
69 current_node = parent_;
-
70 }
-
71 current_node = sink;
-
72 max_flow += flow;
-
73 while (current_node != source) {
-
74 int parent_ = parent[current_node];
-
75 residual_capacity[parent_][current_node] -= flow;
-
76 residual_capacity[current_node][parent_] += flow;
-
77 current_node = parent_;
-
78 }
-
79 }
-
80 }
+

Definition at line 61 of file max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp.

+
61 {
+
62 while (bfs(source, sink)) {
+
63 int current_node = sink;
+
64 int flow = std::numeric_limits<int>::max();
+
65 while (current_node != source) {
+
66 int parent_ = parent[current_node];
+
67 flow = std::min(flow, residual_capacity[parent_][current_node]);
+
68 current_node = parent_;
+
69 }
+
70 current_node = sink;
+
71 max_flow += flow;
+
72 while (current_node != source) {
+
73 int parent_ = parent[current_node];
+
74 residual_capacity[parent_][current_node] -= flow;
+
75 residual_capacity[current_node][parent_] += flow;
+
76 current_node = parent_;
+
77 }
+
78 }
+
79 }
@@ -832,28 +831,28 @@ Private Attributes
-

Definition at line 81 of file max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp.

-
81 {
-
82 for (int i = 0; i < total_nodes; ++i) {
-
83 for (int j = 0; j < total_nodes; ++j) {
-
84 if (capacity[i][j] &&
-
85 residual_capacity[i][j] < capacity[i][j]) {
-
86 edge_participated.emplace_back(std::make_tuple(
-
87 i, j, capacity[i][j] - residual_capacity[i][j]));
-
88 }
-
89 }
-
90 }
-
91 std::cout << "\nNodes : " << total_nodes << "\nMax flow: " << max_flow
-
92 << "\nEdge present in flow: " << edge_participated.size()
-
93 << '\n';
-
94 std::cout << "\nSource\tDestination\tCapacity\total_nodes";
-
95 for (auto& edge_data : edge_participated) {
-
96 int source = 0, destination = 0, capacity_ = 0;
-
97 std::tie(source, destination, capacity_) = edge_data;
-
98 std::cout << source << "\t" << destination << "\t\t" << capacity_
-
99 << '\t';
-
100 }
-
101 }
+

Definition at line 80 of file max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp.

+
80 {
+
81 for (int i = 0; i < total_nodes; ++i) {
+
82 for (int j = 0; j < total_nodes; ++j) {
+
83 if (capacity[i][j] &&
+
84 residual_capacity[i][j] < capacity[i][j]) {
+
85 edge_participated.emplace_back(std::make_tuple(
+
86 i, j, capacity[i][j] - residual_capacity[i][j]));
+
87 }
+
88 }
+
89 }
+
90 std::cout << "\nNodes : " << total_nodes << "\nMax flow: " << max_flow
+
91 << "\nEdge present in flow: " << edge_participated.size()
+
92 << '\n';
+
93 std::cout << "\nSource\tDestination\tCapacity\total_nodes";
+
94 for (auto& edge_data : edge_participated) {
+
95 int source = 0, destination = 0, capacity_ = 0;
+
96 std::tie(source, destination, capacity_) = edge_data;
+
97 std::cout << source << "\t" << destination << "\t\t" << capacity_
+
98 << '\t';
+
99 }
+
100 }
@@ -880,19 +879,19 @@ Private Attributes
-

Definition at line 50 of file max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp.

-
50 {
-
51 std::cin >> total_nodes >> total_edges >> source >> sink;
-
52 parent = std::vector<int>(total_nodes, -1);
-
53 capacity = residual_capacity = std::vector<std::vector<int> >(
-
54 total_nodes, std::vector<int>(total_nodes));
-
55 for (int start = 0, destination = 0, capacity_ = 0, i = 0;
-
56 i < total_edges; ++i) {
-
57 std::cin >> start >> destination >> capacity_;
-
58 residual_capacity[start][destination] = capacity_;
-
59 capacity[start][destination] = capacity_;
-
60 }
-
61 }
+

Definition at line 49 of file max_flow_with_ford_fulkerson_and_edmond_karp_algo.cpp.

+
49 {
+
50 std::cin >> total_nodes >> total_edges >> source >> sink;
+
51 parent = std::vector<int>(total_nodes, -1);
+
52 capacity = residual_capacity = std::vector<std::vector<int> >(
+
53 total_nodes, std::vector<int>(total_nodes));
+
54 for (int start = 0, destination = 0, capacity_ = 0, i = 0;
+
55 i < total_edges; ++i) {
+
56 std::cin >> start >> destination >> capacity_;
+
57 residual_capacity[start][destination] = capacity_;
+
58 capacity[start][destination] = capacity_;
+
59 }
+
60 }