| 16 | #define CHECK(arg) if(!(arg)){fprintf(stderr, "failed CHECK at line %d: %s\n", __LINE__, #arg); abort();} |
| 17 | |
| 18 | static void problem1(void){ |
| 19 | printf("Allocating a memory context\n"); |
| 20 | tal_t *ctx = tal(NULL, tal_t); |
| 21 | assert(ctx); |
| 22 | |
| 23 | printf("Allocating a graph\n"); |
| 24 | struct graph *graph = graph_new(ctx, MAX_NODES, MAX_ARCS, DUAL_BIT); |
| 25 | assert(graph); |
| 26 | |
| 27 | s64 *capacity = tal_arrz(ctx, s64, MAX_ARCS); |
| 28 | |
| 29 | graph_add_arc(graph, arc_obj(0), node_obj(1), node_obj(2)); |
| 30 | capacity[0] = 1; |
| 31 | graph_add_arc(graph, arc_obj(1), node_obj(1), node_obj(3)); |
| 32 | capacity[1] = 4; |
| 33 | graph_add_arc(graph, arc_obj(2), node_obj(2), node_obj(4)); |
| 34 | capacity[2] = 1; |
| 35 | graph_add_arc(graph, arc_obj(3), node_obj(2), node_obj(5)); |
| 36 | capacity[3] = 1; |
| 37 | graph_add_arc(graph, arc_obj(4), node_obj(3), node_obj(5)); |
| 38 | capacity[4] = 4; |
| 39 | graph_add_arc(graph, arc_obj(5), node_obj(4), node_obj(6)); |
| 40 | capacity[5] = 1; |
| 41 | graph_add_arc(graph, arc_obj(6), node_obj(6), node_obj(10)); |
| 42 | capacity[6] = 1; |
| 43 | graph_add_arc(graph, arc_obj(7), node_obj(5), node_obj(10)); |
| 44 | capacity[7] = 4; |
| 45 | |
| 46 | struct node src = {.idx = 1}; |
| 47 | struct node dst = {.idx = 10}; |
| 48 | |
| 49 | bool result = simple_feasibleflow(ctx, graph, src, dst, capacity, 5); |
| 50 | CHECK(result); |
| 51 | |
| 52 | CHECK(node_balance(graph, src, capacity) == -5); |
| 53 | CHECK(node_balance(graph, dst, capacity) == 5); |
| 54 | |
| 55 | for (u32 i = 2; i < 10; i++) |
| 56 | CHECK(node_balance(graph, node_obj(i), capacity) == 0); |
| 57 | |
| 58 | printf("Freeing memory\n"); |
| 59 | ctx = tal_free(ctx); |
| 60 | } |
| 61 | |
| 62 | static void problem2(void){ |
| 63 | /* Stress the graph constraints by setting max_num_nodes to exactly the |
no test coverage detected