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

Function dijkstra_

common/dijkstra.c:123–264  ·  view source on GitHub ↗

Do Dijkstra: start in this case is the dst node. */

Source from the content-addressed store, hash-verified

121
122/* Do Dijkstra: start in this case is the dst node. */
123const struct dijkstra *
124dijkstra_(const tal_t *ctx,
125 const struct gossmap *map,
126 const struct gossmap_node *start,
127 struct amount_msat amount,
128 double riskfactor,
129 bool (*channel_ok)(const struct gossmap *map,
130 const struct gossmap_chan *c,
131 int dir,
132 struct amount_msat amount,
133 void *arg),
134 u64 (*path_score)(u32 distance,
135 struct amount_msat cost,
136 struct amount_msat risk,
137 int dir,
138 const struct gossmap_chan *c),
139 void *arg)
140{
141 struct dijkstra *dij;
142 const struct gossmap_node **heap;
143 size_t heapsize;
144 struct gheap_ctx gheap_ctx;
145
146 /* There doesn't seem to be much difference with fanout 2-4. */
147 gheap_ctx.fanout = 2;
148 /* There seems to be a slight decrease if we alter this value. */
149 gheap_ctx.page_chunks = 1;
150 gheap_ctx.item_size = sizeof(*heap);
151 gheap_ctx.less_comparer = less_comparer;
152 gheap_ctx.less_comparer_ctx = NULL;
153 gheap_ctx.item_mover = item_mover;
154
155 dij = tal_arr(ctx, struct dijkstra, gossmap_max_node_idx(map));
156
157 /* Pay no attention to the man behind the curtain! */
158 global_map = map;
159 global_dijkstra = dij;
160
161 /* Wikipedia's article on Dijkstra is excellent:
162 * https://en.wikipedia.org/wiki/Dijkstra's_algorithm
163 * (License https://creativecommons.org/licenses/by-sa/3.0/)
164 *
165 * So I quote here:
166 *
167 * 1. Mark all nodes unvisited. Create a set of all the unvisited
168 * nodes called the unvisited set.
169 *
170 * 2. Assign to every node a tentative distance value: set it to zero
171 * for our initial node and to infinity for all other nodes. Set the
172 * initial node as current.[14]
173 */
174 heap = mkheap(NULL, dij, map, start, amount);
175 heapsize = tal_count(heap);
176
177 /*
178 * 3. For the current node, consider all of its unvisited neighbouds
179 * and calculate their tentative distances through the current
180 * node. Compare the newly calculated tentative distance to the

Callers

nothing calls this directly

Calls 8

gossmap_max_node_idxFunction · 0.85
mkheapFunction · 0.85
get_dijkstraFunction · 0.85
gossmap_nth_chanFunction · 0.85
gossmap_nth_nodeFunction · 0.85
amount_msat_add_feeFunction · 0.85
risk_priceFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected