fix: linter for max flow. (#997)

(cherry picked from commit b23e9e643978de99cb17843d7388f15246e390f0)
This commit is contained in:
Filip Hlasek 2020-08-13 07:56:53 -07:00 committed by Krishna Vedala
parent dfcfedcdd2
commit bc73f9dd60
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7

View File

@ -16,16 +16,14 @@
// std::max capacity of node in graph // std::max capacity of node in graph
const int MAXN = 505; const int MAXN = 505;
class Graph { class Graph {
int residual_capacity[MAXN][MAXN]; std::vector< std::vector<int> > residual_capacity, capacity;
int capacity[MAXN][MAXN]; // used while checking the flow of edge int total_nodes = 0;
int total_nodes; int total_edges = 0, source = 0, sink = 0;
int total_edges, source, sink; std::vector<int> parent;
int parent[MAXN];
std::vector<std::tuple<int, int, int> > edge_participated; std::vector<std::tuple<int, int, int> > edge_participated;
std::bitset<MAXN> visited; std::bitset<MAXN> visited;
int max_flow = 0; int max_flow = 0;
bool bfs(int source, int sink) { // to find the augmented - path bool bfs(int source, int sink) { // to find the augmented - path
memset(parent, -1, sizeof(parent));
visited.reset(); visited.reset();
std::queue<int> q; std::queue<int> q;
q.push(source); q.push(source);
@ -49,16 +47,17 @@ class Graph {
} }
public: public:
Graph() { memset(residual_capacity, 0, sizeof(residual_capacity)); } void set_graph() {
void set_graph(void) {
std::cin >> total_nodes >> total_edges >> source >> sink; std::cin >> total_nodes >> total_edges >> source >> sink;
for (int start, destination, capacity_, i = 0; i < total_edges; ++i) { parent = std::vector<int>(total_nodes, -1);
capacity = residual_capacity = std::vector< std::vector<int> >(total_nodes, std::vector<int>(total_nodes));
for (int start = 0, destination = 0, capacity_ = 0, i = 0; i < total_edges; ++i) {
std::cin >> start >> destination >> capacity_; std::cin >> start >> destination >> capacity_;
residual_capacity[start][destination] = capacity_; residual_capacity[start][destination] = capacity_;
capacity[start][destination] = capacity_; capacity[start][destination] = capacity_;
} }
} }
void ford_fulkerson(void) { void ford_fulkerson() {
while (bfs(source, sink)) { while (bfs(source, sink)) {
int current_node = sink; int current_node = sink;
int flow = std::numeric_limits<int>::max(); int flow = std::numeric_limits<int>::max();
@ -77,12 +76,12 @@ class Graph {
} }
} }
} }
void print_flow_info(void) { void print_flow_info() {
for (int i = 0; i < total_nodes; ++i) { for (int i = 0; i < total_nodes; ++i) {
for (int j = 0; j < total_nodes; ++j) { for (int j = 0; j < total_nodes; ++j) {
if (capacity[i][j] && if (capacity[i][j] &&
residual_capacity[i][j] < capacity[i][j]) { residual_capacity[i][j] < capacity[i][j]) {
edge_participated.push_back(std::make_tuple( edge_participated.emplace_back(std::make_tuple(
i, j, capacity[i][j] - residual_capacity[i][j])); i, j, capacity[i][j] - residual_capacity[i][j]));
} }
} }
@ -92,14 +91,14 @@ class Graph {
<< '\n'; << '\n';
std::cout << "\nSource\tDestination\tCapacity\total_nodes"; std::cout << "\nSource\tDestination\tCapacity\total_nodes";
for (auto& edge_data : edge_participated) { for (auto& edge_data : edge_participated) {
int source, destination, capacity_; int source = 0, destination = 0, capacity_ = 0;
std::tie(source, destination, capacity_) = edge_data; std::tie(source, destination, capacity_) = edge_data;
std::cout << source << "\t" << destination << "\t\t" << capacity_ std::cout << source << "\t" << destination << "\t\t" << capacity_
<< '\t'; << '\t';
} }
} }
}; };
int main(void) { int main() {
/* /*
Input Graph: (for testing ) Input Graph: (for testing )
4 5 0 3 4 5 0 3