Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Plese fix the code for. I don't know why it don't work. here is the what the output of the program should be. here what
Plese fix the code for. I don't know why it don't work.
here is the what the output of the program should be.
here what I got so far. It don't wok. Thank you.
#includeOutflow of 0 is 10, should be 10 Inflow of 999 is 10, should be 10 End Test#include #include #include #include using namespace std; #define V 6 bool findAugmentingPath(int n, int s, int t, int *rGraph, int path[]) { int parent[V]; bool visited[V]; memset(visited, 0, sizeof(visited)); queue int> q; q.push(s); visited[s] = true; path[s] = -1; // Standard BFS Loop while (!q.empty()) { int u = q.front(); q.pop(); for (int v=0; vV; v++) { if (visited[v]==false && *(rGraph + u + v) > 0) { q.push(v); parent[v] = u; visited[v] = true; } } } return (visited[t] == true); } // do not change the parameters in this function. void maximum_flow(int n, int s, int t, int *capacity, int *flow)//this is the function prototype that professor gave. { int i, j, res_cap[n][n], path[n]; // to hold residual capacity and BFS' augmenting path int min_flow_path = INT_MAX; // to hold the min of the augmenting path // Assign residual capacity equal to the given capacity for (i = 0; i for (j = 0; j // no initial flow } // augment the path while it exist from s to t while (findAugmentingPath(n, s, t, &(res_cap[0][0]), path)) { // find min of the augmenting path for (j = t; j != s; j = path[j]) { i = path[j]; min_flow_path = min(min_flow_path, res_cap[i][j]); } // update residual capacities and flows on both directions for (j = t; j != s; j = path[j]) { i = path[j]; if(*(capacity + i*n + j) > 0) *(flow + i*n + j) += min_flow_path; else *(flow + j*n + i) -= min_flow_path; res_cap[i][j] -= min_flow_path; res_cap[j][i] += min_flow_path; } } } // do not modify main. Also professor gave to test the program. int main(void) { int cap[1000][1000], flow[1000][1000]; int i,j, flowsum; for(i=0; ifor( j =0; jfor(i=0; ifor( j=i+1; jfor(i=1; ifor(i=500; i for( i=754; i"prepared capacity matrix, now executing maxflow code "; maximum_flow(1000,0,999,&(cap[0][0]),&(flow[0][0])); for(i=0; ifor(j=0; jif( flow[i][j] > cap[i][j] ) { cout "Capacity violated "; exit(0); } } flowsum = 0; for(i=0; i"Outflow of 0 is " ", should be 10 "; flowsum = 0; for(i=0; i"Inflow of 999 is " ", should be 10 "; cout "End Test "; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started