Code Monkey home page Code Monkey logo

coloring-map-with-csp's Introduction

Coloring-Map-with-CSP

We were given a list of countries in South America and the colors we can use. First we needed to keep the border neighbors of each of the countries in South America in a data structure. I created a dictionary named graph and kept the country-neighbor key-pairs here. According to our algorithm, first of all, we need to color the country with the most neighbors. In other words, I thought that we should sort the countries according to the number of neighbors, so I wrote a method called sortCountriesByNeighbors. Then I have a method called colorTheCountry. In this method, the countries are colored using back-tracking. I have a counter called 'counter'. Initially, I initialize its value from 0, and if the value of the counter is equal to the color value, there is no other color we can try. In such a case there is no solution so it will print 'unsolved problem' to the screen. Apart from these, I have a method called isColorCorrect. In this method, I checked whether the coloring is correct. If one of the neighbors of a country has the same color as the country, it means that we have made the wrong coloring here. By calling this method called isColorCorrect within the colorTheCountry method, our operations continue according to whether the coloring is correct or not.

Variables: X={"Argentina", "Bolivia", "Brazil", "Chile", "Colombia", "Ecuador", "Falkland Islands", "Guyana", "Paraguay","Peru", "Suriname", "Uruguay", "Venezuela"}

Domains: D={"blue", "green", "red", "yellow"}

Constraints: adjacent regions must have different colors.
C={ ( "Argentina" != "Bolivia", "Brazil", "Chile", "Paraguay", "Uruguay"), ("Bolivia" != "Argentina", "Brazil", "Chile", "Paraguay", "Peru"), ("Brazil" != "Argentina", "Bolivia", "Colombia", "Guyana", "Paraguay", "Peru", "Suriname", "Uruguay", "Venezuela"), ("Chile" != " Argentina", "Bolivia", "Peru"), ("Colombia" !="Brazil", "Ecuador", "Peru", "Venezuela"), ("Ecuador" != "Colombia", "Bolivia", "Peru"), ("Guyana" != "Brazil", "Suriname", "Venezuela"), ("Paraguay" !="Argentina", "Bolivia", "Brazil"), ("Peru" != "Bolivia", "Brazil", "Chile", "Colombia", "Ecuador"), ("Suriname" != "Brazil", "Guyana"), ("Uruguay" !="Argentina", "Brazil"), ("Venezuela" != "Brazil", "Colombia", "Guyana") }

coloring-map-with-csp's People

Contributors

isinsuarici avatar

Stargazers

 avatar  avatar  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.