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

Function main

plugins/askrene/test/run-dijkstra.c:40–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40int main(int argc, char *argv[])
41{
42 common_setup(argv[0]);
43 printf("Allocating a memory context\n");
44 tal_t *ctx = tal(NULL, tal_t);
45 assert(ctx);
46
47 printf("Allocating a graph\n");
48 struct graph *graph = graph_new(ctx, MAX_NODES, MAX_ARCS, DUAL_BIT);
49 assert(graph);
50
51 s64 *capacity = tal_arrz(ctx, s64, MAX_ARCS);
52 s64 *cost = tal_arrz(ctx, s64, MAX_ARCS);
53 s64 *potential = tal_arrz(ctx, s64, MAX_NODES);
54 s64 *distance = tal_arr(ctx, s64, MAX_NODES);
55 struct arc *prev = tal_arr(ctx, struct arc, MAX_NODES);
56
57 graph_add_arc(graph, arc_obj(0), node_obj(1), node_obj(2));
58 cost[0] = 7, capacity[0] = 1;
59 graph_add_arc(graph, arc_obj(1), node_obj(1), node_obj(3));
60 cost[1] = 9, capacity[1] = 1;
61 graph_add_arc(graph, arc_obj(2), node_obj(1), node_obj(6));
62 cost[2] = 14, capacity[2] = 1;
63 graph_add_arc(graph, arc_obj(3), node_obj(2), node_obj(3));
64 cost[3] = 10, capacity[3] = 1;
65 graph_add_arc(graph, arc_obj(4), node_obj(2), node_obj(4));
66 cost[4] = 15, capacity[4] = 1;
67 graph_add_arc(graph, arc_obj(5), node_obj(3), node_obj(4));
68 cost[5] = 11, capacity[5] = 1;
69 graph_add_arc(graph, arc_obj(6), node_obj(3), node_obj(6));
70 cost[6] = 2, capacity[6] = 1;
71 graph_add_arc(graph, arc_obj(7), node_obj(4), node_obj(5));
72 cost[7] = 6, capacity[7] = 1;
73 graph_add_arc(graph, arc_obj(8), node_obj(5), node_obj(6));
74 cost[8] = 9, capacity[8] = 1;
75
76 show(graph, node_obj(1));
77 show(graph, node_obj(2));
78 show(graph, node_obj(3));
79 show(graph, node_obj(4));
80 show(graph, node_obj(5));
81 show(graph, node_obj(6));
82
83 struct node src = {.idx = 1};
84 struct node dst = {.idx = 6};
85
86 bool result = dijkstra_path(ctx, graph, src, dst, false, capacity, 1,
87 cost, potential, prev, distance);
88 CHECK(result);
89
90 int pathlen = 0;
91 int arc_sequence[] = {6, 1};
92 int node_sequence[] = {3, 1};
93
94 for (struct node cur = dst; cur.idx != src.idx;) {
95 struct arc arc = prev[cur.idx];
96 printf("node(%" PRIu32 ") arc(%" PRIu32 ") - ", cur.idx,
97 arc.idx);

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
dijkstra_pathFunction · 0.85
tal_freeFunction · 0.85
common_shutdownFunction · 0.85
showFunction · 0.70
arc_tailFunction · 0.50

Tested by

no test coverage detected