| 60 | } |
| 61 | |
| 62 | static void problem2(void){ |
| 63 | /* Stress the graph constraints by setting max_num_nodes to exactly the |
| 64 | * number of node that participate and put all nodes in line to achieve |
| 65 | * the largest path length possible. */ |
| 66 | printf("Allocating a memory context\n"); |
| 67 | tal_t *ctx = tal(NULL, tal_t); |
| 68 | assert(ctx); |
| 69 | |
| 70 | printf("Allocating a graph\n"); |
| 71 | struct graph *graph = graph_new(ctx, 5, MAX_ARCS, DUAL_BIT); |
| 72 | assert(graph); |
| 73 | |
| 74 | s64 *capacity = tal_arrz(ctx, s64, MAX_ARCS); |
| 75 | |
| 76 | graph_add_arc(graph, arc_obj(0), node_obj(0), node_obj(1)); |
| 77 | capacity[0] = 1; |
| 78 | graph_add_arc(graph, arc_obj(1), node_obj(1), node_obj(2)); |
| 79 | capacity[1] = 4; |
| 80 | graph_add_arc(graph, arc_obj(2), node_obj(2), node_obj(3)); |
| 81 | capacity[2] = 1; |
| 82 | graph_add_arc(graph, arc_obj(3), node_obj(3), node_obj(4)); |
| 83 | capacity[3] = 1; |
| 84 | |
| 85 | struct node src = {.idx = 0}; |
| 86 | struct node dst = {.idx = 4}; |
| 87 | |
| 88 | bool result = simple_feasibleflow(ctx, graph, src, dst, capacity, 1); |
| 89 | CHECK(result); |
| 90 | |
| 91 | CHECK(node_balance(graph, src, capacity) == -1); |
| 92 | CHECK(node_balance(graph, dst, capacity) == 1); |
| 93 | |
| 94 | for (u32 i = 1; i < 4; i++) |
| 95 | CHECK(node_balance(graph, node_obj(i), capacity) == 0); |
| 96 | |
| 97 | printf("Freeing memory\n"); |
| 98 | ctx = tal_free(ctx); |
| 99 | } |
| 100 | |
| 101 | int main(int argc, char *argv[]) |
| 102 | { |
no test coverage detected