Spring 06 Assignment 2: Constraint Satisfaction Problems

Similar documents
Spring 06 Assignment 2: Constraint Satisfaction Problems

Comp th February Due: 11:59pm, 25th February 2014

Section Marks Agents / 8. Search / 10. Games / 13. Logic / 15. Total / 46

UMBC 671 Midterm Exam 19 October 2009

Homework Assignment #1

INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! Revision 2 [2010-May-04] 1

CSE 573 Problem Set 1. Answers on 10/17/08

2359 (i.e. 11:59:00 pm) on 4/16/18 via Blackboard

CMPT 310 Assignment 1

ENGR170 Assignment Problem Solving with Recursion Dr Michael M. Marefat

CMPT 310 Assignment 1

CMSC 201 Fall 2018 Project 3 Sudoku

Solving Problems by Searching

: Principles of Automated Reasoning and Decision Making Midterm

CS 171, Intro to A.I. Midterm Exam Fall Quarter, 2016

CPSC 217 Assignment 3

G53CLP Constraint Logic Programming

CS 188 Fall Introduction to Artificial Intelligence Midterm 1

Written examination TIN175/DIT411, Introduction to Artificial Intelligence

GET OVERLAPPED! Author: Huang Yi. Forum thread:

ISudoku. Jonathon Makepeace Matthew Harris Jamie Sparrow Julian Hillebrand

10/5/2015. Constraint Satisfaction Problems. Example: Cryptarithmetic. Example: Map-coloring. Example: Map-coloring. Constraint Satisfaction Problems

isudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: Gavin Hillebrand Jamie Sparrow Jonathon Makepeace Matthew Harris

Games and Adversarial Search II

Tac Due: Sep. 26, 2012

Kenken For Teachers. Tom Davis January 8, Abstract

UN DOS TREZ Sudoku Competition. Puzzle Booklet for Preliminary Round. 19-Feb :45PM 75 minutes

Assignment 6 Play A Game: Minesweeper or Battleship!!! Due: Sunday, December 3rd, :59pm

CS188: Section Handout 1, Uninformed Search SOLUTIONS

COCI 2008/2009 Contest #3, 13 th December 2008 TASK PET KEMIJA CROSS MATRICA BST NAJKRACI

UNIVERSITY of PENNSYLVANIA CIS 391/521: Fundamentals of AI Midterm 1, Spring 2010

CS-171, Intro to A.I. Mid-term Exam Winter Quarter, 2015

Homework Assignment #2

CS 540-2: Introduction to Artificial Intelligence Homework Assignment #2. Assigned: Monday, February 6 Due: Saturday, February 18

Tiling Problems. This document supersedes the earlier notes posted about the tiling problem. 1 An Undecidable Problem about Tilings of the Plane

Constraint Satisfaction Problems: Formulation

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

On the Combination of Constraint Programming and Stochastic Search: The Sudoku Case

Serbian round at Logic Masters India

8. You Won t Want To Play Sudoku Again

Beyond Prolog: Constraint Logic Programming

An improved strategy for solving Sudoku by sparse optimization methods

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

Techniques for Generating Sudoku Instances

CSC 396 : Introduction to Artificial Intelligence

SUDOKU X. Samples Document. by Andrew Stuart. Moderate

Conversion Masters in IT (MIT) AI as Representation and Search. (Representation and Search Strategies) Lecture 002. Sandro Spina

Math 3012 Applied Combinatorics Lecture 2

Heuristics, and what to do if you don t know what to do. Carl Hultquist


Investigation of Algorithmic Solutions of Sudoku Puzzles

Yet Another Organized Move towards Solving Sudoku Puzzle

Grade 7/8 Math Circles Game Theory October 27/28, 2015

For slightly more detailed instructions on how to play, visit:

a b c d e f g h 1 a b c d e f g h C A B B A C C X X C C X X C C A B B A C Diagram 1-2 Square names

Game Playing in Prolog

Introduction to Computers and Engineering Problem Solving Spring 2012 Problem Set 10: Electrical Circuits Due: 12 noon, Friday May 11, 2012

2 Textual Input Language. 1.1 Notation. Project #2 2

