CS 171: Intro to AI Discussion Week 2 Jan 15 th 2016.

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Constraint Satisfaction Problems Russell and Norvig: Chapter
Constraint Satisfaction Problems
This lecture topic (two lectures) Chapter 6.1 – 6.4, except
This lecture: CSP Introduction and Backtracking Search
Lecture 11 Last Time: Local Search, Constraint Satisfaction Problems Today: More on CSPs.
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
This lecture topic (two lectures) Chapter 6.1 – 6.4, except 6.3.3
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
Constraint Satisfaction problems (CSP)
Review: Constraint Satisfaction Problems How is a CSP defined? How do we solve CSPs?
Constraint Satisfaction Problems
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
Constraint Satisfaction Problems
Constraint Satisfaction
CAP 492 Course Dr. Souham Meshoul 1 CONSTRAINT SATISFACTION PROBLEMS Chapter 5.
A game of logic where the player must assign the numbers 1..9 to cells on a 9x9 grid. The placement of the numbers must be such that every number must.
Constraint Satisfaction Problem Solving Chapter 5.
Chapter 5 Outline Formal definition of CSP CSP Examples
Constraint Satisfaction Problems
Constraint Satisfaction Problems
Constraint Satisfaction Problems
ISC 4322/6300 – GAM 4322 Artificial Intelligence Lecture 4 Constraint Satisfaction Problems Instructor: Alireza Tavakkoli September 17, 2009 University.
1 Constraint Satisfaction Problems Slides by Prof WELLING.
Constraint Satisfaction Problems (CSPs) Chapter 6.1 – 6.4, except
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
CS 484 – Artificial Intelligence1 Announcements Homework 2 due today Lab 1 due Thursday, 9/20 Homework 3 has been posted Autumn – Current Event Tuesday.
Constraint Satisfaction Problems Chapter 6. Review Agent, Environment, State Agent as search problem Uninformed search strategies Informed (heuristic.
Constraint Satisfaction Read Chapter 5. Model Finite set of variables: X1,…Xn Variable Xi has values in domain Di. Constraints C1…Cm. A constraint specifies.
Chapter 5 Section 1 – 3 1.  Constraint Satisfaction Problems (CSP)  Backtracking search for CSPs  Local search for CSPs 2.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Hande ÇAKIN IES 503 TERM PROJECT CONSTRAINT SATISFACTION PROBLEMS.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
1 Chapter 5 Constraint Satisfaction Problems. 2 Outlines  Constraint Satisfaction Problems  Backtracking Search for CSPs  Local Search for CSP  The.
CSC 8520 Spring Paula Matuszek CS 8520: Artificial Intelligence Search 3: Constraint Satisfaction Problems Paula Matuszek Spring, 2013.
Chapter 5 Constraint Satisfaction Problems
Review Test1. Robotics & Future Technology Future of Intelligent Systems / Ray Kurzweil futurist Ray Kurzweil / A Long Bet A Long Bet / Robot Soccer.
Maintaining Arc Consistency (MAC) MAC is the same as Back-tracking, but with calls to AC-3 interleaved... function Backtracking-Search(csp) returns.
An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3 Grand Challenge:
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
Constraint Satisfaction Problems University of Berkeley, USA
Constraint Satisfaction Problems Chapter 6. Outline CSP? Backtracking for CSP Local search for CSPs Problem structure and decomposition.
Arc Consistency CPSC 322 – CSP 3 Textbook § 4.5 February 2, 2011.
1. 2 Outline of Ch 4 Best-first search Greedy best-first search A * search Heuristics Functions Local search algorithms Hill-climbing search Simulated.
Monster (“Mega”) Sudoku
Fahiem Bacchus, University of Toronto CSC384: Intro to Artificial Intelligence  Backtracking Search (CSPs)  Chapter 5  5.3 talks about local search.
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
EXAMPLE: MAP COLORING. Example: Map coloring Variables — WA, NT, Q, NSW, V, SA, T Domains — D i ={red,green,blue} Constraints — adjacent regions must.
Domain Splitting, Local Search CPSC 322 – CSP 4 Textbook §4.6, §4.8 February 4, 2011.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
ARTIFICIAL INTELLIGENCE (CS 461D) Dr. Abeer Mahmoud Computer science Department Princess Nora University Faculty of Computer & Information Systems.
CS 561, Session 8 1 This time: constraint satisfaction - Constraint Satisfaction Problems (CSP) - Backtracking search for CSPs - Local search for CSPs.
Monster (“Mega”) Sudoku
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Satisfaction Problems
Artificial Intelligence
Constraints and Search
Constraint satisfaction problems
Constraint Satisfaction Problems. A Quick Overview
CS-171 Discussion Week3.
Constraint Satisfaction
CS 8520: Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems (CSP)
Presentation transcript:

CS 171: Intro to AI Discussion Week 2 Jan 15 th 2016

Agenda Project Information (15 min) –Team Formation by Today 23:59pm –Project Problem Generator by Sun., 24 Jan., 11:59pm Monster Sudoku Example Generator Specification CSP Mini Sudoku Example (30 min) –Search : Backtracking –Heuristic : Variable (MRV/DH) Value (LCV) –Forward Checking –Arc Consistency Quiz 1 (5 min)

Project Information Team Formation – Monster Sudoku Example Generator Specification

Examples p = 3, q = 4, N = 3x4 = 12p = 4, q = 4, N = 4x4 = 16 P=3 q block cell token N x N grid

Parameters N –Number of tokens –Length of the N x N grid –Number of cells in each block –N = P * Q P –Number of blocks fit horizontally –Number of rows in each block Q –Number of blocks fit vertically –Number of columns in each block M –Number of cells initially filled Tokens –1,2,…,8,9,A,B,C,…,Z up to 35 tokens (35 X 35 grid) –0 is reserved for representing BLANK cell

Generator Specification Generator N, P, Q, M (Initially N x N grid filled with 0) Check if N = P*Q, M <= N*N (Don’t miss checking input params) Randomly choose M cells Replace 0 with Randomly chosen tokens in [1..N] such that the generated problem is consistent, i.e., initial assignments should not be in conflict positions It is okay to generate a problem with unique, multiple, no solution. How to generate consistent problems? Pickup a cell randomly Assign a random token to it Check constraints and if it doesn’t violate them pickup next cell If the random token was in conflict to other cells, try other tokens until success If there is no possible choice, then discard everything and start from the beginning! Monster Sudoku Problem

Generator Specification Generator $ you will submit single executable (and other stuffs..) test it at openlab.ics.uci.edu with the test script before submission Input file Output file M N P Q 1 line, 4 numbers are separated by space e.g <= 6*6 and 6 = 2*3 Output fileInput file 6 2 3\n \n \n … \n N+1 lines, First line: N P Q Next N lines Show each line in the grid

Submission EEE Drop box –One of your team member should Submit “zipped” file LastName_yourUCI_ID#_yourTeamName.zip LEE_ _MyTeamName.zip –If your partner has deposited your submission, please deposit a text file LastName_yourUCI_ID#_yourTeamName.txt LEE_ _MyTeamName.txt Lastname_UCI#ID_teamName –src: source files & other necessary files for producing the executable –bin: executable (recommend static link) –doc: report Finally, you will analyze its performance and write up a report according to a report template

Mini Sudoku Example M = 20 N = 6 P = 2 Q = 3 P=2

Backtracking search (Figure 6.5) function BACKTRACKING-SEARCH(csp) return a solution or failure return RECURSIVE-BACKTRACKING({}, csp) function RECURSIVE-BACKTRACKING(assignment, csp) return a solution or failure if assignment is complete then return assignment var  SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp) for each value in ORDER-DOMAIN-VALUES(var, assignment, csp) do if value is consistent with assignment according to CONSTRAINTS[csp] then add {var=value} to assignment result  RECURSIVE-BACTRACKING(assignment, csp) if result  failure then return result remove {var=value} from assignment return failure

