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

Road vehicles don't balance between multiple loading bays #7592

Closed
nielsmh opened this issue May 14, 2019 · 11 comments
Closed

Road vehicles don't balance between multiple loading bays #7592

nielsmh opened this issue May 14, 2019 · 11 comments
Milestone

Comments

@nielsmh
Copy link
Contributor

@nielsmh nielsmh commented May 14, 2019

Based on post on TT-Forums

Version of OpenTTD

Likely after merge of road vehicle path caching

Expected result

Road vehicles choose a free loading bay to head towards when multiple are available at a station.

Actual result

Road vehicles head towards the same loading bay even after it has been filled.

Steps to reproduce

Send many road vehicles to the same few stations with mutiple loading bays.

Suggested fix

Prevent road vehicles from caching the last 1 or 2 turns (or 10 tiles if that's shorter) before their scheduled next stop.

@MingweiSamuel
Copy link
Contributor

@MingweiSamuel MingweiSamuel commented May 16, 2019

I'm guessing caching also breaks road vehicle balancing https://wiki.openttdcoop.org/Road_Vehicle_Networking#Balacing

@nielsmh nielsmh added this to the 1.10.0 milestone Sep 1, 2019
@Wirdal
Copy link

@Wirdal Wirdal commented Oct 2, 2019

Would RoadVehUpdateCache in roadveh_cmd.cpp be a good place to start poking around?

Edit:

Looks like that function is mostly for updating GroundVehicleCache, which seems to be thing more mechanical in nature, such as speed, weight, and drag.

RoadVehPathCache is the structure that caches hold the cached path that nielsmh mentioned in the suggested fix. I'll see where it updates.

@Wirdal
Copy link

@Wirdal Wirdal commented Oct 13, 2019

After some digging and wrestling with my own IDE, the cache is updated in ChooseRoadTrack in the yapf_road.cpp file.

I think that there is another kind of pathfinding that OpenTTD has, although I am not sure. I'll look into it, though.

Edit:

NPF is the other type, but does not cache, therefor, this issue (probably) does not exist with it.

Wirdal added a commit to Wirdal/OpenTTD that referenced this issue Oct 16, 2019
@Wirdal
Copy link

@Wirdal Wirdal commented Oct 19, 2019

I just need to work on the turn counting that was the other part of the suggested fix.

Hopefully what I have now works for "less that 10 tiles", although I am not sure if they are always before the next scheduled stop.

I'll do some testing by just sending a bunch of before and after things and see how things stack up.

Wirdal added a commit to Wirdal/OpenTTD that referenced this issue Oct 19, 2019
@nielsmh
Copy link
Contributor Author

@nielsmh nielsmh commented Oct 20, 2019

I'm not sure what I was thinking with the suggested fix, it makes no sense to not cache the last 10 tiles if that's a straight road/no intersections, as that still doesn't give the vehicle any alternates.
A better attempt: Do not cache segments on the last 5, 8, or 10 (not sure, probably needs tuning?) tiles before the destination, but always at least 1 segment not cached regardless of distance.

@Eddi-z
Copy link
Contributor

@Eddi-z Eddi-z commented Oct 20, 2019

How about a different approach: still cache all the segments, but have the pathfinder add penalties for cached loading bay selections, so on average it still balances out?

@Wirdal
Copy link

@Wirdal Wirdal commented Oct 26, 2019

Any good resource for understanding YAPF? The wiki is very sparse.

@Eddi-z
Copy link
Contributor

@Eddi-z Eddi-z commented Oct 26, 2019

Rules for understanding YAPF:

  1. don't try to understand YAPF
  2. you only need to change the "follow track" function, which assigns the penalties
@JGRennison
Copy link
Contributor

@JGRennison JGRennison commented Oct 26, 2019

YAPF is not so complicated that you should not try to understand it. The source can be understood with a little time, and is by nature authoritative.

For what it's worth this is one I prepared earlier which gave satisfactory results at my end: JGRennison/OpenTTD-patches@79d5be7

A more heavyweight solution to issues around road vehicle cache invalidation in general is here: JGRennison/OpenTTD-patches@829c635, parts of this may come in handy.

@Wirdal
Copy link

@Wirdal Wirdal commented Nov 3, 2019

OK. I'll reset what I worked on and try to make some progress towards one of those suggestions (whatever may be easier for me at that time).

Also, I have never worked with this kind template work before. Double whammy.

@Wirdal
Copy link

@Wirdal Wirdal commented Nov 11, 2019

I like to think I have made progress in the the understanding of the system, or at least a semblance of
progress. However I think that @JGRennison 's first fix was the general area I was headed in, just two weeks earlier.

I don't see myself writing anything better than that, although I would be more than willing to help test it, if needed.

nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Feb 6, 2020
…stination with multiple entrances

Ported from jgrpp commit 79d5be7e265df3be8b73d484f0c7261b3c23229d
nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Feb 6, 2020
…stination with multiple entrances

Ported from jgrpp commit 79d5be7e265df3be8b73d484f0c7261b3c23229d
@nielsmh nielsmh closed this in 1a88fb5 Feb 7, 2020
douiwby added a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
…stination with multiple entrances

Ported from jgrpp commit 79d5be7e265df3be8b73d484f0c7261b3c23229d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.