MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

plugins/askrene/test/run-mcf.c:18–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#define DUAL_BIT 7
17
18int main(int argc, char *argv[])
19{
20 common_setup(argv[0]);
21 printf("Allocating a memory context\n");
22 tal_t *ctx = tal(NULL, tal_t);
23 assert(ctx);
24
25 printf("Allocating a graph\n");
26 struct graph *graph = graph_new(ctx, MAX_NODES, MAX_ARCS, DUAL_BIT);
27 assert(graph);
28
29 s64 *capacity = tal_arrz(ctx, s64, MAX_ARCS);
30 s64 *cost = tal_arrz(ctx, s64, MAX_ARCS);
31
32 graph_add_arc(graph, arc_obj(0), node_obj(0), node_obj(1));
33 capacity[0] = 2, cost[0] = 0;
34 graph_add_arc(graph, arc_obj(1), node_obj(0), node_obj(2));
35 capacity[1] = 2, cost[1] = 0;
36 graph_add_arc(graph, arc_obj(2), node_obj(1), node_obj(3));
37 capacity[2] = 1, cost[2] = 1;
38 graph_add_arc(graph, arc_obj(3), node_obj(1), node_obj(4));
39 capacity[3] = 1, cost[3] = 2;
40 graph_add_arc(graph, arc_obj(4), node_obj(2), node_obj(3));
41 capacity[4] = 2, cost[4] = 1;
42 graph_add_arc(graph, arc_obj(5), node_obj(2), node_obj(4));
43 capacity[5] = 1, cost[5] = 2;
44 graph_add_arc(graph, arc_obj(6), node_obj(3), node_obj(5));
45 capacity[6] = 3, cost[6] = 0;
46 graph_add_arc(graph, arc_obj(7), node_obj(4), node_obj(5));
47 capacity[7] = 3, cost[7] = 0;
48
49 struct node src = {.idx = 0};
50 struct node dst = {.idx = 5};
51
52 bool result = simple_mcf(ctx, graph, src, dst, capacity, 4, cost);
53 CHECK(result);
54
55 CHECK(node_balance(graph, src, capacity) == -4);
56 CHECK(node_balance(graph, dst, capacity) == 4);
57
58 for (u32 i = 1; i < 4; i++)
59 CHECK(node_balance(graph, node_obj(i), capacity) == 0);
60
61 const s64 total_cost = flow_cost(graph, capacity, cost);
62 printf("best flow cost: %" PRIi64 "\n", total_cost);
63 CHECK(total_cost == 5);
64
65 printf("Freeing memory\n");
66 ctx = tal_free(ctx);
67 common_shutdown();
68 return 0;
69}

Callers

nothing calls this directly

Calls 10

common_setupFunction · 0.85
graph_newFunction · 0.85
graph_add_arcFunction · 0.85
arc_objFunction · 0.85
node_objFunction · 0.85
simple_mcfFunction · 0.85
node_balanceFunction · 0.85
flow_costFunction · 0.85
tal_freeFunction · 0.85
common_shutdownFunction · 0.85

Tested by

no test coverage detected