Search Heuristic Variable Selection –Minimum Remaining Value Select Variable with smallest domain size –Degree heuristic Select Variable that involves in the largest number of constraints on unassigned variables Value Selection –For each value, count number of removed values in other variables that are removed by current assignment –Select Value with the smallest count

Inference Forward Checking –While Search (after assigning value to Xi) Enforce Arc Consistency on { (Xj, Xi) } neighbors Arc Consistency –Before Search Global Arc Consistency  No need to do FC –While Search (after assigning value to Xi) Maintaining Arc Consistency { (Xj, Xi) } propagate!

1x13X2X2 56 4x36x4x5X6X6 x71x8x932 6Z125Z24 Z3Z4534Z5 34z62Z75 Variables X1~X9, Z1 ~ Z7 Domains {1,2,3,4,5,6} Let assigned cells represent variables that are allowed to have only 1 value Let’s call them B1=1, B2=3, B3=4, B4=6 Y1=5, Y2=6 R1=1, R2=6, R3=2 P1=3,P2=2, P3=5, P4-4 G1=5,G2=3, G3=4 O1=3, O2=4, O3=2 O4=5 Constraints AllDiff per Block 6 Blocks AllDiff per Row 6 Rows AllDiff per Column 6 Columns For example, Row1 AllDiff (B1, X1, B2, X2, Y1, Y2) is a set of constraints B1 != X1 B1 != B2 B1 != X2 B1 != Y1 B1 != Y2 X1 != B2 X1 != X2 X1 != Y1 X1 != Y2 B2 != X2 B2 != Y1 B2 != Y2 X2 != Y1 X2 != Y2 Y1 != Y2 We converted 1 AllDiff constraint into 15 binary constarints ! The Alldifferent Constraint: A Survey ∗

