From cca6495d1e6c6a4c76487bd05c77fe74b8f1a109 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 11 Aug 2015 21:06:21 +0100 Subject: [PATCH 1/3] Auto timetabling: bias timetable adjustment to favour negative adjustments. This is to prevent positive feedback where timetable times are increased due to congestion, which creates more congestion due to trains waiting for extended periods at stations and/or due to timetable auto separation going overboard due to overly long timetables. * Double rate of negative adjustments. * Half rate of positive adjustments. * Only do step changes for large negative adjustments. * Reduce jam detection threshold. --- src/timetable_cmd.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index c26b4e73b2..809a4149b0 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -668,15 +668,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) new_time = time_loading; } - /* Check for too large a difference from expected time, and if so don't average. */ - if (!(new_time > (int32)timetabled * 2 || new_time < (int32)timetabled / 2)) { - int arrival_error = timetabled - new_time; - /* Compute running average, with sign conversion to avoid negative overflow. */ - new_time = ((int32)timetabled * 4 + new_time + 2) / 5; - /* Use arrival_error to finetune order ticks. */ - if (arrival_error < 0) new_time++; - if (arrival_error > 0) new_time--; - } else if (new_time > (int32)timetabled * 10 && travelling) { + if (new_time > (int32)timetabled * 4 && travelling) { /* Possible jam, clear time and restart timetable for all vehicles. * Otherwise we risk trains blocking 1-lane stations for long times. */ ChangeTimetable(v, v->cur_real_order_index, 0, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true); @@ -686,6 +678,15 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index); } return; + } else if (new_time >= (int32)timetabled / 2) { + /* Compute running average, with sign conversion to avoid negative overflow. */ + if (new_time < (int32)timetabled) { + new_time = ((int32)timetabled * 3 + new_time * 2 + 2) / 5; + } else { + new_time = ((int32)timetabled * 9 + new_time + 5) / 10; + } + } else { + /* new time is less than hald old time, set value directly */ } if (new_time < 1) new_time = 1; From 40ad3dea020de15e2c25788eef15ca7270e41f23 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 11 Aug 2015 21:20:01 +0100 Subject: [PATCH 2/3] Auto separation: Add setting to scale vehicle lateness adjustments. No longer set vehicle lateness to 0 if separation fails, instead leave it as it was. The setting defaults to 100% (full abruptness, old behaviour). Reduce the setting if auto separation is too disruptive, e.g. causes excessive waiting in stations. Note that this is not savegame compatible. --- src/lang/english.txt | 2 ++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 14 ++++++++++++++ src/timetable_cmd.cpp | 7 +++++-- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 3a4de4156c..04181e382c 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1400,6 +1400,8 @@ STR_CONFIG_SETTING_TIMETABLE_IN_TICKS :Show timetable STR_CONFIG_SETTING_TIMETABLE_IN_TICKS_HELPTEXT :Show travel times in time tables in game ticks instead of days STR_CONFIG_SETTING_TIMETABLE_SEPARATION :Use timetable to ensure vehicle separation: {STRING2} STR_CONFIG_SETTING_TIMETABLE_SEPARATION_HELPTEXT :Select whether to ensure separation of vehicles when using automatic timetables +STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE :Vehicle separation factor: {STRING2} +STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE_HELPTEXT :How much of the vehicle separation timetable change to apply at each step STR_CONFIG_SETTING_TIMETABLE_SHOW_ARRIVAL_DEPARTURE :Show arrival and departure in timetables: {STRING2} STR_CONFIG_SETTING_TIMETABLE_SHOW_ARRIVAL_DEPARTURE_HELPTEXT :Display anticipated arrival and departure times in timetables STR_CONFIG_SETTING_QUICKGOTO :Quick creation of vehicle orders: {STRING2} diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 452f6b6fd2..1c3da570a7 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1628,6 +1628,7 @@ static SettingsContainer &GetSettingsTree() vehicles->Add(new SettingEntry("order.serviceathelipad")); vehicles->Add(new SettingEntry("order.timetable_automated")); vehicles->Add(new SettingEntry("order.timetable_separation")); + vehicles->Add(new SettingEntry("order.timetable_separation_rate")); } SettingsPage *limitations = main->Add(new SettingsPage(STR_CONFIG_SETTING_LIMITATIONS)); diff --git a/src/settings_type.h b/src/settings_type.h index b3eeae407f..7c3b34478d 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -440,6 +440,7 @@ struct OrderSettings { bool no_servicing_if_no_breakdowns; ///< don't send vehicles to depot when breakdowns are disabled bool timetable_automated; ///< whether to automatically manage timetables bool timetable_separation; ///< whether to perform automatic separation based on timetable + uint8 timetable_separation_rate; ///< percentage of timetable separation change to apply bool serviceathelipad; ///< service helicopters at helipads automatically (no need to send to depot) }; diff --git a/src/table/settings.ini b/src/table/settings.ini index d7c6d692a9..53efed2fe6 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -347,6 +347,20 @@ str = STR_CONFIG_SETTING_TIMETABLE_SEPARATION strhelp = STR_CONFIG_SETTING_TIMETABLE_SEPARATION_HELPTEXT cat = SC_EXPERT +[SDT_VAR] +base = GameSettings +var = order.timetable_separation_rate +type = SLE_UINT8 +from = TIMESEP_SV +def = 100 +min = 0 +max = 100 +interval = 10 +str = STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE +strhelp = STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE_HELPTEXT +strval = STR_CONFIG_SETTING_PERCENTAGE +cat = SC_EXPERT + ; There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow ; these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. [SDT_OMANY] diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 809a4149b0..3fddfbe6ac 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -548,8 +548,11 @@ void UpdateSeparationOrder(Vehicle *v_start) } int separation_ahead = SeparationBetween(v, v->AheadSeparation()); int separation_behind = SeparationBetween(v->BehindSeparation(), v); - v->lateness_counter = (separation_ahead - separation_behind) / 2; - if (separation_ahead == -1 || separation_behind == -1) v->lateness_counter = 0; + if (separation_ahead != -1 && separation_behind != -1) { + int new_lateness = (separation_ahead - separation_behind) / 2; + v->lateness_counter = (new_lateness * _settings_game.order.timetable_separation_rate + + v->lateness_counter * (100 - _settings_game.order.timetable_separation_rate)) / 100; + } v = v->AheadSeparation(); } while (v != v_start); } From 25bc8eb1e2019a5482b1ec49e606672eea383304 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 11 Aug 2015 21:24:56 +0100 Subject: [PATCH 3/3] Save/load changes for timetable_separation_rate setting. --- src/table/settings.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/table/settings.ini b/src/table/settings.ini index 345c575a31..af0754bbd1 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -355,7 +355,6 @@ patxname = ""auto_timetables.order.timetable_separation"" base = GameSettings var = order.timetable_separation_rate type = SLE_UINT8 -from = TIMESEP_SV def = 100 min = 0 max = 100 @@ -364,6 +363,8 @@ str = STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE strhelp = STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE_HELPTEXT strval = STR_CONFIG_SETTING_PERCENTAGE cat = SC_EXPERT +extver = SlXvFeatureTest(XSLFTO_AND, XSLFI_AUTO_TIMETABLE) +patxname = ""auto_timetables.order.timetable_separation_rate"" ; There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow ; these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI.