Given an image create a Directed Graph and Query it in a graph database.
On this try to query for :
A. All vertices you can reach in one step from A, D, E
B. All vertices you can reach in two steps from I
- SQLite3
- Python3.7
- Graphviz
- SQLite, version 3.31.0 or higher; get the latest source or precompiled binaries from the SQLite Download Page
- Python
- Graphviz for visualization
- install (download page, installation procedure for Windows); and
pip install graphviz
The database script provides convenience functions for atomic transactions to add, delete, connect, and search for nodes.
Any single node or path of nodes can also be depicted graphically by using the visualize
function within the database script to generate dot files, which in turn can be converted to images with Graphviz.
This is the Python implementation.
- Created a database object and initialized it by method initialize defined in database.py
- Created all the nodes given in an image.png i.e. A, B, C, D, E, F, G, H, I.
- Connect all the created node as per the image.png
- After connections, graph looks like this
- Created a function named as 'get_one_step_nodes' which uses 'get_connections_one_way' method from database.py to find all the connections of single node. 'get_one_step_nodes' takes any number of nodes as an argument and results one step connections from all the given nodes
- Created a function named as 'get_n_step_nodes' which uses 'get_one_step_nodes' method to find all the connections of single node recursively. 'get_n_step_nodes' takes two arguments 'a node' and 'number of steps to reach'
For full solution refer to notebook