If seems like the majority of the penalty for trains waiting at a station with non-time based wait condidtions is applied already on arrive_station instead of on wait_station.
In the attached example a train prefers the path through 63 train stops over the path with a train braking before a station in the block. To start the trains turn on the combinator on the hazard concrete. To see which path the train chooses if the blocking train is in on_the_path delete the train stop on the hazard concrete to the north.
Example of strangeness caused by this in the wild here.
EDIT: Using this mod makes the state changes a lot easier to see.
[kovarex] [0.15.37] Early station wait penalty
[kovarex] [0.15.37] Early station wait penalty
- Attachments
-
- Early wait penalty.zip
- (3.08 MiB) Downloaded 230 times
Re: [kovarex] [0.15.37] Early station wait penalty
I would like to thank you from my heart for this report.
I knew there was something fishy there, when even 2000 of penalty for train stops wasn't enough to keep trains from going through the stops in my playthrough and clogging my system.
I really like nice and clean examples of the bug as you gave me, so it was easy to debug without having to select which train is it related to.
The bug was related to calculation of penalty related to calculation of how long will the train stay in station. This code was made long time ago, before chain signals and when the only possible condition was wait condition. Long story short, when other than TimeCondition was used, the method returns uint32_t(-1) as no value which, when used as number is 2^32 - 1, which was used as the penalty value. This was meant to make the train go to the station that is going to be empty the first. Value this big can beat 63 (stations) * 2000 (penalty) easily and much more
This is what I did for 0.16
I knew there was something fishy there, when even 2000 of penalty for train stops wasn't enough to keep trains from going through the stops in my playthrough and clogging my system.
I really like nice and clean examples of the bug as you gave me, so it was easy to debug without having to select which train is it related to.
The bug was related to calculation of penalty related to calculation of how long will the train stay in station. This code was made long time ago, before chain signals and when the only possible condition was wait condition. Long story short, when other than TimeCondition was used, the method returns uint32_t(-1) as no value which, when used as number is 2^32 - 1, which was used as the penalty value. This was meant to make the train go to the station that is going to be empty the first. Value this big can beat 63 (stations) * 2000 (penalty) easily and much more
This is what I did for 0.16
- Since we have chain signals now, and Time waiting is not used so much anymore. I completely removed the logic of dynamic penalty based on how much will the train stay in the station (use chain signals properly).
- I tweaked some of the other penalty constants.
- I moved all the constants to utility-constants, so it can be viewed by others or modded.
Code: Select all
train_path_finding =
{
train_stop_penalty = 2000,
stopped_manually_controlled_train_penalty = 2000,
stopped_manually_controlled_train_without_passenger_penalty = 7000,
signal_reserved_by_circuit_network_penalty = 1000,
train_in_station_penalty = 500,
train_in_station_with_no_other_valid_stops_in_schedule = 1000,
train_arriving_to_station_penalty = 100,
train_arriving_to_signal_penalty = 100,
train_waiting_at_signal_penalty = 100,
train_waiting_at_signal_tick_multiplier_penalty = 0.1
},
Re: [kovarex] [0.15.37] Early station wait penalty
Ah, the ol' "Negative number interpreted as an unsigned integer" shenanigan.kovarex wrote:... Long story short, when other than TimeCondition was used, the method returns uint32_t(-1) as no value which, when used as number is 2^32 - 1, which was used as the penalty value. ...
I wonder how many head-scratching this caused to players over the years
Re: [kovarex] [0.15.37] Early station wait penalty
Thank you, I'm just happy you guys keep making this game better and better!kovarex wrote:I would like to thank you from my heart for this report.
I knew there was something fishy there, when even 2000 of penalty for train stops wasn't enough to keep trains from going through the stops in my playthrough and clogging my system.
I really like nice and clean examples of the bug as you gave me, so it was easy to debug without having to select which train is it related to.
I was a bit suspicious about that when Rseding91 shared the source for the pathfinder, but I figured that if it was only applied when train were at the station it wouldn't really be that much of a problemkovarex wrote:The bug was related to calculation of penalty related to calculation of how long will the train stay in station. This code was made long time ago, before chain signals and when the only possible condition was wait condition. Long story short, when other than TimeCondition was used, the method returns uint32_t(-1) as no value which, when used as number is 2^32 - 1, which was used as the penalty value. This was meant to make the train go to the station that is going to be empty the first. Value this big can beat 63 (stations) * 2000 (penalty) easily and much more
Those are some great changes! With all the other fixes to trains I'm really looking forward to 0.16 ... and trying to break itkovarex wrote:This is what I did for 0.16
- Since we have chain signals now, and Time waiting is not used so much anymore. I completely removed the logic of dynamic penalty based on how much will the train stay in the station (use chain signals properly).
- I tweaked some of the other penalty constants.
- I moved all the constants to utility-constants, so it can be viewed by others or modded.
Code: Select all
train_path_finding = { train_stop_penalty = 2000, stopped_manually_controlled_train_penalty = 2000, stopped_manually_controlled_train_without_passenger_penalty = 7000, signal_reserved_by_circuit_network_penalty = 1000, train_in_station_penalty = 500, train_in_station_with_no_other_valid_stops_in_schedule = 1000, train_arriving_to_station_penalty = 100, train_arriving_to_signal_penalty = 100, train_waiting_at_signal_penalty = 100, train_waiting_at_signal_tick_multiplier_penalty = 0.1 },
[shameless begging]Would you please consider sharing the code for the 0.16 pathfinder, I would love to compare it to the old one. I'd be especially interested in checking if setting train_stop_penalty to a large value would still be a bad idea for performance for large train networks[/shameless begging]
Keep up the great work and have a great day!
Re: [kovarex] [0.15.37] Early station wait penalty
Can't you just test it by changing the values now? (In case you don't know, these are in core/prototypes/utility-constants.lua)aaargha wrote: Those are some great changes! With all the other fixes to trains I'm really looking forward to 0.16 ... and trying to break it
[shameless begging]Would you please consider sharing the code for the 0.16 pathfinder, I would love to compare it to the old one. I'd be especially interested in checking if setting train_stop_penalty to a large value would still be a bad idea for performance for large train networks[/shameless begging]
Keep up the great work and have a great day!
Just be aware, that changing Factorio files will make make problems automatic updater, this is why I usually refer to modding the value, which means making simple mod that just changes these values.
Last edited by Loewchen on Wed Dec 13, 2017 5:09 pm, edited 1 time in total.
Reason: Fixed quote
Reason: Fixed quote