1x13X2X2 56 4x36x4x5X6X6 x71x8x932 6Y1Y1 25Y2Y2 4 y3y4534y5 34y62y75 Start Select Variable MRV? Assigned cells can take ONLY ONE value There are 20 such variables. DH? Same for all 20 variables Pick up B1 = 1 (upper left) Select Value, Only 1 Forward Checking Reduce domains X1 = {2,3,4,5,6} X2 = {2,3,4,5,6} X3 = {2,3,4,5,6} Check all constraints  Okay If we convert all AllDiff constraints as Binary constraints, We have (3*6) * 15 = 270 constraints

1x13X2X2 56 4x36x4x5X6X6 x71x8x932 6Y1Y1 25Y2Y2 4 y3y4534y5 34y62y75 B1 = 1 Select Variable There are 19 pre-assigned cells DH? Any pre-assigned variable that are not related to B1 like R1 Select Value? Only 1 Forward Checking X7 = {2,3,4,5,6} X8 = {2,3,4,5,6} X9 = {2,3,4,5,6} Y4 = {2,3,4,5,6} X1 = {2,3,4,5,6} X2 = {2,3,4,5,6} X3 = {2,3,4,5,6}

1x13X2X2 56 4x36x4x5X6X6 x71x8x932 6Y1Y1 25Y2Y2 4 y3y4534y5 34y62y75 B1 = 1 R1 =1 Select Variable There are 18 pre-assigned cells DH? Any pre-assigned variable that are not in blue/ red block and away from previously selected rows/columns like O1 Select Value? Only 3 Forward Checking Y3 = {1,2,4,5,6} Y4 = {2,4,5,6} Y5 = {1,2,4,5,6} Y7 = {1,2,4,5,6} X9 = {2,4,5,6} X4 = {1,2,4,5,6} X2 = {2,4,5,6} X1 = {2,3,4,5,6} X2 = {2,3,4,5,6} X3 = {2,3,4,5,6} X7 = {2,3,4,5,6} X8 = {2,3,4,5,6} X9 = {2,3,4,5,6} Y4 = {2,3,4,5,6}

1x13X2X2 56 4x36x4x5X6X6 x71x8x932 6Y1Y1 25Y2Y2 4 y3y4534y5 34y62y75 B1 = 1, R1 =1, O1 = 3 Select Variable By MRV we will select all pre-assigned cells At each iteration, we apply Forward Checking Then, domains for not-assigned variables become X1 = {2} X2 = {4} X3 = {2,5} X4 = {1} X5= {1,2} X6= {1,3} X7 = {5} X8 = {4} X9 = {6} Y1 = {3} Y2 = {1} Y3 = {2} Y4 = {2,6} Y5 = {1} Y6 = {1} Y7 = {1,6}