Lab 1. CS 5233 Fall 2007 assigned August 22, 2007 Tom Bylander, Instructor due midnight, Sept. 26, 2007

CSE548, AMS542: Analysis of Algorithms, Fall 2016 Date: Sep 25. Homework #1. ( Due: Oct 10 ) Figure 1: The laser game.

It Stands to Reason: Developing Inductive and Deductive Habits of Mind

KenKen Strategies. Solution: To answer this, build the 6 6 table of values of the form ab 2 with a {1, 2, 3, 4, 5, 6}

Logic Masters India Presents. April 14 16, 2012 April 2012 Monthly Sudoku Test INSTRUCTION BOOKLET

Senior Math Circles February 10, 2010 Game Theory II

Indian Sudoku Championship 2015

Adverserial Search Chapter 5 minmax algorithm alpha-beta pruning TDDC17. Problems. Why Board Games?

1 Modified Othello. Assignment 2. Total marks: 100. Out: February 10 Due: March 5 at 14:30

Problem C The Stern-Brocot Number System Input: standard input Output: standard output

Chapter 4 Heuristics & Local Search

LMI SUDOKU TEST 7X JULY 2014 BY RICHARD STOLK

6.034 Quiz 2 20 October 2010

Heuristic Search with Pre-Computed Databases

CMPUT 657: Heuristic Search

We hope you enjoy the set. Good luck for the Indian Puzzle Championship! 3 A B C 4 H D 5 G F E 7 A B 8 H 9 G F

Logic Masters India Presents

Assignment 12 CSc 210 Fall 2017 Due December 6th, 8:00 pm MST

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

Eight Queens Puzzle Solution Using MATLAB EE2013 Project

Game-Playing & Adversarial Search

COMP5211 Lecture 3: Agents that Search

Assignment 2 (Part 1 of 2), University of Toronto, CSC384 - Intro to AI, Winter

Grade 6 Math Circles March 7/8, Magic and Latin Squares

If a word starts with a vowel, add yay on to the end of the word, e.g. engineering becomes engineeringyay

CSC242 Intro to AI Spring 2012 Project 2: Knowledge and Reasoning Handed out: Thu Mar 1 Due: Wed Mar 21 11:59pm

Python for education: the exact cover problem

CCO Commun. Comb. Optim.

Lecture 2: Problem Formulation

CS4700 Fall 2011: Foundations of Artificial Intelligence. Homework #2

Diagonal Vision LMI March Sudoku Test

Reading 14 : Counting

Introduction to Spring 2009 Artificial Intelligence Final Exam

Eleventh Annual Ohio Wesleyan University Programming Contest April 1, 2017 Rules: 1. There are six questions to be completed in four hours. 2.

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

Some results on Su Doku

1 Recursive Solvers. Computational Problem Solving Michael H. Goldwasser Saint Louis University Tuesday, 23 September 2014

Unit 12: Artificial Intelligence CS 101, Fall 2018

CSCE 2004 S19 Assignment 5. Halfway checkin: April 6, 2019, 11:59pm. Final version: Apr. 12, 2019, 11:59pm

Search then involves moving from state-to-state in the problem space to find a goal (or to terminate without finding a goal).

Project Connect Four (Version 1.1)

PROBLEM SET 2 Due: Friday, September 28. Reading: CLRS Chapter 5 & Appendix C; CLR Sections 6.1, 6.2, 6.3, & 6.6;

Transcription:

