Code Monkey home page Code Monkey logo

road-network's Introduction

Python 2.7 License: MIT

QuadTree model for generating random road networks

Generate a sample road network

  • clone repo and then run the following
cd road-network/rng
python network_gen.py <plane size> <number of nodes>

output

Generating road network...
*** Tree Stats ***
...
generating squares...
writing data to files...
# of edges: 1099
generate road network image at: /path/to/your/dir/road-network/rand-quad-road-network.png
node list at: /path/to/your/dir/road-network/node-list
edge list at: /path/to/your/dir/road-network/edge-list
Done

About the model

ScreenShot

QuadTree Model

Eisenstat introduces random road network generation using QuadTree data structure in [Eis10 ]. This project implements that model in python and can be used to generate random road network of varying sizes.

QuadTree implementation

The main component of the model is the Quadtree data structure. Quadtree is a tree data structure similar to a binary tree with the difference that each node could have up to four children instead of two. In this implementation each node either has four children or no children. The first node in the tree forms the initial plane. Each node in the tree represents a square and its four children represent the division of the square into four quadrants. Squares are added to the tree by recursively dividing squares into four quadrants.

This image from Wikipedia shows how an image is represented using a QuadTree: quadImage

QuadTree Wikipedia

Road network and coordinate generation

Each node in the tree represents a square in a plane. For a given number n of nodes, the squares are randomly divided into four quadrants, i.e. add four children to leaf nodes in the QuadTree. Each edge of the square forms a road connecting two points. The Point class represents a point in the 2 dimensional space. The Point class implements Python’s standard comparison, hash methods and also a method to calculate euclidean distance to another point in the same plane. Once the desired number of squares are generated, the tree is recursively traversed to generate Points based on the box formed by the squares in the tree. From these Points a list of edges are generated and the euclidean distance between them are calculated. Additionally, there are utility methods to perform Breadth First Search, add nodes to specific nodes in the tree and print statistics. To visualize the generated road network there is a utility to plot the network using Matplotlib

License: MIT License

[Eis10] David Eisenstat. “Random road networks: the quadtree model”. In: CoRR abs/1008.4916 (2010). url: http://arxiv.org/abs/1008.4916.

road-network's People

Contributors

arun1729 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.