[kovarex] [0.15.37] Early station wait penalty

This subforum contains all the issues which we already resolved.

[kovarex] [0.15.37] Early station wait penalty

Postby aaargha » Fri Nov 17, 2017 6:17 pm

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.
Attachments
Early wait penalty.zip
(3.08 MiB) Downloaded 8 times
aaargha
Filter Inserter
Filter Inserter
 
Posts: 286
Joined: Wed Dec 07, 2016 8:35 am

Re: [kovarex] [0.15.37] Early station wait penalty

Postby kovarex » Tue Dec 12, 2017 3:29 pm

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
  • 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
},
kovarex
Factorio Staff
Factorio Staff
 
Posts: 6313
Joined: Wed Feb 06, 2013 12:00 am
Location: Prague

Re: [kovarex] [0.15.37] Early station wait penalty

Postby sillyfly » Tue Dec 12, 2017 3:39 pm

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. ...


Ah, the ol' "Negative number interpreted as an unsigned integer" shenanigan.

I wonder how many head-scratching this caused to players over the years :D
sillyfly
Smart Inserter
Smart Inserter
 
Posts: 1094
Joined: Sun May 04, 2014 11:29 am

Re: [kovarex] [0.15.37] Early station wait penalty

Postby aaargha » Wed Dec 13, 2017 10:45 am

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.

Thank you, I'm just happy you guys keep making this game better and better!
kovarex 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 :)

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 problem :)
kovarex 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
},

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] :D

Keep up the great work and have a great day!
aaargha
Filter Inserter
Filter Inserter
 
Posts: 286
Joined: Wed Dec 07, 2016 8:35 am

Re: [kovarex] [0.15.37] Early station wait penalty

Postby kovarex » Wed Dec 13, 2017 5:01 pm

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] :D

Keep up the great work and have a great day!

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)
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
kovarex
Factorio Staff
Factorio Staff
 
Posts: 6313
Joined: Wed Feb 06, 2013 12:00 am
Location: Prague


Return to Resolved Problems and Bugs

Who is online

Users browsing this forum: Nyk93 and 7 guests