The International Simutrans Forum

 

Author Topic: Proposal: Maintaining Traffic Flow  (Read 10254 times)

0 Members and 1 Guest are viewing this topic.

Offline burgi

  • *
  • Posts: 10
Proposal: Maintaining Traffic Flow
« on: September 04, 2008, 03:13:51 AM »
I have noticed that when vehicles come across slower moving traffic it comes to a complete stop until the next tile is unoccupied. While this may only be a few milliseconds it does mean the vehicles travel with a rather jerky stop/start fashion because they catch the slower traffic faster.

What I propose is a way that the faster traffic travels at the same speed as the slower traffic until the road ahead becomes clear. I have got some puesdo-code that illustrates my idea slightly better.
Code: [Select]
LOOP UNTIL current_destination = true
IF next_tile = clear
   current_speed = max_speed
ELSE IF next_car_current_speed < current_speed THEN
   current_speed = next_car_current_speed
END IF

Comments, suggestions or flames welcome.

Thanks

John

Offline vilvoh

  • One of the good guys
  • Administrator (Inactive)
  • *
  • Posts: 4504
  • I'm the constructor, the architect
    • Escala real
Re: Proposal: Maintaining Traffic Flow
« Reply #1 on: September 04, 2008, 07:07:56 AM »
Sounds easy and simple. I support it.

Offline Ormac

  • Devotees (Inactive)
  • *
  • Posts: 85
    • Simutrans Reference Material
Re: Proposal: Maintaining Traffic Flow
« Reply #2 on: September 04, 2008, 07:24:47 AM »
I thought that there were some things overlooked by the psudo-code but on further consideration it makes sense.

I support it

Ormac 8)

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Proposal: Maintaining Traffic Flow
« Reply #3 on: September 04, 2008, 11:41:11 AM »
Also got my support. Not only seems to be simple and nice, but also sounds realistic. :D

Offline DirrrtyDirk

  • Devotees (Inactive)
  • *
  • Posts: 1253
  • JR 700 Series Shinkansen
  • Languages: EN,DE
Re: Proposal: Maintaining Traffic Flow
« Reply #4 on: September 04, 2008, 11:47:05 AM »
On the other hand, I think if it was that simple it would have probably been done by now... well, let's see what prissi has to say about this.  ;)

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Proposal: Maintaining Traffic Flow
« Reply #5 on: September 04, 2008, 11:52:59 AM »
Probably you're right... but sometimes is much more difficult to think of something than doing it. Even I would say it happens often ;D

Offline robofish

  • Devotees (Inactive)
  • *
  • Posts: 130
  • Languages: DE, EN
Re: Proposal: Maintaining Traffic Flow
« Reply #6 on: September 04, 2008, 02:15:17 PM »
That doesn't seem very realistic to me, as the last car in a line in front of traffic lights would accelerate just as fast as the first car. Also there won't be any traffic jams, because if the first car speeds up again, all other cars will immediately have the same speed.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9411
  • Languages: De,EN,JP
