| 646 | } |
| 647 | |
| 648 | s64 flow_cost(const struct graph *graph, const s64 *capacity, const s64 *cost) |
| 649 | { |
| 650 | assert(graph); |
| 651 | const size_t max_num_arcs = graph_max_num_arcs(graph); |
| 652 | s64 total_cost = 0; |
| 653 | |
| 654 | /* check preconditions */ |
| 655 | assert(capacity); |
| 656 | assert(cost); |
| 657 | assert(tal_count(capacity) == max_num_arcs); |
| 658 | assert(tal_count(cost) == max_num_arcs); |
| 659 | |
| 660 | for (u32 i = 0; i < max_num_arcs; i++) { |
| 661 | struct arc arc = {.idx = i}; |
| 662 | struct arc dual = arc_dual(graph, arc); |
| 663 | |
| 664 | if (arc_is_dual(graph, arc)) |
| 665 | continue; |
| 666 | |
| 667 | total_cost += capacity[dual.idx] * cost[arc.idx]; |
| 668 | } |
| 669 | return total_cost; |
| 670 | } |