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

Feature: [Linkgraph] Prioritize faster routes for passengers and express cargo #9457

Merged
merged 1 commit into from Aug 17, 2021

Conversation

@nchappe
Copy link
Contributor

@nchappe nchappe commented Jul 24, 2021

Motivation / Problem

Cargodist does not optimize for travel time but for distance, which means passengers sometimes take (for instance) a slow but short bus route instead of a faster train route to their destination. I think it would be more intuitive if cargodist prioritized the fastest paths, at least for passengers and express cargo (goods, food). Since cargo payment depends on travel time, this may also increase income for some networks.

Description

This PR adds a member variable travel_time_sum to LinkGraph::Edge. When a vehicle traverses a link, the product of its travel time and its capacity is added to this variable, so that travel_time_sum / capacity gives the average travel time of a cargo unit traversing this edge in a saturated network. Just like capacities, the value is halved every 256 days, so that older travel times weigh less in the average.

This average travel time is then used in the MCF solver in place of the distance for cargo of classes CC_PASSENGERS and CC_EXPRESS.

Limitations

This change could be hidden behind a default-disabled setting for better backward compatibility.

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 affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
Copy link
Member

@LordAro LordAro left a comment

Strange mismatch between uint64 and uint32 (and uint). Sure that these are all correct?

Loading

src/saveload/saveload.h Outdated Show resolved Hide resolved
Loading
@nchappe nchappe force-pushed the cargodist-travel-time branch from 27a891e to 4d1b978 Aug 16, 2021
@nchappe
Copy link
Contributor Author

@nchappe nchappe commented Aug 16, 2021

Thanks for the comments. There were indeed some typing inconsistencies with travel times, now they are all uint32. As for LinkGraph::BaseEdge::travel_time_sum, it has to be uint64 because it's basically travel_time * capacity, which would not fit in a uint32.

Loading

src/linkgraph/mcf.cpp Outdated Show resolved Hide resolved
Loading
@nchappe nchappe force-pushed the cargodist-travel-time branch from 4d1b978 to 116f093 Aug 17, 2021
…d express cargo

Passengers usually prefer fast paths to short paths.
Average travel times of links are updated in real-time for use in Dijkstra's algorithm,
and newer travel times weigh more, just like capacities.
@nchappe nchappe force-pushed the cargodist-travel-time branch from 116f093 to 8600b49 Aug 17, 2021
Copy link
Member

@michicc michicc left a comment

My mini test-game confirms that it works in some way (😄), and I like the behaviour more.

Test setup: A slow direct bus route compared to a longer but faster train route with one intermediate change. Unmodified, pax are perpetually waiting for full buses while with this PR, the trains carry the main load.

Somebody will cry wolf that there carefully timed network is completely disrupted, of course.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants