GithubHelp home page GithubHelp logo

gwu-ai-proj2-coloring's Introduction

Project 2 CSP

Author: Abbas Aliyev

Link to the project

Introduction

In this project, we are going to solve a constraint satisfaction problem (CSP) using the backtracking algorithm. I am going to implement Minimum Remaining Values (MRV) and Least Constraining Value (LCV) heuristics to improve the performance of the backtracking algorithm. On top of that I will implement forward checking and arc consistency to further improve the performance of the backtracking algorithm.

Problem

The problem is to assign a color to each region in a map such that no two adjacent regions have the same color. The map is represented as a graph, where each region is a node and each edge represents an adjacency relationship between two regions. The graph is given as an adjacency list. The colors are represented as integers. The goal is to find a valid coloring of the map, if one exists.

Implementation

The project is implemented in Python. The main file is main.py, which contains the main function that reads the input file, constructs the graph, and calls the backtracking algorithm to solve the CSP. For the graph representation I am using networkx library. Coloring algorithm is implemented in Coloring.py file. The file contains the implementation of the backtracking algorithm, as well as the heuristics and consistency checks. The input file is given as a command line argument to the main function. The input file is a text file that contains the graph in the following format:

#Any comments must start with a hash symbol
#The first line contains the number of colors
colors = 3
#The rest of the file contains the graph as an edge list
#Each line contains two integers, which represent the indices of the two nodes that are connected by an edge
0 1
0 2
1 2

The output of the program is the coloring of the graph, if one exists. The output is printed to the console in the following format:

0:1
1:2
2:0

Each line contains a node index and the color assigned to that node. The output is printed in the order of the node indices.

Usage

To run the program, you need to have Python installed on your machine. You can run the program by executing the following command in the terminal:

python main.py input.txt

Where input.txt is the input file that contains the graph. The output will be printed to the console.

For the testing purposes, I have included a few input files. You can use these files to test the program.

Conclusion

In this project, I have implemented a backtracking algorithm to solve a constraint satisfaction problem. I have also implemented heuristics and consistency checks to improve the performance of the backtracking algorithm. The program is able to solve the graph coloring problem for small graphs. However, the performance of the program may degrade for larger graphs. Interestingly, I have noticed that the largest improvement by of the speed of the algorithm is happened when I implemented forward checking functionality. Everything else didn't provide significant improvements or even slowed down the execution. In the future, I would like to improve the performance of the program by implementing more advanced heuristics and consistency checks. I would also like to implement the program in a more efficient language, such as C++.

gwu-ai-proj2-coloring's People

Contributors

capta1n-n9m0 avatar

Watchers

 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.