News:

SimuTranslator
Make Simutrans speak your language.

Proposal: Maintaining Traffic Flow

Started by burgi, September 04, 2008, 03:13:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

burgi

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

vilvoh


Escala Real...a blog about Simutrans in Spanish...

Ormac

I thought that there were some things overlooked by the psudo-code but on further consideration it makes sense.

I support it

Ormac 8)
Simutrans Reference Material Blog SRM very wet ink
Download Simutrans Reference Material from http://docs.simutrans.com

Zeno

Also got my support. Not only seems to be simple and nice, but also sounds realistic. :D

DirrrtyDirk

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.  ;)
  
***** PAK128 Dev Team - semi-retired*****

Zeno

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

robofish

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.

prissi

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.

burgi

#8
Quote from: prissi 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.
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?

Zeno

#9
Quote from: prissi on September 04, 2008, 02:52:54 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.

Quote from: robofish 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.
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  :-[

burgi

thanks zeno, thats exactly what i meant.

Zeno

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.

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  :'(

prissi

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.

Zeno

Quote from: prissi on September 04, 2008, 07:26:44 PM
...cars are not processed in any geographic order...
Quote from: prissi on September 04, 2008, 07:26:44 PM
Therfore, the cars are processed in different order.
With this is enough. Nothing to do. :-X

prissi

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.

Zeno

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

burgi

Quote from: prissi 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.
I didn't know what the procedure was for suggesting something. Now I know its technical not feasible thats fine.

DirrrtyDirk

@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.  :)
  
***** PAK128 Dev Team - semi-retired*****

Sarrus

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