1x13X2X2 56 4x36x4x5X6X6 x71x8x932 6Y1Y1 25Y2Y2 4 y3y4534y5 34y62y75 Select Variable MRV? X1, X2, X4, X7, X8, X9, Y1, Y2, Y3, Y5, Y6 Take only 1 value DH? (w.r.t. unassigned variable?) X1 = x3, x2, y1, y4 X2 = x1, x4, x5, x6, x9 X4 = x2, x5, x6, x3, x9 X7 = y1, x8, y3, x9 X8 = x7, x9, y6 X9 = x7, x8, y2, x2, x4 Y1 = x7, x8, x1, x3, y4 Y2 = x9, x5, y7, y1 Y3 = y4, y6, x7, y5 Y5 = x6, y3, y4, y7 Y6 = y3, y4, y7, x8 Y7 = y5, y6, y2, x5 X2, X4, X9, Y1 tie! Select one of them like Y1 = 3 X1 = {2} X2 = {4} X3 = {2,5} X4 = {1} X5= {1,2} X6= {1,3} X7 = {5} X8 = {4} X9 = {6} Y1 = {3} Y2 = {1} Y3 = {2} Y4 = {2,6} Y5 = {1} Y6 = {1} Y7 = {1,6}

1x13 X2 56 4x36x4x5X6X6 x71x8x932 6 Y1= 3 25Y2Y2 4 y3y4534y5 34y62y75 Y1 =3 After assignment, let’s apply Maintaining Arc Consistency Algorithm Put binary constraints (X1, Y1) (X3, Y1) (X7, Y1) (X8, Y1) (Y4, Y1) Into Queue All 5 binary constraints are consistent No Change X1 = {2} X2 = {4} X3 = {2,5} X4 = {1} X5= {1,2} X6= {1,3} X7 = {5} X8 = {4} X9 = {6} Y1 = {3} Y2 = {1} Y3 = {2} Y4 = {2,6} Y5 = {1} Y6 = {1} Y7 = {1,6}

1x13 X2 56 4x36x4x5X6X6 x71x8x932 6 Y1= 3 25Y2Y2 4 y3y4534y5 34y62y75 Y1 =3 After assignment, let’s apply If we applied AC algorithm Put all binary constraints X1-X2 X2-X1 X1-X3, X3-X1 X1-Y4, Y4-X1 X7-X8, X8-X7 X7-X9, X9-X7 X7-Y3, Y3-X7 X8-X9, X9-X8 X8-Y6, Y6-X8 … Into Queue As a result, We solve the problem X1 = {2} X2 = {4} X3 = {2,5} X4 = {1} X5= {1,2} X6= {1,3} X7 = {5} X8 = {4} X9 = {6} Y1 = {3} Y2 = {1} Y3 = {2} Y4 = {2,6} Y5 = {1} Y6 = {1} Y7 = {1,6}

1x13 X2 56 4x36x4x5X6X6 x71x8x932 6 Y1= 3 25Y2Y2 4 y3y4534y5 34y62y75 Y1 =3 Select Variable? MRV? All except X3, X5, X6, Y4, Y7 DH? X1=3 X2=5 X4=5 X7=3 X8=3 X9=5 Y2=3 Y3=4 Y5=3 Y6=4 Select X4 or X9 Select X9 What Value? X9 = 6 X1 = {2} X2 = {4} X3 = {2,5} X4 = {1} X5= {1,2} X6= {1,3} X7 = {5} X8 = {4} X9 = {6} Y1 = {3} Y2 = {1} Y3 = {2} Y4 = {2,6} Y5 = {1} Y6 = {1} Y7 = {1,6}

1x13 X2 56 4x36x4x5X6X6 x71x8 X9 = Y1= 3 25Y2Y2 4 y3y4534y5 34y62y75 Y1 =3, X9=6 MRV/ DH will Select X1, X2, X4, X7, X8, Y2, Y3, Y5, Y6 Let’s not apply FC X1 = {2} X2 = {4} X3 = {2,5} X4 = {1} X5= {1,2} X6= {1,3} X7 = {5} X8 = {4} X9 = {6} Y1 = {3} Y2 = {1} Y3 = {2} Y4 = {2,6} Y5 = {1} Y6 = {1} Y7 = {1,6}

1 X1= 2 3 X2= X3 =5 6 X4= 1 x5 X6 =3 X7 =5 1 X8 =4 X9 = Y1= 3 25 Y2 =1 4 Y3 =2 y4534 Y5 =1 34 Y6 =1 2Y7Y7 5 What Variable? MRV X3, X5, X6, Y4, Y7 DH? X3 = 3 X5 = 3 X6 = 2 Y4 = 1 Y7 = 1 Choose X3 or X5 If we choose X3, What Value to choose? LCV? 2: inconsistent 5: Only possible value X3= 5 X3 = {2,5} X5= {1,2} X6= {1,3} Y4 = {2,6} Y7 = {1,6}

Quiz 1