Timetable based separation patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Timetable based separation patch

Post by MagicBuzz »

The timetable feature was added into the trunk and I think it's quite useless without an automatic separation system.

So I designed a small patch that adds an auto-separation system to the timetable feature.

This patch is part of the ChrisIN since r11046

How to use it ? It's fully automatic. (See documentation bellow)
- First create a shared route with a few vehicles.
- Then autofill the timetable.
- When the timetable is filled, ajust the values in order to add some extra at loading/unload for each station (this will ensure late vehicles can catch up their lateness in order to ensure proper separation)
- (Mostly for savegames or after problems due to construction) Check is the first vehicle of the shared route lateness is 0. If it's not, reset the counter as the separation is based on the first vehicle of the shared route theorical time position in the route.
I recommand you use the "display timetable in ticks rather than day" option in order to fine tune the loading times. Although, the patch works with day rounded values in order to remain compatible with the "day" display.

How does it works ?
- When the second vehicle is about to leave the first station of the shared order, it checks the total timetable duration against the count of vehicle before him in the shared order chain.
- Next, it calculate since how much time the first vehicle* left the station : wait_time = (total_time / count_vehicle) * count_vehicle_before - first_vehicle_time
- If wait_time is higher than 0, then the vehicle waits until it is 0 : the separation isn't enougth with the previous vehicle
- If wait_time is 0, then the vehicle is on time, then it can leave the station and run the timetable as usual
- If wait_time is below 0, then the vehicle is late. It leaves immediately, and its lateness counter is set up with wait_time * -1 : by this way, it will try to reduce the lateness by running the timetable with a correct lateness value

The first vehicle of the shared route won't check for separation, only the following will try to follow it with correct separation. But the first vehicle will automatically adjusts the route timetable when there are changes (construction, heavy loaded station, new vehicle, etc.)
Ensure the first vehicle shared of the shared route runs on time (add enought extra wait time to station), or all vehicles will be flaged "late" and the separation won't work correctly until the first vehicle is on time.

