| 492 | } |
| 493 | |
| 494 | static void combine_cost_function(const tal_t *working_ctx, |
| 495 | const struct graph *graph, |
| 496 | const double *arc_prob_cost, |
| 497 | const double *arc_fee_cost, |
| 498 | const double *arc_delay_cost, |
| 499 | const s8 *biases, |
| 500 | double fee_dial, |
| 501 | double delay_dial, |
| 502 | double per_hop_dial, |
| 503 | double prob_dial, |
| 504 | s64 *arc_cost) |
| 505 | { |
| 506 | assert(prob_dial >= 0); |
| 507 | assert(fee_dial >= 0); |
| 508 | assert(delay_dial >= 0); |
| 509 | assert(per_hop_dial >= 0); |
| 510 | const double total_dial = prob_dial + fee_dial + delay_dial + per_hop_dial; |
| 511 | assert(fabs(total_dial - 1.0) < 1e-9); |
| 512 | |
| 513 | /* probabilty and fee costs are not directly comparable! |
| 514 | * Scale by ratio of (positive) medians. */ |
| 515 | const double median_fee = get_median(working_ctx, graph, arc_fee_cost); |
| 516 | const double median_prob = get_median(working_ctx, graph, arc_prob_cost); |
| 517 | const double median_delay = get_median(working_ctx, graph, arc_delay_cost); |
| 518 | const double ln_30 = log(30); |
| 519 | const size_t max_num_arcs = graph_max_num_arcs(graph); |
| 520 | |
| 521 | for(struct arc arc = {.idx=0};arc.idx < max_num_arcs; ++arc.idx) |
| 522 | { |
| 523 | if (arc_is_dual(graph, arc) || !arc_enabled(graph, arc)) |
| 524 | continue; |
| 525 | |
| 526 | const double pcost = arc_prob_cost[arc.idx]; |
| 527 | const double fcost = arc_fee_cost[arc.idx]; |
| 528 | const double dcost = arc_delay_cost[arc.idx]; |
| 529 | double combined; |
| 530 | u32 chanidx; |
| 531 | int chandir; |
| 532 | s32 bias; |
| 533 | |
| 534 | assert(fcost != DBL_MAX); |
| 535 | assert(pcost != DBL_MAX); |
| 536 | combined = fcost / median_fee * fee_dial + |
| 537 | dcost / median_delay * delay_dial + |
| 538 | /* per-hop cost is 1 for every arc */ |
| 539 | 1.0 * per_hop_dial + |
| 540 | pcost / median_prob * prob_dial; |
| 541 | |
| 542 | /* The median costs corresponds to the normalize value 1.0. |
| 543 | * An arbitrary up-scale is used here to capture values below |
| 544 | * the median when converting costs from double to u64. |
| 545 | * To match the rough values of the previous version |
| 546 | * (see commit 2a0f09fc2d79c636817d610e529c3160b531d51e) |
| 547 | * we use the median of the fee times the old MU_MAX (100). |
| 548 | * */ |
| 549 | combined *= median_fee * 100; |
| 550 | |
| 551 | /* Bias is in human scale, where "bigger is better" */ |
no test coverage detected