int solve() { const int src = 0; const int snk = 1; V = 2 + N + M; for (int i = 0; i < N; ++i) { capacity[src][2 + i] = profit[i]; } for (int i = 0; i < M; ++i) { capacity[2 + N + i][snk] = cost[i]; } for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { if (requires[i][j] == 1) { capacity[2 + i][2 + N + j] = MAX_I; } } } int P = std::accumulate(profit.begin(), profit.end(), 0); int C = ford_fulkerson(src, snk); return P - C; }
int main(int argc, char**argv){ char * ficheiroIn; char * connectivity = malloc(100*sizeof(char)); node * list; int option; int initial_node, final_node; if(argc<2){ printf("TOO FEW ARGUMENTS\n"); exit(-1); } printf("PLEASE CHOOSE AN OPTION \n"); printf("1. CALCULATE THE NODES SEPARATING NODE A FROM B\n"); printf("2. CALCULATE STATISTICS AND CONNECTIVITY OF THE GRAPH\n"); if(scanf("%d", &option)!=1){ printf("ERROR: SPECIFY A VALID SOURCE AND DESTINATION\n"); exit(0); } ficheiroIn = argv[1]; int size = Read_file(ficheiroIn, &list); /*********************VECTOR DE ESTATISTICAS***************************/ int * node_statistics = malloc(size*sizeof(int)); init_vector(&node_statistics, size, 0); int * parent = malloc(size*sizeof(int)); /**********************************************************************/ int min = 100; if(option == 1){ printf("PLEASE CHOOSE A SOURCE AND DESTINATION.\n"); if(scanf("%d %d", &initial_node, &final_node)!=2){ printf("ERROR: SPECIFY A VALID SOURCE AND DESTINATION\n"); exit(0); } if(contiguous(list, initial_node, final_node)!=0) printf("THERE IS NO WAY OF SEPARATING NODE %d FROM NODE %d BECAUSE THEY ARE CONTIGUOUS\n", initial_node, final_node); else printf("FOR SPECIFIED SET OF NODES, IS NECESSARY TO TAKE %d NODE(S) WHICH IS/ARE:%s\n", ford_fulkerson(&list, size, &parent, initial_node, final_node, &connectivity, min), connectivity); }else{ int colum; int row; for(colum=0; colum<size; colum++){ for(row=0; row<size; row++){ if(row!=colum){ if(contiguous(list, colum, row)!=0){ (node_statistics[0]) ++; }else{ (node_statistics[ford_fulkerson(&list, size, &parent, colum, row, &connectivity, min)]) ++; Read_file(ficheiroIn, &list); } } } } cumulative_statistics(node_statistics, size); printf("IF YOU TAKE THE NODE(S)%s THE GRAPH WILL SPLIT\n", connectivity); } exit(0); }