What are the limitations ?
- Separation is not immediate. It need the vehicle enter the first station in order to reset it's separation counter. If it's late, the vehicle will try to catch up the late. As a result, for long courses and big lateness, it can take some time to obtain the correct separation.
- Separation works per routes (because I think it's the way it must work). So heavy loaded stations desserved by serval different routes could remain heavy loaded and won't seem to be correctly regulated. But vehicles of each routes will come regulary, and not by "packets".

Regardless of these limitations, I hope you'll enjoy this small patch.

Limitations resoled :
- there were a problem with the route chain order. When you injected vehicle somewhere else than the last position, the separation was quite impossible to optain. to fix that problem, the vehicle just checks his position when entering the first order station, then reorder the chain if needed.
- there is no problem anymore with orders that start with something else than a station where the vehicles load/unload.


History :
r10386 : Fix - Now each vehicle ensure its separation basing on the first vehicle in the shared orders chain. This avoid getting very hight lateness values, and a very long time for separation to be ok.
r10386 bis : Fix - No functional change, just code and comments cleanup to fit the OTTD coding style rules.
r10877 : Complete rewrite of the code, and add shared order list reorder control.
r10885 : Fix - The game doesn't crash anymore when using boats.
r10887 : All separation tests and chain order tests were moved to the "first stop station order" instead of the first order. As a result, you can start a route with a "no-stop" flag, a waypoint or a buoy, then the separation will start correctly at the first station where the vehicle actually stops.
r10908 : Removed the list of last vehicles that visited the stations. This was used for the chain reorder, but I found a better system (thanks l_Blue_l for the suggestion). Also fixed the separation counter, as I introduced a small bug when added first order destination other than a station support.
r10977 : Fix - A lot of code rewrite, and a major fix: in some cases (most cases) the separation was absolutely stuck and vehicles were just ensuring they didn't use correct separation. This bug is fixed now.
r10980 : Fix - The bug in the chain reorder process was still exist. Now it's definately corrected.
r10980 bis : Optimisation - Moved the separation computation from HandleLoading() function to BeginLoading() function. By this way the separation is computed only one time when the vehicle enters the first route station instead of many times while loading at this station.
r10990 : Added - The separation feature is now a patch option located in the vehicle section under the timetable option. It needs the timetable function enabled in order to work.
r10990 ChrisIN : Added - The separation feature is now a patch option located in the ChrisIN section under the timetable option. It needs the timetable function (vehicle section) enabled in order to work. This diff contains the ChrisIN-r10982. See the ChrisIN topic for more information. http://www.tt-forums.net/viewtopic.php?f=33&t=32698
r12032 : Update - Fixed some problems dues to trunk code structure changes. Also "cleaned" some part of code... A last hope to get integrated in the trunk.
r12038 : Update - Code cleaning to fit coding style rules
r12059 : Update - Belugas added the IsSharedListOrder class member method to replace the simple function of the same name in trunk according the patch. removed the method from the patch.
r13704 : Refresh - Tiberius did a refresh of this patch in order to comply with the current trunk.

Flyspray report opened since r10887
http://bugs.openttd.org/task/1128

Still need to test :
- Network support : I did a few tests alone, and it seems to work correctly. I'm confident as this patch stores nothing anywhere.

If anyone is playing with this patch activated on network games, please send some feedback in order to fix any problem, or confirm it works correctly. This may be one of the reason it's still not in trunk.
Attachments
Timetable based separation patch.doc
Documentation (Microsoft Word)
(168 KiB) Downloaded 985 times
timetable-separation_r13704.patch
r13704
(14.76 KiB) Downloaded 561 times
Last edited by MagicBuzz on 05 Aug 2008 18:46, edited 31 times in total.
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: What does the timetable ?

Post by DJ Nekkid »

i find them not very usefull, tho one thing is somewhat ok...

you don't need to fill the whole table, the usefull part is to just fill inn for example 10 days at the stations, and the train will stay thoose 10 days.

but you can't use it for separation, not yet anyway.

but other then that? i dont find them even remotely usefull
Member of the
ImageImage
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: What does the timetable ?

Post by MagicBuzz »

I just looked at the code and I can see why I can't see any interrest in the timetable.
- Trains will load/unload completely, THEN when will wait the remaining time. Because of this, I think it's just unusefull for late trains I think. It's should be better if the train load/unload UNTIL the stay time is up. By this way, an early train would wait a few more, while a late train could just leave the station before every cargo/passengers got time to load/unload.

There is actually nothing about separation. What I figured it should work might work with a very few work.
I'll try to design a patch for these two features.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: What does the timetable ?

Post by MagicBuzz »

Well, it's quite dirty, but it works.

As it's very simple and i'm not very skilled in C++ in order to improve it, I rely on devs to make the code cleared... :?

PS : This works only with complete timetable. I don't know how to detect incomplete timetable... In this case it should works as with the "all_shared_timetabled" flag set to "false".
User avatar
NukeBuster
Traffic Manager
Traffic Manager
Posts: 222
Joined: 04 Jan 2006 18:16
Location: Alphen aan den Rijn, The Netherlands
Contact:

Re: What does the timetable ?

Post by NukeBuster »

Please take a look at Advanced Timetable which l_Blue_l was working on.
NukeBuster

Transport Empire: The Transport Empire Linux effort
Join the Transport Empire IRC channel: [url]irc://irc.oftc.net/transportempire[/url] !

OpenTTD patch(es): Password at join
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

Well, I already read this thread, but I wasn't able to understand what it's supposed to do nor how it's supposed to work.

My small patch is just simple and (I think) it works like it should : separation is automatic and based on the line vehicules current position. each time the vehicules comes to the first order station, it will wait the needed time for separation (ie it waits until the previous vehicle is total_course_time/nb_vehicle ticks far).
Tom0004
Chairman
Chairman
Posts: 822
Joined: 01 Jul 2007 22:33
Location: Manchester, UK

Re: Timetable base separation patch

Post by Tom0004 »

but what happens to train 1, if train 2 has hit traffic, at the receiving industry ?

this patch makes it simple the way i see it

train 1 will spend 6 days loading, 15 days travelling,and 6 day unloading.

while train 1 is in its 7th day of travelling, train 2 leaves the loading station.

so this makes it, that there is a 7 day gap, between loading and unloading

using the tabletime patch, Train's 1 and 2 will try and always keep 7 days between leaving the raw industry station

hope this makes it more understandable
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

You make me realize what was wrong with my patch.
I'm currently fixing it. Now it should work as expected.

Imagine you have a timetable like this :
Sation A wait 100 ticks
Travel for 500 ticks
Station B wait 100 ticks
Travel for 1000 ticks
Station C wait 100 ticks
Traval for 200 ticks

=> Total timetable course = 2000 ticks

If you have 2 vehicles with shared orders, then after the timetable was set up, the second vehicle will wait at station A until the first vehicle left station A since at least 1000 ticks

With 10 vehicles, then the second vehicle will wait the first one left since 200 ticks. The third one will wait until the second one left since 200 ticks, etc.
The separation will be computed automatically each time a vehicle enters the first order station. By this way you can add/remove vehicles from your shared orders group, the separation will remain coherent.

I'm currently trying to compile this and make some adjustements :
- First train should ensure separation with last train. If not and improper timetable, then it will end up by all trains following the second one that is really late.
- Splitted all the code in methods of Vehicle object. Unsure methods is the best choice, it is still easy to turn it back into simple functions.
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Timetable base separation patch

Post by DJ Nekkid »

what seems to work for me, lets say i connect two somewhat large cities (3k+) and they have a separation of aprox 5-600 tiles appppart, and a normal ICE3 train or another HST, make the train, set 10 days on the first station, and make sure the trains can't come all together out of the depot, but place the depot next to the platform. then have the 1st train pinned out (i use delete a lot to close all windows).

clone the train so u have 10-20 of them. hit the green flag and wait until the first train leave the station.

this will ensure a somewhat good separation. it's not exact after 10 years, but somewhat close, unless they get into some heavy congestion or something else.

20 trains may seem to be a lot, but give it a few years, and they will all be full :)
Member of the
ImageImage
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

