This Python script provides functionality to represent a country's geographic structure using an adjacency matrix, where states (or districts within states) are represented as nodes, and edges between them signify shared borders. The script is accompanied by an example implementation using India's states as nodes.
-
Convert adjacency matrix to a graph representation: The script allows you to convert an adjacency matrix into a graph representation, where nodes represent states (or districts) and edges represent shared borders.
-
Visualization of the graph: You can visualize the graph using the provided function, making it easier to understand the geographical relationships between states.
-
Mapping of node numbers to state names: The script includes functionality to map node numbers to state names (or states and their districts), making it easier to interpret the graph representation.
-
Flexibility with adjacency matrix: The script is designed to handle various formats of the adjacency matrix, including the lower half matrix. For example, providing only the lower half of the matrix also works, as the script intelligently converts it to the complete adjacency matrix.
# Example adjacency matrix for India (lower half only)
adj_matrix = [
[0],
[1, 0]
]
# Example mapping of node numbers to state names
state_mapping = {
0: "Punjab",
1: "Haryana"
}
-
Installation: Clone the repository to your local machine.
git clone https://github.com/your_username/adjacency-matrix-graph.git
-
Usage: Use the provided functions to convert an adjacency matrix into a graph representation and visualize it. Ensure that your adjacency matrix accurately represents the relationships between states (or districts).
-
Contributing: Feel free to contribute to this project by suggesting improvements, reporting bugs, or submitting pull requests.
- Ensure that the mapping dictionary accurately reflects the correspondence between node numbers and state names.