Traffic simulation : directed graph including specific rules

  • Context: Undergrad 
  • Thread starter Thread starter Guitz
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the use of directed graphs for traffic simulation, specifically focusing on implementing rules for vehicle movement, such as prohibiting U-turns at certain nodes while allowing them at others. Participants explore modifications to the graph data structure and algorithms like A* or Dijkstra's to accommodate these rules.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant suggests modifying the search algorithm to exclude the previous node from future traversals unless it is the only option available.
  • Another proposes generating a new directed graph from the original undirected graph to represent valid travel directions through intersections and dead ends.
  • A different viewpoint mentions the possibility of transforming nodes with multiple edges into two nodes, each with directed edges reflecting the relevant travel directions.
  • Some participants express difficulty in finding existing code solutions online for implementing these concepts.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a single approach to modifying the graph or algorithm. Multiple competing views and suggestions are presented without resolution.

Contextual Notes

The discussion includes various assumptions about the graph structure and the specific rules for vehicle movement, which may not be fully articulated. There are also unresolved questions regarding the implementation of the proposed modifications.

Guitz
Messages
22
Reaction score
8
Hi all,

I'm trying to use a directed graph for a traffic simulation program.

This is an example of a simplified graph :

graph.gif


The red triangle is the position and orientation of the car. The green circle is the destination node.

I wish to prohibit a U-turn on a bend and a crossroads but I authorize it on a dead end (node 4).

The array of nodes (3, 6, 8) is therefore prohibited.
Likewise (3, 1, 3, 6, 8) is forbidden.
On the other hand, (3, 1, 2, 3, 6, 8) and (3, 4, 3, 6, 8) are allowed. The latter being the shortest path.

How please modify the data structure of my graph and the A* (or Dijkstra's) algorithm to achieve my goals?

Thanks
 
Last edited:
Mathematics news on Phys.org
Your search algorithm must exclude the previous node from the nodes to traverse next, unless its the only option.

If a search algorithm marks nodes as allread visted (to abort subsequent longer paths), then you must refine this flag to encode from which node it has already been entered.

Did you really not find any code online for this?
 
Last edited:
I would probably also consider changing the algorithm to adjust for the need at hand, but in case you are somehow required to use a "standard" algorithm unchanged you can perhaps consider to generate a new directed graph from your undirected graph such that the two travel directions on each edge is transformed into a node and these nodes are then connected with directed edges representing valid ways through an intersection or end-point.

This should be possible to do in a fairly mechanic way. For example, the sub-graph from your nodes 1, 2 and 3 you would add the nodes and transitions (1-2) -> (2-3) -> (3-1) and (3-2) -> (2-1) -> (1-3), that is two isolated cycles. Adding your node 4 to this would then add nodes (3-4) and (4-3) along with the transitions {(1-3), (2-3)} -> (3-4) -> (4-3) -> {(3-1), (3-2)}, and so forth.

Old suggestion that was only half baked:
Perhaps it is possible to transform your problem into a directed graph where your original nodes with more than one edge is replaced by two nodes, each with directed edges in relevant directions?
 
Last edited:
  • Like
Likes   Reactions: Guitz and FactChecker
thanks a lot for your replies
 
  • Like
Likes   Reactions: berkeman
A.T. said:
Did you really not find any code online for this?
Unfortunately no
 
  • Like
Likes   Reactions: Guitz

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
4K
Replies
24
Views
8K
  • · Replies 12 ·
Replies
12
Views
7K