Python: Traffic-Simulation (cars on the road)

I want to create a traffic simulator, as here: http://www.doobybrain.com/wp-content/uploads/2008/03/traffic-simulation.gif But I did not speak very deeply about this.

I would create a cool car. Each car has its own color, position, etc.

And I could create a road with an array.

But how to tell the car where to go? Can i hear your ideas

EDIT: Is it forbidden to get new ideas from good programmers? Why do some people want to close this topic? Or ask such questions? I do not understand them. :(

EDIT2: Next time I will go to the forum gamer. I like the ideas so far. Thanks!

+4
source share
7 answers

There is a Java package called processing that artists and non-beginner programmers are targeting, which include some great visualization features when presenting a simplified development environment (for example, there is no "public static void main (String [] args"). Look at demos that particle systems show to get an idea of ​​how to model your individual cars.There is a Python version of this pyprocessing code call that follows most of the same simple programming idiom.

Here is my little "tesla" applet - move the mouse between two spherical electrodes.

+1
source

You do not tell the car where to go. In any case, this is due to its speed. If you look ahead (where there will now be several timestamps, and is there still a road?), You can see if you need to adjust the speed.

And the road is not an array; this is a matrix or bitmap. You cannot go so fast in the corner, or you are flying off the road.

It is always helpful to clearly articulate goals and frameworks first. In this case, you will think about the scale of the simulation (the physics involved) and the complexity of the car's movements (collisions, following bending roads, etc.).

I find that if you can clearly articulate your concept in plain English (or in my case in Dutch), writing code becomes much easier, almost trivially sometimes.

EDIT

For clarity, when I talk about speed, I'm talking about a vector that has both a magnitude (10MPH) and a direction. Your vectors will have 2 elements, x and y, if you also don't want planes, or want to model hills, etc. (You do not want the hills to force you to take gravity into account as well :) where az position and speed are used.

+6
source

Each car has a position, speed, direction / trajectory / destination. Based on this information and the relative position of other cars and (ultimately) the presence of "road signs", you can calculate the next position of each car and if the car will slow down or accelerate.

When you add a new car to the simulation, just set its initial position, speed and destination.

+2
source

You will also need to consider collision detection, not necessarily collisions between cars, but you will need a way to tell agents (AI) when it is advisable to slow down when next to other vehicles. You can do this using the bounding spheres around each car.

+2
source

I urge you to use my own project for this. It was called GarlicSim , it’s a simulation platform, and it’s great for the kind of simulation you have in mind. (By the way, just yesterday I made a big release, version 0.4).

Everything is Python, and it will give you a nice GUI.

If you are serious about this, I can help you write your simpack. If you want to do this, send an email to the mailing list.

+2
source

Simulator Theory - Queing Theory. I found a page on my alma mater’s course, which will show you some keywords that can help you - https://www.erasmus.cvut.cz/prospectus/FTS/11THO-E.html . The simulator itself will be "easier."

+2
source

First question: what is the scope of modeling?

You can do it as simple as one-dimensional cellular automata in discrete time or as complex as a full-fledged physical system (you can even simulate chemical reactions in an engine!) With sophisticated artificial intelligence and advanced photorealistic graphics and sound effects.

There are many possibilities between them. Think about what you can do and want to know.

0
source

Source: https://habr.com/ru/post/1308127/


All Articles