The Python code tackles the map coloring problem, a classic graph theory challenge where the objective is to color the regions of a map in such a way that no two adjacent regions share the same color. The code employs a backtracking algorithm, which systematically explores different color assignments until a valid solution is discovered or all possibilities have been exhausted.
This project requires Python 3.12.1 or later. To set up the project:
-
Ensure Python 3.12.1 or a later version is installed on your system. You can download Python from python.org.
-
Clone or download the repository to your local machine.
git clone https://github.com/jaiswalchitransh/CSP-Map-coloring-using-Backtracking.git
-
Open the project in your preferred Python environment (e.g., IDE or terminal).
-
Modify the
map
,regions
, andcolors
variables in the main block of themap_coloring.py
script according to your map and color choices. -
Run the script (
csp_map_coloring.py
) and observe the output to see the valid coloring of regions.
Modify the map
, regions
, and colors
variables in the main block according to your map and color choices.
Run the script:
python csp_map_coloring.py
Observe the output to see the valid coloring of regions.
- Backtracking Algorithm: Utilizes a backtracking approach to systematically explore and find valid colorings for the map.
- is_valid Function: Checks whether a color assignment for a region is valid based on its neighbors.
- solve_map_coloring Function: Recursively attempts to find a valid coloring for the entire map.
- Main Block: Provides a sample map with regions and their neighbors, along with a list of available colors, demonstrating how the solver works.
I, Chitransh Jaiswal developed this Project Individually. I was responsible for all aspects of the project, including design, development, testing, and documentation. Contributions to improve the efficiency, readability, or functionality of the code are welcome. To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes.
- Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Create a new Pull Request.
Please ensure your contributions adhere to the coding standards and follow the existing style and structure.
Thank you for your interest in the CSP Map Coloring using Backtracking!