Get the max amount of flow one can send from source to target along the path * encoded in `prev`. */
| 162 | /* Get the max amount of flow one can send from source to target along the path |
| 163 | * encoded in `prev`. */ |
| 164 | static s64 get_augmenting_flow(const struct graph *graph, |
| 165 | const struct node source, |
| 166 | const struct node target, const s64 *capacity, |
| 167 | const struct arc *prev) |
| 168 | { |
| 169 | const size_t max_num_nodes = graph_max_num_nodes(graph); |
| 170 | const size_t max_num_arcs = graph_max_num_arcs(graph); |
| 171 | assert(max_num_nodes == tal_count(prev)); |
| 172 | assert(max_num_arcs == tal_count(capacity)); |
| 173 | |
| 174 | /* count the number of arcs in the path */ |
| 175 | int path_length = 0; |
| 176 | s64 flow = INFINITE; |
| 177 | |
| 178 | struct node cur = target; |
| 179 | while (cur.idx != source.idx) { |
| 180 | assert(cur.idx < max_num_nodes); |
| 181 | const struct arc arc = prev[cur.idx]; |
| 182 | assert(arc.idx < max_num_arcs); |
| 183 | flow = MIN(flow, capacity[arc.idx]); |
| 184 | |
| 185 | /* we are traversing in the opposite direction to the flow, |
| 186 | * hence the next node is at the tail of the arc. */ |
| 187 | cur = arc_tail(graph, arc); |
| 188 | |
| 189 | /* We may never have a path exceeds the number of nodes, it this |
| 190 | * happens it means we have an infinite loop. */ |
| 191 | path_length++; |
| 192 | if(path_length >= max_num_nodes){ |
| 193 | flow = -1; |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | assert(flow < INFINITE && flow > 0); |
| 199 | return flow; |
| 200 | } |
| 201 | |
| 202 | |
| 203 | /* Helper. |
no test coverage detected