7of9 wrote:what seems to work for me, lets say i connect two somewhat large cities (3k+) and they have a separation of aprox 5-600 tiles appppart, and a normal ICE3 train or another HST, make the train, set 10 days on the first station, and make sure the trains can't come all together out of the depot, but place the depot next to the platform. then have the 1st train pinned out (i use delete a lot to close all windows).

clone the train so u have 10-20 of them. hit the green flag and wait until the first train leave the station.

this will ensure a somewhat good separation. it's not exact after 10 years, but somewhat close, unless they get into some heavy congestion or something else.

20 trains may seem to be a lot, but give it a few years, and they will all be full :)
You can ensure something that looks like separation with trains.
But what about buses and ships ?
Airplanes are also quite dumb, and a real separation system can just double a line revenues and ratings.
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Timetable base separation patch

Post by DJ Nekkid »

point taken... but i dont use too much buses and ships tbh, but quite easy for ships as well ... make a ship depot 20 tiles appart (for bulk/tanker type slow ships) and clone at each, and free them all at once ... seems to work like a charm, and probably the same with busses, but hell, a "space me"-button would be nice!
Member of the
ImageImage
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

7of9 wrote:point taken... but i dont use too much buses and ships tbh, but quite easy for ships as well ... make a ship depot 20 tiles appart (for bulk/tanker type slow ships) and clone at each, and free them all at once ... seems to work like a charm, and probably the same with busses, but hell, a "space me"-button would be nice!
It won't work, as the first boat will take age to load hundreds of passengers, while the next ones won't because it remains only a few passengers on the docks (I mean if you don't activate the "full load" option). So the following ships will just catch up the first one after a few minutes...

Anyway, the patch is ready to use now. It's not perfect, but it works.
Just don't try to understand what it does when you look at your vehicles, I just gave up myself. The only matter is that after some time separation is ok ;)

PS : Currently I only checked the patch with trucks. I hope it does fine with other vehicles (it should, as I only modified the global vehicle functions).
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

Two small ideas to improve this patch with trains : signals should give priority to late trains. May be YAPF should also send early vehicles not to the best path, but an acceptable alternate path (a few slower), as this should release the faster sections for late trains.
But I can't design theses changes, I have not idea on how works the PF codes.
Psistorm
Traffic Manager
Traffic Manager
Posts: 173
Joined: 05 Jun 2004 12:22

Re: Timetable base separation patch

Post by Psistorm »

I should try this patch out, ive been waiting for this feature for ages, tired of seeing my passenger trains /always/ end up right up behind each other. so one station gets 10 trains in a few days, then none for weeks until they return. makes the ratings go horrible and also clogs up the station. - I do hope this makes it into trunk, since this is IMO much better than timetabling itself.

my thoughts on the whole thing:
creating a handmade timetable is pretty much small-time tweaking. its no use in /my/ eyes. but autoseparation for a group of shared-order vehicles is revolutionary, since it changes one of (O)TTDs oldest problems, in my eyes. especially for passenger lines.
freight lines are easy to balance out, since trains will always wait for full load at the loading station. but passenger lines? no way of seeing those work properly, give it a year at most and you have a train convoy travelling along the line (also causing the side effect that the last trains in that "convoy" make no more profit since there are no passengers left to be picked up)

so yeah, hope this makes trunk someday, its a great idea :)
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