15-381 Spring 06 Assignment 2: Constraint Satisfaction Problems Questions to Vaibhav Mehta(vaibhav@cs.cmu.edu) Out: 2/07/06 Due: 2/21/06 Name: Andrew ID: Please turn in your answers on this assignment (extra copies can be obtained from the class web page). This written portion must be turned in at the beginning of class at 1:30pm on February 21. The code portion must be submitted electronically by 1:30pm on February 21. Please write your name and Andrew ID in the space provided on the first page, and write your Andrew ID in the space provided on each subsequent page. This is worth 5 points: if you do not write your name/andrew ID in every space provided, you will lose 5 points. Code submission. To submit your code, please copy all of the necessary files to the following directory: /afs/andrew.cmu.edu/course/15/381/hw2_submit_directory/yourandrewid replacing yourandrewid with your Andrew ID. You can use any of the following programming languages: C/C++, Java, Perl, Matlab, Lisp, ML/Ocaml, or Python. If you would like to use a language that is not on this list, please check with us first. All code will be tested on a Linux system, we will not accept Windows binaries. No matter what language you use, you must ensure that the code compiles and runs in the afs submission directory. Clearly document your program. Late policy. Both your written work and code are due at 1:30pm on 2/21. Submitting your work late will affect its score as follows: If you submit it after 1:30pm on 2/21 but before 1:30pm on 2/22, it will receive 90% of its score. If you submit it after 1:30pm on 2/22 but before 1:30pm on 2/23, it will receive 50% of its score. If you submit it after 1:30pm on 2/23, it will receive no score. Collaboration policy. You are to complete this assignment individually. However, you are encouraged to discuss the general algorithms and ideas in the class in order to help each other answer homework questions. You are also welcome to give each other examples that are not on the assignment in order to demonstrate how to solve problems. But we require you to: not explicitly tell each other the answers 1

Andrew ID: 2 not to copy answers not to allow your answers to be copied In those cases where you work with one or more other people on the general discussion of the assignment and surrounding topics, we ask that you specifically record on the assignment the names of the people you were in discussion with (or none if you did not talk with anyone else). This is worth five points: for each problem, space has been provided for you to either write people s names or none. If you leave any of these spaces blank, you will lose five points. This will help resolve the situation where a mistake in general discussion led to a replicated weird error among multiple solutions. This policy has been established in order to be fair to the rest of the students in the class. We will have a grading policy of watching for cheating and we will follow up if it is detected. For the programming part, you are supposed to write your own code for submission. 1 The N-queens Problem (10 points) References (names of people I talked with regarding this problem or none ): Consider the N-queens problem for N=4. As stated in class, this problem can be formulated as a CSP. Assume that the rows and columns are numbered from 1 to 4. 1.1 (5 points) Starting from a blank board, can 4-queens be solved with constraint propagation only without DFS? Why or why not. No. because initial choice (search) needs to be made because the constraints don t lead to assignment of any variable. 1.2 (5 points) Suppose that we assign the first queen (in column 1) to row 3. Can 4-queens be solved with constraint propagation only without DFS now? Why or why not. Yes. There is only one assignment of the remaining queens possible. The constraints lead to a fixed assignment of all the remaining variables. 2 Placing Tiles on Board(20 points) References (names of people I talked with regarding this problem or none ):

Andrew ID: 3 Example set of squares Example Solution Figure 1: Placing tiles on a board Suppose that we have N tiles that we want to place on a board so that no two tiles overlap. Suppose that the tiles are 2 units on the side (see Figure 1). Suppose that the board is made of squares connected to each other and not overlapping. The side of the squares is 1. The squares can be in any configuration that is a subset of a regular grid (see Figure 1). 2.1 (5 points) Formulate this problem as a CSP where the variables are the tiles (define domains and constraints). Specifically, assume that each square in the board has been assigned a co-ordinate (i, j). Different answers are possible. Any logically correct and slightly formal notation is fine. Variables : Let there be n tiles. Then, we form 2n variables. T 11, T 12, T 21, T 22,..., T n1, T n2. Each tile corresponds to two variables. Domain : 1 to m (m squares of the board) Constraints : For each k, T k1 and T k2 are adjacent squares on the board. Each variable is unique. i.e. For each k,l,i,j T ki T lj. 2.2 (5 points) Formulate this problem as a CSP where the variables are the squares (define domains and constraints). Different answers are possible. Any logically correct and slightly formal notation is fine. Variables : Let there be m squares on the board. Variables are s 1,..., s m Domain : 1 to n (it can be 1.. m, m n, since we do not require the index of tiles to be unique. ) Constraints : if s i == a, exactly one of the variable corresponding to the adjacent squares is also a and no other variable is a.

