Advertisement

Traffic AI

Started by April 05, 2002 11:21 AM
18 comments, last by JSCFaith 22 years, 7 months ago
How, should I go about implementing a traffic system. It should support as many lanes as you want. Left + right turn lanes, Bus lanes,through lanes, merger lanes, highway lanes, on ramps, off ramps. bike lanes, side walks, traffic lights, train stops, 4, 3, 2 way stops, turn signals, etc. You should be able to change light timings (including right and left turn signals), change speed limits, change right of ways, Place stop signs, lights, add light triggers. It should be able to handle 100s of cars, if not 1000s. Basically, does any system this complecated exist? For example, SimCity 3000, has a very limited traffic system. My system needs to allow a car to trave from point A, to point B. It should know how to travers lanes, make left and right turns at intercetions, etc. Basically, this system would be used to test road designs for the most efficient use. I would also, like to try to implement this into a city game, or traffic game sometime in the future. Does this seem feseable for one person to do? I have a few years to do it, and my 3d engine is nearly complete. If you could help, I would appreciate. P.S I have a few ideas on how I could implement this. I just wanted to hear what other people's thoughts were. Someone else could have an apporach that is much better. Thanks for your thoughts in advance. ...added more criteria. [edited by - JSCFaith on April 5, 2002 12:44:09 PM]
Here's a good start on some steering behaviors. Halfway down the page, you will see a list of links showing various examples. The ones toward the bottom will interest you as they deal with path following and collision avoidance. If you were to combine this with node based pathfinding as well as response to the environment (e.g. signals), you can make your own hybrid that would work.

It DOES sound like a monster project! Good luck!

Dave Mark
President and Lead Designer
Intrinsic Algorithm Development

"Reducing the world to mathematical equations!"

[edited by - InnocuousFox on April 5, 2002 5:49:05 PM]

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Advertisement
Check Gamasutra.com, a while ago there was a good article on how they did the traffic in Midtown madness - it explained it really well, and showed how to do it without eating up the CPU time.

Trying is the first step towards failure.
Trying is the first step towards failure.
You might want to consider each car, bike or pedestrian to be an independent agent, controlled by a Finite State Machine. Choosing the design for each FSM would be a matter of putting yourself in the car, on the bike or on your feet in the environment and writing down the rules and actions you follow to achieve goals.

Driving from A to B can be thought of as passing through a set of waypoint, each located at an intersection... and staying on the road (or footpath) as much as possible!

Consider approaching a left turn at the next intersection... you would need to:

a) move to the left lane;
b) decelerate
c) make the turn

which could be broken down into:

a.1) find an opening in the next lane
a.2) indicate a lane change to the left
a.3) move one lane to the left
a.4) if not in left most lane, return to a.1

(this model assumes driving on the left side of the road... if you want them to drive on the right, you''ll need to add a stop condition that tests if they''re on the left most lane heading in their direction!)

c) might break down as:

c.1) indicate the turn
c.2) give way to other traffic
c.3) turn into nearest lane of new road


You can see from this that you might want to consider a heirarchical planning system. These are fairly widespread in the game industry these days and there''s plenty of literature online about them.

You are certainly taking on a big project, but don''t let that stop you. Just approach it incrementally and set yourself sub-goals to achieve... like designing an agent that can drive in a single lane of traffic and speed up and slow down to accomodate other drivers in the lane... then add the ability to respond to traffic signals... then add changing lanes... etc, etc,...

Good luck and keep us posted as to your progress!

Timkin
I think in "Game Programming Gems II" there was an AI article describing specifically an instance of using a Fuzzy State Machine to control spacing between following cars using acceleration and deceleration. In fact, it may very well have been written by our very own Eric "Geta" Dybsand.

Dave Mark
President and Lead Designer
Intrinsic Algorithm Development

"Reducing the world to mathematical equations!"

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Timkin, I would suggest that rather than treating the vehicles and pedestrians as intelligent agents, treat the roads an intersections as the brains - giving the pedestrians and vehicles orders which they will mindlessly follow. I''m looking at something like this:

a.1) find an opening in the next lane
a.2) indicate a lane change to the left
a.3) move one lane to the left
a.4) if not in left most lane, return to a.1

and thinking that to find an opening in the next lane would require an awareness of all surrounding vehicles, thus meaning that you would probably want some type of tree structure to store the location of all the vehicles (or spend a really long time iteratively searching for vehicles in the way ). I figure, that it would be a lot easier to just make each section of road "in control" of a set of cars, and make sure that they don''t crash, and that they change lanes and what not.

Then, when you want to give way to other traffic, you again have to seach for other cars, plus, if there are other conditions (say a green light for you, indicating that you can turn, or the path is clear but you have a red light), then it gets even more complicated.

I don''t know, I am 100% certain that you would have had more experience than me , so maybe you have a better way of implementing it to what I am thinking.

Trying is the first step towards failure.
Trying is the first step towards failure.
Advertisement
In a way, it would be like The Sims model wherein the objects broadcast their uses and effects to a certain radius rather than the people constantly polling all the objects in the world. That way, a red light would broadcast to nearby cars that they need to stop. Just something to ponder.

Dave Mark
President and Lead Designer
Intrinsic Algorithm Development

"Reducing the world to mathematical equations!"

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

quote: Original post by ragonastick
Timkin, I would suggest that rather than treating the vehicles and pedestrians as intelligent agents, treat the roads an intersections as the brains - giving the pedestrians and vehicles orders which they will mindlessly follow. I''m looking at something like this:

a.1) find an opening in the next lane
a.2) indicate a lane change to the left
a.3) move one lane to the left
a.4) if not in left most lane, return to a.1

and thinking that to find an opening in the next lane would require an awareness of all surrounding vehicles, thus meaning that you would probably want some type of tree structure to store the location of all the vehicles (or spend a really long time iteratively searching for vehicles in the way ). I figure, that it would be a lot easier to just make each section of road "in control" of a set of cars, and make sure that they don''t crash, and that they change lanes and what not.

Then, when you want to give way to other traffic, you again have to seach for other cars, plus, if there are other conditions (say a green light for you, indicating that you can turn, or the path is clear but you have a red light), then it gets even more complicated.

Original post by ragonastick
I don''t know, I am 100% certain that you would have had more experience than me , so maybe you have a better way of implementing it to what I am thinking.


Hehe… don''t be so sure of that! I''ve never implemented a traffic system before! All I am doing is compiling ideas from different problems that I have worked on - and read about - and applying them to your problem. For instance, as IFox mentioned, there was an article regarding the use of Fuzzy State Machines for the acceleration/deceleration problem… it was in Game Programming Gems (I) though, as I have it on my shelf at home (and I still haven''t picked up volume II from the campus bookshop!)!

I think the question of ''what'' should be in control is an excellent question to ask. I can see very valid arguments for both sides: i.e., agents (cars, bikes, pedestrians) in control vs environment in control. Perhaps the answer is a combination of these, as IFox suggested with environment objects polling surrounding agents.

As for the lane changing problem, I don''t really see that as a problem at all… if there is no opening beside the car (or bike) then it can choose to speed up or slow down to come closer to an opening. Using it''s indicator should send a signal to the car behind the opening to slow down (if they are courteous) and let the other car change lanes.

Like I said, this is going to be a very complex system you design, whatever the approach you choose. Don''t be daunted… just decide on the model you want to implement (be it your own idea or someone elses) and go for it! I''m sure members of this forum would be happy to help out with solving problems along the way!

Cheers,

Timkin

One thing you might want to consider is driving personalities. Actions are reacted to differently by different people, and might want to be modeled in your program.
Wow ohohvi! I had put in a little bit of some thoughts on that very same idea in my last post, but I deleted them to keep the post simple and really only about one point!

Please post any ideas you have as to how you would describe driver personalities and how they would affect the simulation!

Cheers,

Timkin

This topic is closed to new replies.

Advertisement