Psistorm wrote:I should try this patch out, ive been waiting for this feature for ages, tired of seeing my passenger trains /always/ end up right up behind each other. so one station gets 10 trains in a few days, then none for weeks until they return. makes the ratings go horrible and also clogs up the station. - I do hope this makes it into trunk, since this is IMO much better than timetabling itself.

my thoughts on the whole thing:
creating a handmade timetable is pretty much small-time tweaking. its no use in /my/ eyes. but autoseparation for a group of shared-order vehicles is revolutionary, since it changes one of (O)TTDs oldest problems, in my eyes. especially for passenger lines.
freight lines are easy to balance out, since trains will always wait for full load at the loading station. but passenger lines? no way of seeing those work properly, give it a year at most and you have a train convoy travelling along the line (also causing the side effect that the last trains in that "convoy" make no more profit since there are no passengers left to be picked up)

so yeah, hope this makes trunk someday, its a great idea :)
Keep in mind the timetable must be updated manually.
You must slightly increase the waiting value for each station, in order to help late train to make up their lateness while on time trains wait a few.
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Re: Timetable base separation patch

Post by l_Blue_l »

@MagicBuzz. Nice work. I see i have some compitition here to improve the Timetableing systme. :p. Both our system i believe will still be quite different. Yours uses the timetable to seperate the Vehicles while mine would use the average travel times to seperate the Vehicles. Since now i am back at University and have lack of free time i have put all my OpenTTD Development on hold but i hope i will beable to post some Clean and up to date version of my patches soon. If you would like to use any of my code from auto seperate vehicles in your patch feel free to do so just remember to give me credit where justified.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

l_Blue_l wrote:@MagicBuzz. Nice work. I see i have some compitition here to improve the Timetableing systme. :p. Both our system i believe will still be quite different. Yours uses the timetable to seperate the Vehicles while mine would use the average travel times to seperate the Vehicles. Since now i am back at University and have lack of free time i have put all my OpenTTD Development on hold but i hope i will beable to post some Clean and up to date version of my patches soon. If you would like to use any of my code from auto seperate vehicles in your patch feel free to do so just remember to give me credit where justified.
I'll take a look at your patch because I have a small problem...
On a route that takes like 20k ticks, the only way I found to make the trains reaching their "chain position" it to flag them late. But when a train is 15k ticks late, it takes ages for it to catch up its schedule...
I definately need to find a better system.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

I just got an idea to help getting correct separation faster...
Currently, each vehicle checks its separation with the previous one. But when the previous vehicle is in fact at the same station of behind, the vehicle thinks it's late but it is early ! Because of this, auto separation will fail on heavy network when you add vehicles to the route without taking care of the order (it's quite impossible to do).

I think it each vehicle checks it's separation with the first one should be better, as the vehicle will know immediately and correctly if it's early or late. As a result, there is a risk of heavy traffic jam when adding several vehicle in the wrong place in the chain... I'll check if it's a real matter or not, it should be temporary only.

The new system will be :
wait_time = (total_time / count_vehicles) * position_in_chain - first_vehicle_distance
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Re: Timetable base separation patch

Post by l_Blue_l »

I forget which version of my patch is online atm but i expect to beable to post a clean updated version of my patch within the next 24 hours.

I'm glad you found a way to fix that one as i would of been no help. After you explained that your system makes A LOT of sence to me now. If i knew of your solution before i started my patch i dont think i would have done it. Also that could be a real problem the traffic jam. Just wondering is the position_in_chain dynamic of fixed. A dynamic position in chain would reduce the affects of traffic jams and vehicels getting over taken.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Timetable base separation patch

Post by MagicBuzz »

I updated the patch with first vehicle based separation system.
As I believed, its the day and the night :) Separation process if incredibely faster. But the bad effect is when you add many vehicles at the same time and inject them in the trafic... The resulting trafic jam just breaks the current separation and it take a while to get it back. You can avoid this by injecting the new vehicles one by one, ensuring the first station in chain always have one free slot for already running vehicles.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: _dp_ and 16 guests