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

Function find_optimal_path

plugins/renepay/mcf.c:1004–1079  ·  view source on GitHub ↗

TODO(eduardo): unit test this Similar to `find_admissible_path` but use Dijkstra to optimize the distance * label. Stops when the target is hit. */

Source from the content-addressed store, hash-verified

1002/* Similar to `find_admissible_path` but use Dijkstra to optimize the distance
1003 * label. Stops when the target is hit. */
1004static bool find_optimal_path(const tal_t *ctx, struct dijkstra *dijkstra,
1005 const struct linear_network *linear_network,
1006 const struct residual_network *residual_network,
1007 const u32 source, const u32 target,
1008 struct arc *prev, char **fail)
1009{
1010 tal_t *this_ctx = tal(ctx,tal_t);
1011 bool target_found = false;
1012
1013 bitmap *visited = tal_arrz(this_ctx, bitmap,
1014 BITMAP_NWORDS(linear_network->max_num_nodes));
1015
1016 if(!visited)
1017 {
1018 if(fail)
1019 *fail = tal_fmt(ctx, "bad allocation of visited");
1020 goto finish;
1021 }
1022
1023
1024 for(size_t i=0;i<tal_count(prev);++i)
1025 prev[i].idx=INVALID_INDEX;
1026
1027 const s64 *const distance=dijkstra_distance_data(dijkstra);
1028
1029 dijkstra_init(dijkstra);
1030 dijkstra_update(dijkstra,source,0);
1031
1032 while(!dijkstra_empty(dijkstra))
1033 {
1034 u32 cur = dijkstra_top(dijkstra);
1035 dijkstra_pop(dijkstra);
1036
1037 if(bitmap_test_bit(visited,cur))
1038 continue;
1039
1040 bitmap_set_bit(visited,cur);
1041
1042 if(cur==target)
1043 {
1044 target_found = true;
1045 break;
1046 }
1047
1048 for(struct arc arc = node_adjacency_begin(linear_network,cur);
1049 !node_adjacency_end(arc);
1050 arc = node_adjacency_next(linear_network,arc))
1051 {
1052 // check if this arc is traversable
1053 if(residual_network->cap[arc.idx] <= 0)
1054 continue;
1055
1056 u32 next = arc_head(linear_network,arc);
1057
1058 s64 cij = residual_network->cost[arc.idx]
1059 - residual_network->potential[cur]
1060 + residual_network->potential[next];
1061

Callers 1

optimize_mcfFunction · 0.85

Calls 13

bitmap_test_bitFunction · 0.85
bitmap_set_bitFunction · 0.85
tal_freeFunction · 0.85
dijkstra_distance_dataFunction · 0.70
dijkstra_initFunction · 0.70
dijkstra_updateFunction · 0.70
dijkstra_emptyFunction · 0.70
dijkstra_topFunction · 0.70
dijkstra_popFunction · 0.70
node_adjacency_beginFunction · 0.70
node_adjacency_endFunction · 0.70
node_adjacency_nextFunction · 0.70

Tested by

no test coverage detected