|
|
|
@ -29,6 +29,8 @@ int test_max_flow()
|
|
|
|
|
double *flow = 0;
|
|
|
|
|
double flow_value;
|
|
|
|
|
|
|
|
|
|
struct Edge **cut_edges = 0;
|
|
|
|
|
|
|
|
|
|
FILE *f = fopen("tmp/flow.in", "r");
|
|
|
|
|
abort_if(!f, "could not open input file");
|
|
|
|
|
|
|
|
|
@ -53,8 +55,8 @@ int test_max_flow()
|
|
|
|
|
rval = fscanf(f, "%d %d %d ", &from, &to, &cap);
|
|
|
|
|
abort_if(rval != 3, "invalid input format");
|
|
|
|
|
|
|
|
|
|
edges[i*4] = edges[i*4+3] = from;
|
|
|
|
|
edges[i*4+1] = edges[i*4 + 2] = to;
|
|
|
|
|
edges[i * 4] = edges[i * 4 + 3] = from;
|
|
|
|
|
edges[i * 4 + 1] = edges[i * 4 + 2] = to;
|
|
|
|
|
capacities[2 * i] = cap;
|
|
|
|
|
capacities[2 * i + 1] = 0;
|
|
|
|
|
}
|
|
|
|
@ -64,8 +66,8 @@ int test_max_flow()
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < edge_count; i++)
|
|
|
|
|
{
|
|
|
|
|
graph.edges[2*i].reverse = &graph.edges[2*i+1];
|
|
|
|
|
graph.edges[2*i+1].reverse = &graph.edges[2*i];
|
|
|
|
|
graph.edges[2 * i].reverse = &graph.edges[2 * i + 1];
|
|
|
|
|
graph.edges[2 * i + 1].reverse = &graph.edges[2 * i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flow = (double *) malloc(graph.edge_count * sizeof(double));
|
|
|
|
@ -81,12 +83,38 @@ int test_max_flow()
|
|
|
|
|
for (int i = 0; i < graph.edge_count; i++)
|
|
|
|
|
{
|
|
|
|
|
struct Edge *e = &graph.edges[i];
|
|
|
|
|
if(flow[e->index] <= 0) continue;
|
|
|
|
|
if (flow[e->index] <= 0) continue;
|
|
|
|
|
|
|
|
|
|
log_info(" %d %d %6.2f / %6.2f\n", e->from->index, e->to->index,
|
|
|
|
|
flow[e->index], capacities[e->index]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log_info("Nodes reachable from origin on residual graph:\n");
|
|
|
|
|
for (int i = 0; i < graph.node_count; i++)
|
|
|
|
|
{
|
|
|
|
|
struct Node *n = &graph.nodes[i];
|
|
|
|
|
if(n->mark)
|
|
|
|
|
log_info(" %d\n", n->index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cut_edges_count = 0;
|
|
|
|
|
cut_edges = (struct Edge**) malloc(graph.edge_count * sizeof(struct Edge*));
|
|
|
|
|
abort_if(!cut_edges, "could not allocate cut_edges");
|
|
|
|
|
|
|
|
|
|
rval = get_cut_edges_from_marks(&graph, &cut_edges_count, cut_edges);
|
|
|
|
|
abort_if(rval, "get_cut_edges_from_marks failed");
|
|
|
|
|
|
|
|
|
|
log_info(" %d %d %6.2f / %6.2f\n", e->from->index, e->to->index, flow[e->index], capacities[e->index]);
|
|
|
|
|
log_info("Min cut edges:\n");
|
|
|
|
|
for (int i = 0; i < cut_edges_count; i++)
|
|
|
|
|
{
|
|
|
|
|
struct Edge *e = cut_edges[i];
|
|
|
|
|
if(capacities[e->index] <= 0) continue;
|
|
|
|
|
log_info(" %d %d\n", e->from->index, e->to->index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
|
if(cut_edges) free(cut_edges);
|
|
|
|
|
if (capacities) free(capacities);
|
|
|
|
|
if (edges) free(edges);
|
|
|
|
|
if (flow) free(flow);
|
|
|
|
|