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

Function find_admissible_path

plugins/renepay/mcf.c:818–878  ·  view source on GitHub ↗

TODO(eduardo): unit test this Finds an admissible path from source to target, traversing arcs in the * residual network with capacity greater than 0. * The path is encoded into prev, which contains the idx of the arcs that are * traversed. */

Source from the content-addressed store, hash-verified

816 * The path is encoded into prev, which contains the idx of the arcs that are
817 * traversed. */
818static bool
819find_admissible_path(const tal_t *ctx,
820 const struct linear_network *linear_network,
821 const struct residual_network *residual_network,
822 const u32 source, const u32 target, struct arc *prev)
823{
824 tal_t *this_ctx = tal(ctx,tal_t);
825
826 bool target_found = false;
827
828 for(size_t i=0;i<tal_count(prev);++i)
829 prev[i].idx=INVALID_INDEX;
830
831 // The graph is dense, and the farthest node is just a few hops away,
832 // hence let's BFS search.
833 LQUEUE(struct queue_data,ql) myqueue = LQUEUE_INIT;
834 struct queue_data *qdata;
835
836 qdata = tal(this_ctx,struct queue_data);
837 qdata->idx = source;
838 lqueue_enqueue(&myqueue,qdata);
839
840 while(!lqueue_empty(&myqueue))
841 {
842 qdata = lqueue_dequeue(&myqueue);
843 u32 cur = qdata->idx;
844
845 tal_free(qdata);
846
847 if(cur==target)
848 {
849 target_found = true;
850 break;
851 }
852
853 for(struct arc arc = node_adjacency_begin(linear_network,cur);
854 !node_adjacency_end(arc);
855 arc = node_adjacency_next(linear_network,arc))
856 {
857 // check if this arc is traversable
858 if(residual_network->cap[arc.idx] <= 0)
859 continue;
860
861 u32 next = arc_head(linear_network,arc);
862
863 assert(next < tal_count(prev));
864
865 // if that node has been seen previously
866 if(prev[next].idx!=INVALID_INDEX)
867 continue;
868
869 prev[next] = arc;
870
871 qdata = tal(this_ctx,struct queue_data);
872 qdata->idx = next;
873 lqueue_enqueue(&myqueue,qdata);
874 }
875 }

Callers 1

find_feasible_flowFunction · 0.85

Calls 5

tal_freeFunction · 0.85
node_adjacency_beginFunction · 0.70
node_adjacency_endFunction · 0.70
node_adjacency_nextFunction · 0.70
arc_headFunction · 0.70

Tested by

no test coverage detected