Andrew ID: 4 2.3 (10 points) Construct a configuration of 8 squares for which the CSP problem is tree-structured. What is the complexity of the problem in that case. Any linear placement of the squares would be a tree-structured CSP when using the squares as variables. Note that in this problem, we do not have the constraints that the index of one tile must be different with the indices of other tiles. Otherwise it will not be a tree-structured CSP. Complexity : O(n) 3 The Dinner Problem References (names of people I talked with regarding this problem or none ): Five friends (designated U,V,W,X, and Y) are planning to go to dinner but they don t all get along. Specifically, two of (V,W,and Y) will go to dinner if U goes to dinner. W never goes to dinner if either X or Y are there. V always goes to dinner with either X or Y. Assume that U goes to dinner. 3.1 (5 points) Formulate as a CSP problem. Variables : U, V, W, X, Y Domain : F,T Constraints : U (V W ) (V Y ) (W Y ) X Y W V (X Y ) 3.2 (5 points) After running constraint propagation once without DFS, do any of the domains change? Yes, V = 1, W = 0, Y = 1 are assigned. Note: in each step, constraint propagation needs to eliminate all the impossible values in the neighbor nodes until it cannot find any more. Since the definition does not state specifically what kind of methods should be used to find the impossible values, you should remove all of the impossible configurations as long as they can be found by one method. For example, in this problem, these impossible configurations can be found by 4-consistency checking rather than 2-consistency checking. Therefore the domains of the variables will be changed after the constraint propagation.

Andrew ID: 5 3.3 (5 points) Assume we use CP with DFS, does the search require backtracking? No, the search doesn t require backtracking. It is because after a CP step, only X would remain to be assigned. Both assignments of X to 0 or 1 are valid solutions. Hence, no backtracking required. 3.4 (5 points) What solution is found? U = 1, V = 1, W = 0, Y = 1, X = 0 or 1 4 The Soduko Puzzle References (names of people I talked with regarding this problem or none ): Sudoku is a logic-based placement puzzle, also known as Number Place in the United States. The aim of the puzzle is to enter a numerical digit from 1 to N in each cell of N N grid made up of sub-grids (called regions ), starting with various digits in some cells (the givens ). Each row, column, and region must contain only one instance of each numeral. Sudoku initially caught on in Japan in 1986 and gained international popularity in 2005. A number of variants of the Sudoku puzzle have been published. These variants differ in the size and configuration of the board, and the constraints enforced on the placement of numbers. To read more about the game, you can go to http://en.wikipedia.org/wiki/sudoku. To try out the game, you can go to http://www.sudoku.com. Solving Sudoku puzzles is a good pastime and is recommended by some teachers as an exercise in logical reasoning. However, completing a puzzle requires a lot of patience, logical ability and time!. You, as experts of finite domain constraint programming, will write a program to solve a general Sudoku puzzle. You will write a series of increasingly efficient approaches to solve a Sudoku puzzle. Here is a formal description of the general Sudoku puzzle. You are given a square grid containing N N cells. A region in the grid is of dimensions A B. Some cells already contain a number. You are supposed to fill the empty cells with numbers between 1 to N, such that each row, column and region contains the numbers 1 to N exactly once. The figures below show an example Sudoku puzzle alongwith its solution.

Andrew ID: 6 10 2 9 5 6 8 7 2 5 3 8 12 7 10 1 11 3 5 8 3 5 2 10 1 4 12 7 9 7 10 4 6 3 7 11 10 3 4 5 1 10 3 9 2 8 1 5 12 5 11 12 7 Sample Sudoku puzzle on 12 12 board with region size of 3 4 8 10 4 2 11 12 1 7 9 6 3 5 6 8 7 12 3 2 9 11 1 4 5 10 5 3 6 8 12 11 10 1 4 7 2 9 7 9 12 6 10 1 11 3 2 5 8 4 3 5 1 12 9 2 8 6 4 11 10 7 10 3 5 9 8 4 12 1 2 6 7 11 12 1 11 4 5 7 9 2 6 8 3 10 1 10 2 8 7 12 4 5 11 9 6 3 6 7 11 9 10 3 4 5 1 8 12 2 2 11 1 4 7 5 6 10 3 12 9 8 9 2 10 7 4 6 8 3 11 1 5 12 5 4 3 11 8 9 2 6 12 10 7 1 4.1 Input Format Solution to the sample puzzle given above Files describing a Sudoku puzzle will visually represent the board using a string of characters. The first line contains three numbers: length of the board (N), length of a region (A) and breadth of a region (B). The next N lines describe the N rows of the board. An empty cell is denoted by. Here is a sample input board corresponding to the sample puzzle: 12 3 4 _ 10 _ 2 3 5 _ 7 11 9 _ 2 10 3 4 5 9 5 _ 7 6 8 7 _ 10 _ 1 2 _ 4 12 10 5 _ 3 _ 9 3 _ 8 _ 2

Andrew ID: 7 12 7 9 _ 8 7 _ 10 _ 1 5 12 1 _ 5 11 10 1 11 3 4 5 8 _ 6 3 12 _ 7 _ 4.2 Output Format The output should consist of the completed Sudoku puzzle. You should output N lines each describing a row of the completed board. The individual entries should be separated by a single space. The last line gives a number indicating the number of partial assignments explored to reach the solution. Here is a sample output of the input shown above. 8 10 4 2 3 5 1 12 6 7 11 9 11 12 1 7 9 2 8 6 10 3 4 5 9 6 3 5 4 11 10 7 1 8 12 2 6 8 7 12 10 3 5 9 2 11 1 4 3 2 9 11 8 4 12 1 7 5 6 10 1 4 5 10 2 6 7 11 3 12 9 8 5 3 6 8 12 1 11 4 9 2 10 7 12 11 10 1 5 7 9 2 4 6 8 3 4 7 2 9 6 8 3 10 11 1 5 12 7 9 12 6 1 10 2 8 5 4 3 11 10 1 11 3 7 12 4 5 8 9 2 6 2 5 8 4 11 9 6 3 12 11 7 1 1244312 4.3 (10 points) Backtracking with consistency checking: Implement a backtracking DFS search algorithm to solve the Sudoku puzzle. Report the number of partial assignments explored and time taken before a solution is reached for the example puzzles A, B, C. Note that this naive approach might take too long for some of the puzzles. Puzzle A : 392888 (it is ok as long as the orders approximately match) Puzzle B : >40000000 (it is ok if you claim that it takes too long to run puzzle B/C) Puzzle C : 42368316 4.4 (10 points) Dynamic Variable Ordering: Modify the search step so that instead of picking the first uninstantiated variable, it examines the domains of all uninstantiated variables, and picks the first one with the minimum legal domain size. Report the number of partial assignments explored and time taken before a solution is reached for the example puzzles. Puzzle A : 470

Andrew ID: 8 Puzzle B : 891 Puzzle C : 16236 4.5 (10 points) Some more Constraints: At each step, apply the constraint that if a particular value can be assigned to only one variable in a row, column or a region, then the value should be assigned to that variable. Report the number of partial assignments explored and time taken before a solution is reached for the example puzzles. Puzzle A : 147 Puzzle B : 360 Puzzle C : 1448 4.6 (15 extra credit points) Try to improve the performance using constraint propagation, value ordering or other heuristics that you think would be suitable for the problem. Report the number of partial assignments explored and time taken before a solution is reached for the example puzzles. Puzzle A : Puzzle B : Puzzle C : 4.7 (20 points) You are supposed to submit code for each of the parts above. In addition to your code, please submit a one-page description of the various algorithms you have used and their implementation. Also comment on the benefits obtained by using various enhancements to the basic backtracking search. This must be attached to the rest of the part of your assignment. 5 Code Submission Details Program Output Your code should output the solved puzzle in the output format given earlier alongwith the number of partial assignments explored. We would be testing your code on the Andrew machines, so please ensure that your code compiles and runs successfully there. Documentation A README should be submitted with your code which specifies how to compile and run your code. Specifically the file must describe the command line arguments needed to run each of the algorithms implemented alongwith the example puzzles. Grading Grading will be based on the correctness of the solution output by the program. The order of the outputs generated by your code should be correct to get credit for a solution. All

Andrew ID: 9 solutions will be graded using the same set of puzzles. We would be using some extra puzzles for testing other than the ones provided with the homework. You are encouraged to try your code on puzzles other than the ones provided by us. The code submitted by you should be written by you, and not copied from any other source.