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

Function solve_case

plugins/askrene/test/run-mcf-large.c:53–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53static bool solve_case(const tal_t *ctx)
54{
55 int ret;
56 static int c = 0;
57 c++;
58 const tal_t *this_ctx = tal(ctx, tal_t);
59
60 int N_nodes, N_arcs;
61 ret = myscanf("%d %d\n", &N_nodes, &N_arcs);
62 CHECK(ret == 2);
63 printf("Testcase %d\n", c);
64 printf("nodes %d arcs %d\n", N_nodes, N_arcs);
65 if (N_nodes == 0 && N_arcs == 0)
66 goto fail;
67
68 const int MAX_NODES = N_nodes;
69 const int DUAL_BIT = next_bit(N_arcs-1);
70 const int MAX_ARCS = 1LL << (DUAL_BIT+1);
71 printf("max nodes %d max arcs %d bit %d\n", MAX_NODES, MAX_ARCS, DUAL_BIT);
72
73 struct graph *graph = graph_new(ctx, MAX_NODES, MAX_ARCS, DUAL_BIT);
74 CHECK(graph);
75
76 s64 *capacity = tal_arrz(ctx, s64, MAX_ARCS);
77 s64 *cost = tal_arrz(ctx, s64, MAX_ARCS);
78
79 for (u32 i = 0; i < N_arcs; i++) {
80 u32 from, to;
81 ret = myscanf("%" PRIu32 " %" PRIu32 " %" PRIi64 " %" PRIi64,
82 &from, &to, &capacity[i], &cost[i]);
83 CHECK(ret == 4);
84 struct arc arc = {.idx = i};
85 graph_add_arc(graph, arc, node_obj(from), node_obj(to));
86
87 struct arc dual = arc_dual(graph, arc);
88 cost[dual.idx] = -cost[i];
89 }
90 printf("Reading arcs finished\n");
91 struct node src = {.idx = 0};
92 struct node dst = {.idx = 1};
93
94 s64 amount, best_cost;
95 ret = myscanf("%" PRIi64 " %" PRIi64, &amount, &best_cost);
96 CHECK(ret == 2);
97
98 bool result = simple_mcf(ctx, graph, src, dst, capacity, amount, cost);
99 CHECK(result);
100
101 CHECK(node_balance(graph, src, capacity) == -amount);
102 CHECK(node_balance(graph, dst, capacity) == amount);
103
104 for (u32 i = 2; i < N_nodes; i++)
105 CHECK(node_balance(graph, node_obj(i), capacity) == 0);
106
107 const s64 total_cost = flow_cost(graph, capacity, cost);
108 CHECK(total_cost == best_cost);
109
110 tal_free(this_ctx);

Callers 1

mainFunction · 0.85

Calls 10

myscanfFunction · 0.85
next_bitFunction · 0.85
graph_newFunction · 0.85
graph_add_arcFunction · 0.85
node_objFunction · 0.85
simple_mcfFunction · 0.85
node_balanceFunction · 0.85
flow_costFunction · 0.85
tal_freeFunction · 0.85
arc_dualFunction · 0.50

Tested by

no test coverage detected