Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: [Linkgraph] Improve distance scaling algorithm in demand scaler #12542

Merged

Conversation

JGRennison
Copy link
Contributor

Motivation / Problem

The current scaling algorithm produces poor quality results at values other than 0% and 100%.
At large values (e.g. > 200%) scaling is erratic does not produce results consistent with a large setting value.

This broadly is due to:

  • The base distance scaling value is DistanceMaxPlusManhattan(map size), which is far too large.
  • The "Increase effect of mod_dist > 100" adjustment is also far too large.
  • At setting values < 100%, short distances are increased too much.
  • At setting values > 100%, short distances become huge negative distances.
  • At setting values > 100%, the accuracy part of the divisor term is far too large, as a result the algorithm is pushed almost entirely into the fallback path (++chance > this->accuracy * num_demands * num_supplies, etc) which leads to poor results.

Description

Change the base distance value to IntSqrt(DistanceMaxPlusManhattan(map size)), which gives much more reasonable values and outputs, whilst still being responsive to variable map size.

Decrease the magnitude of the "Increase effect of mod_dist > 100" adjustment.

Change the scaling distance adjustment, such that it gives reasonable results with the now reduced range of mod_dist, and do not allow negative distances.

Scale divisor by a constant to reduce rounding losses.

The outputs are broadly the same as the existing algorithm at 0% and near 100%.

Limitations

N/A

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

Improve scaling at values other than 0% and 100%
Fix erratic scaling and increase effect size at large setting values
@rubidium42 rubidium42 merged commit 9647fe1 into OpenTTD:master May 1, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants