Algorithmically generated city layouts.

At the start of the simulation, the City is seeded with a major road node at a geographically central point. New nodes and edges are gradually added to represent roads and junctions. In the city, there are two types of road - major roads and minor roads. Cycles of major roads form "Quarters" with each Quarter having an assigned type of property (commercial, residential or industrial) and an associated StreetPattern that affects the geometric properties or the random road expansion (e.g. road length and angle). Once a Quarter is established (a new cycle in the major road network is detected) it is "filled" with minor road expansion. If no Quarters are available for minor road expansion, the major road network is expanded until new Quarters are created.

The main simulation code consists of a road expansion loop then grows the city step by step, picking an existing node in the road network and creating and testing a proposed random road expansion.

  • Unexpanded Quarters are searched for.
  • If an empty/unexpanded Quarter is found, a node is selected from the major road boundary.
  • A RoadProposal object is created to hold a proposed continuation of a road from that node. If the node is already connected to two other nodes, then a 3-way junction will be proposed. The maximum number of roads that can lead from a single node is 4.
  • A proposed endpoint position for the road is stored on the RoadProposal object. The length and angle of the road can be affected by the StreetPattern chosen for the Quarter.
  • Given the RoadProposal with a proposed target end point position, an "adapt" step may alter the position. For example, to follow terrain, avoiding obstacles, or to propose the creation of a junction if the road proposal intersects an existing road. The RoadProposal endpoint is then updated.
  • The legality of the RoadProposal is then checked. For example, a RoadProposal that ends outside of the Quarter will be rejected. A RoadProposal endpoint that lies too close to an existing 4-way junction will also be rejected. The creation of a very tight angle junction may also lead to rejection. Rejected RoadProposals are discarded.
  • If the RoadProposal is not rejected, the proposal is "built" and a new Road object is added to the city connected the source with a new or existing target node.

Traffic is periodically simulated between residentially and commercial areas of the city. Roads may remain candidates until their traffic usage passes some threshold, after-which they can be marked as "built" and will be permanently added to the resulting city layout.