The following post is a short description of an algorithm to generate a semirealistic city road network:
The algorithm goes as follows:
- Start with a grid where each edge has a high movement cost.
- Select two points on the map using a normal distribution. The normal distribution will model a higher activity center and less active outer areas.
- Run a pathfinding algorithm to find the fastest route between the two points.
- Reduce the movement cost along all edges of the path. If the cost has reached the minimum, increase it by a big amount. This will ensure roads won't get too busy.
- Repeat until you have a convincing road network.
Since the pathfinding algorithm will prefer cheaper routes, routes that have been used already will get bigger and bigger over time.
Here is a javascript version:
(the pathfinding used is https://github.com/bgrins/javascript-astar)