[0.17.79] Train pathfinder does not account for length of final segment

Things that has been reported already before.
aaargha
Filter Inserter
Filter Inserter
Posts: 333
Joined: Wed Dec 07, 2016 8:35 am
Contact:

[0.17.79] Train pathfinder does not account for length of final segment

Post by aaargha »

While trying to wrangle the train pathfinder to create logic circuits using trains (you know, as you do) I ran in to a train always choosing the longer of two similar paths. After experimenting a bit, and taking a look at the source code, I've arrived at the conclusion that the length of the final segment is not accounted for when determining which path is shortest.

In the picture below the path to the closer train stop contains more segments which leads to the longer path being chosen. This is because the pathfinder returns as soon as it reaches the segment containing the target rail end.
demonstration.png
demonstration.png (422.17 KiB) Viewed 1390 times
Blueprint for reproduction
I think the issue stems from

Code: Select all

double costFromStart = currentNode->costFromStart + currentSegment->getLength();
not being

Code: Select all

double costFromStart = currentNode->costFromStart + neighbor->getLength();
Changing that would likely mean changing how the initial nodes are generated and fixing viewtopic.php?f=7&t=79951
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3017
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [0.17.79] Train pathfinder does not account for length of final segment

Post by boskid »

Duplicate 78821
aaargha
Filter Inserter
Filter Inserter
Posts: 333
Joined: Wed Dec 07, 2016 8:35 am
Contact:

Re: [0.17.79] Train pathfinder does not account for length of final segment

Post by aaargha »

Ah, must have missed that one in my search. Good to know it's already handled.
Keep up the good work!
Post Reply

Return to “Duplicates”