All Projects → Erfaniaa → map-coloring

Erfaniaa / map-coloring

Licence: GPL-3.0 license
Map coloring, using four colors

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to map-coloring

InterviewBit
Collection of solution for problems on InterviewBit
Stars: ✭ 77 (+83.33%)
Mutual labels:  backtracking
Data-Structures-Algorithms-Handbook
A series of important questions with solutions to crack the coding interview and ace it!
Stars: ✭ 30 (-28.57%)
Mutual labels:  backtracking
prolog-dry
A terse Prolog course
Stars: ✭ 32 (-23.81%)
Mutual labels:  backtracking
backtrex
Backtracking behaviour to solve discrete problems by brute force
Stars: ✭ 22 (-47.62%)
Mutual labels:  backtracking
egison-haskell
Template Haskell Implementation of Egison Pattern Matching
Stars: ✭ 31 (-26.19%)
Mutual labels:  backtracking
sweet-egison
Haskell library for non-deterministic pattern matching
Stars: ✭ 15 (-64.29%)
Mutual labels:  backtracking
backtrading-python-binance
Backtesting several trading strategy and rank them according their profit return.
Stars: ✭ 108 (+157.14%)
Mutual labels:  backtracking
problem-solving
No description or website provided.
Stars: ✭ 56 (+33.33%)
Mutual labels:  backtracking
DSA--GeeksForGeeks
DSA course solutions in C++ Jump to below directly for more problems
Stars: ✭ 47 (+11.9%)
Mutual labels:  backtracking
Sudoku-Solver
🎯 This Python-based Sudoku Solver utilizes the PyGame Library and Backtracking Algorithm to visualize and solve Sudoku puzzles efficiently. With its intuitive interface, users can input and interact with the Sudoku board, allowing for a seamless solving experience.
Stars: ✭ 51 (+21.43%)
Mutual labels:  backtracking
Algorithms
✨ a bunch of algorithms in a bunch of languages ✨
Stars: ✭ 55 (+30.95%)
Mutual labels:  backtracking
pytholog
Python library that enables using prolog syntax and logic programming in python
Stars: ✭ 59 (+40.48%)
Mutual labels:  backtracking
py-problems-solutions
Implementations of various problems using Python. Dynamic Programming, BackTracking & Sorting algorithms 💻
Stars: ✭ 20 (-52.38%)
Mutual labels:  backtracking

map-coloring

Map coloring, using four colors

This program gets a map image as an input and produces all possible valid colorings of that map using backtracking.

The input image background and borders should be white.

Some Basic Stuff to Know

  1. Map coloring
  2. Four color theorem

Algorithm

  1. Detecting all non-white regions (eg. provinces or states).
  2. Converting the input map to a simple planar graph: There will be a node for each region. Two nodes will be adjacent, if and only if their corresponding regions have a common border on the map.
  3. Using backtracking for coloring that graph (it's a recursive function that produces all valid colorings).
  4. Displaying all produced colorings on the given map.

Dependencies

Install numpy, matplotlib and opencv using pip.

pip install -r requirements.txt

Run

python3 map_coloring.py map_image_file_name

Samples

python3 map_coloring.py iran.jpg

The original image:

A part of the program output:

python3 map_coloring.py tehran_province.jpg

The original image:

A part of the program output:

python3 map_coloring.py usa.png

The original image:

A part of the program output:

Notes

It runs slowly on large images. It can be improved by changing the second part of its algorithm (about setting the graph edges). Some computational geometry knowledge about polygons may be needed for this part.

Any contributions are welcomed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].