Re: Proposal: Maintaining Traffic Flow
« Reply #7 on: September 04, 2008, 02:52:54 PM »
Apart from that, real life do not work like this too :( And it is not simple, as it would neet to be done all the time. And which pak do you use? Usually car accelerate slowly.

Offline burgi

  • *
  • Posts: 10
Re: Proposal: Maintaining Traffic Flow
« Reply #8 on: September 04, 2008, 03:29:11 PM »
Apart from that, real life do not work like this too :( And it is not simple, as it would neet to be done all the time. And which pak do you use? Usually car accelerate slowly.
I use pak128, the cars do accelerate up to their maximum speed... after coming to a complete stop. I was thinking that the cars should then use the normal physics to get back up to their maximum speed.

edit:
The collision detection currently forcing the vehicles to stop when they encounter another car is run all the time too. How much would it adversely effect the game speed if there were lots of vehicles on the map if my idea was implemented?
« Last Edit: September 04, 2008, 03:39:18 PM by burgi »

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Proposal: Maintaining Traffic Flow
« Reply #9 on: September 04, 2008, 04:18:34 PM »
Apart from that, real life do not work like this too
???
I think there's a misunderstanding somewhere... I think burgi is talking about the following case (correct me if not!):
Truck transporting mail running ahead at max speed (IE: 45 kmh). Bus full of people travelling after the mail truck at its max speed (IE 58 kmh). The truck keeps running and running at 45 kmh; but the bus stops each time it catches the mail truck: every time goes to 0 kmh and then starts again.
If that's what he meant... I never stop my car when I follow a vehicle that is slower than me!!!
I hope the explanation is clear enogh... I've just tried it with last versions: 100 & pak128.

That doesn't seem very realistic to me, as the last car in a line in front of traffic lights would accelerate just as fast as the first car.
Sure. That is the non-realistic part of it... I wonder if it would be possible to get the only the good part, but as prissi said that won't be so simple  :-[
« Last Edit: September 04, 2008, 04:22:55 PM by Zeno »

Offline burgi

  • *
  • Posts: 10
Re: Proposal: Maintaining Traffic Flow
« Reply #10 on: September 04, 2008, 04:24:59 PM »
thanks zeno, thats exactly what i meant.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Proposal: Maintaining Traffic Flow
« Reply #11 on: September 04, 2008, 04:32:50 PM »
Maybe changing the pseudocode before to something like this: cars won't start until next is 10% of its max speed or the next tile is clear.
Code: [Select]
LOOP UNTIL current_destination = true
IF next_tile = clear
   current_speed = max_speed
ELSE IF next_car_current_speed < 10% of max_speed
   stop
ELSE IF next_car_current_speed < current_speed THEN
   current_speed = next_car_current_speed
END IF

This way it could be possible to simulate the delay between two cars starting and might not interfere sightly in other situations...  :-\
But I'm thinking in the process-cost of this executing all the time  :'(

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9411
  • Languages: De,EN,JP
Re: Proposal: Maintaining Traffic Flow
« Reply #12 on: September 04, 2008, 07:26:44 PM »
The problem is, that the speed of the next car is not really know, when processing a step, because it normally changes during processing. However, the cars are not processed in any geographic order, the hashtable is sorted by the last 7 bits (roughly) of their address. Therfore, the cars are processed in different order.

A second problem exists too: Every time a convoi comes to a crossing, it will stop, until the crossing is clear. This will will force the next car stop. And so one, no big change to the current behaviour in the end.

Going at higher speed than the leading car is not happening very often in my games (and especially not, if you are not buying the most expensive streets but try to keep the costs low).

But you can experiment for yourself: The code is in
bool automobil_t::ist_weg_frei(int &restart_speed)
in vehicle/simvehikel.cc at line 1648 following

A similar routine for city cars is
bool stadtauto_t::ist_weg_frei(grund_t *gr)
located in vehikel/simverkehr.cc line 515 following

These are called each step and decide, if the tile to enter is free. For more speed advance check, they have to check if the next tile is free too (since otherwise entering this tile will fail anyway). The logic is already there, it is needed for crossings. Of course looking two tiles ahead will eat considerably more resources, even though it is also done now quite often.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Proposal: Maintaining Traffic Flow
« Reply #13 on: September 04, 2008, 09:08:17 PM »
...cars are not processed in any geographic order...
Therfore, the cars are processed in different order.
With this is enough. Nothing to do. :-X

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9411
  • Languages: De,EN,JP
Re: Proposal: Maintaining Traffic Flow
« Reply #14 on: September 05, 2008, 08:47:44 AM »
I did not mean to force you. OpenSource is there to experiment for yourself. If you can type pseudocode, real code in those two routines should be not too difficult to understand and to write.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Proposal: Maintaining Traffic Flow
« Reply #15 on: September 05, 2008, 08:56:05 AM »
I already spend 8 hours a day coding at work, so I prefer to do some creative things in my free time... actually, I just remember I began to draw a new tram stop  ;D

Offline burgi

  • *
  • Posts: 10
Re: Proposal: Maintaining Traffic Flow
« Reply #16 on: September 05, 2008, 02:44:01 PM »
I did not mean to force you. OpenSource is there to experiment for yourself. If you can type pseudocode, real code in those two routines should be not too difficult to understand and to write.
I didn't know what the procedure was for suggesting something. Now I know its technical not feasible thats fine.

Offline DirrrtyDirk

  • Devotees (Inactive)
  • *
  • Posts: 1253
  • JR 700 Series Shinkansen
  • Languages: EN,DE
Re: Proposal: Maintaining Traffic Flow
« Reply #17 on: September 05, 2008, 04:43:02 PM »
@burgi:

You didn't do anything wrong, don't worry. But not all requests find the interest (or the time) of a developer. But even if this happens, it is still free for anybody to give it a try. And if someone else creates some code that'll do the desired stuff - it'll have still have good chances to be put into the trunk one day.  :)

Offline Sarrus pl

  • *
  • Posts: 52
  • Languages: EN, PL
Re: Proposal: Maintaining Traffic Flow
« Reply #18 on: November 06, 2008, 01:10:38 PM »
I think, that implement braking process is the solution. I mean slowing down, not stopping rapidly. I suspect cars behavior some like this:
Car will slowing down, to stop before enter occupied title. Before its speed comes zero, title in front of it will be cleared, and car starts to speed up because the title it has to stop, was moved. Next it will slowing down to stop on next title, but it will clear too, so car will speed up. The diffrents of speed in that process will make expression that car has the same speed as car in front of it.

I hope my post is easy to understand. English is not my native language.

Greetings