G53CLP Constraint Logic Programming

Similar documents
Constraint Satisfaction Problems: Formulation

Spring 06 Assignment 2: Constraint Satisfaction Problems

Spring 06 Assignment 2: Constraint Satisfaction Problems

CS 730/730W/830: Intro AI

Beyond Prolog: Constraint Logic Programming

Eight Queens Puzzle Solution Using MATLAB EE2013 Project

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

Solution Algorithm to the Sam Loyd (n 2 1) Puzzle

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


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

More Recursion: NQueens

N-Queens Problem. Latin Squares Duncan Prince, Tamara Gomez February

Lecture 2: Problem Formulation

Python for Education: The Exact Cover Problem

arxiv: v1 [cs.ai] 25 Jul 2012

Complete and Incomplete Algorithms for the Queen Graph Coloring Problem

Writing and debugging programs

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

Tutorial: Constraint-Based Local Search

1 Introduction. 2 An Easy Start. KenKen. Charlotte Teachers Institute, 2015

Sudoku 16 X 16: 100 Sudoku Puzzles Volume 2 By David Badger READ ONLINE

Modelling Equidistant Frequency Permutation Arrays: An Application of Constraints to Mathematics

CS 188 Fall Introduction to Artificial Intelligence Midterm 1

A1 Problem Statement Unit Pricing

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

Outline for today s lecture Informed Search Optimal informed search: A* (AIMA 3.5.2) Creating good heuristic functions Hill Climbing

ON 4-DIMENSIONAL CUBE AND SUDOKU

A Glimpse of Constraint Satisfaction

Python for education: the exact cover problem

Solving Nonograms by combining relaxations

Automatically Generating Puzzle Problems with Varying Complexity

Chapter 5 Backtracking. The Backtracking Technique The n-queens Problem The Sum-of-Subsets Problem Graph Coloring The 0-1 Knapsack Problem

AUTOMATED REASONING. Agostino Dovier. Udine, November Università di Udine CLPLAB

CS 188 Introduction to Fall 2014 Artificial Intelligence Midterm

Foundations of Artificial Intelligence

Rating and Generating Sudoku Puzzles Based On Constraint Satisfaction Problems

Hybridization of CP and VLNS for Eternity II.

ENGR170 Assignment Problem Solving with Recursion Dr Michael M. Marefat

Investigation of Algorithmic Solutions of Sudoku Puzzles

Lecture 1, CS 2050, Intro Discrete Math for Computer Science

Explaining Ourselves: Human-Aware Constraint Reasoning

SudokuSplashZone. Overview 3

Written examination TIN175/DIT411, Introduction to Artificial Intelligence

Knights, Knaves, and Logical Reasoning

Problem of the Month. Miles of Tiles. 5 in. Problem of the Month Miles of Tiles Page 1

Overview. Algorithms: Simon Weber CSC173 Scheme Week 3-4 N-Queens Problem in Scheme

Topspin: Oval-Track Puzzle, Taking Apart The Topspin One Tile At A Time

2-TONE CODING FORMAT INSTRUCTION MANUAL

Introduction to Spring 2009 Artificial Intelligence Final Exam

1 Introduction The n-queens problem is a classical combinatorial problem in the AI search area. We are particularly interested in the n-queens problem

Caching Search States in Permutation Problems

SUDOKU X. Samples Document. by Andrew Stuart. Moderate

Permutations. = f 1 f = I A

Overview PROBLEM SOLVING AGENTS. Problem Solving Agents

Unit 12: Artificial Intelligence CS 101, Fall 2018

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

Sudoku Solver Version: 2.5 Due Date: April 5 th 2013

Taking Sudoku Seriously

The Birds of a Feather Research Challenge. Todd W. Neller Gettysburg College November 9 th, 2017

An efficient algorithm for solving nonograms

Two Parity Puzzles Related to Generalized Space-Filling Peano Curve Constructions and Some Beautiful Silk Scarves

A Novel Approach to Solving N-Queens Problem

Sally s Bedroom. 12 feet. 9 Bedroom C Bedroom D feet. 11 feet. Bedroom F. 11 feet. 1. If you were choosing, which room would you choose? Why?

Asymptotic Results for the Queen Packing Problem

Finding First and Most-Beautiful Queens by Integer Programming

Activity Sheet #1 Presentation #617, Annin/Aguayo,

Chapter 4 Heuristics & Local Search

Logic Masters India Presents

COMP219: Artificial Intelligence. Lecture 13: Game Playing

Chained Permutations. Dylan Heuer. North Dakota State University. July 26, 2018

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

CS 188: Artificial Intelligence Spring 2007

8. You Won t Want To Play Sudoku Again

Lecture 6: Latin Squares and the n-queens Problem

A B O U T T H E S E P U Z Z L E S

CMSC 201 Fall 2018 Project 3 Sudoku

Griddler Creator. Supervisor: Linda Brackenbury. Temitope Otudeko 04/05

Local search algorithms

Automatic Generation of Constraints for Partial Symmetry Breaking

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

Game Playing in Prolog

Cracking the Sudoku: A Deterministic Approach

CS 1571 Introduction to AI Lecture 12. Adversarial search. CS 1571 Intro to AI. Announcements

Computing Explanations for the Unary Resource Constraint

A difficult question until you realize algebra is the way to go. n = Nick, l = Lynne, a = Alf, s=shadi, c=chris

LESSON 2: THE INCLUSION-EXCLUSION PRINCIPLE

Pennies vs Paperclips

Swarming the Kingdom: A New Multiagent Systems Approach to N-Queens

Adversary Search. Ref: Chapter 5

KenKen Strategies 17+

CS188: Section Handout 1, Uninformed Search SOLUTIONS

Lecture 1 What is AI? EECS 348 Intro to Artificial Intelligence Doug Downey

Announcements. CS 188: Artificial Intelligence Fall Today. Tree-Structured CSPs. Nearly Tree-Structured CSPs. Tree Decompositions*

CMPT 310 Assignment 1

AI Plays Yun Nie (yunn), Wenqi Hou (wenqihou), Yicheng An (yicheng)

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

UMBC 671 Midterm Exam 19 October 2009

Reflections on the N + k Queens Problem

UKPA Presents. March 12 13, 2011 INSTRUCTION BOOKLET.

Transcription:

G53CLP Constraint Logic Programming Dr Rong Qu Modeling CSPs Case Study I

Constraint Programming... represents one of the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it. Eugene C. Freuder 1999 2 of 26

Constraint Programming The computer solves it A number of CP software tools available One can use the tools effectively after some training Necessary settings We ve seen foundations of constraint satisfaction Many software tools are based on this theory and algorithms 3 of 26

Constraint Programming The user states the problem Not the way we write/code the problem using languages of tools How we model the problem effectively in formulations In practice Model the problem understood by computers Code in specific languages Own codes for specific problems 4 of 26

Solving CSP How can we state the problem? Languages of different tools are different Model is the same 5 of 26

Solving CSP To improve the efficiency of CP solving Improve the algorithms Specialised domain information Higher level (complex) constraints (alldifferent) Different models for the problem Add redundant constraints More fundamental way Number of variables Number of constraints 6 of 26

Solving CSP software tools specific coding integration analyse coding problem model testing 7 of 26

Solving CSP... makes stating combinatorial problems easy in terms of a constraint satisfaction problem, however, it is more complicated to design solvable models. Roman Barták 2002 8 of 26

Solving CSP Primary role of constraint programmers Model the problem Translating high level constraints in the problem low level constraints supported by CP solvers 9 of 26

These Two Lectures Case study on AI puzzle n-queen Some in-class exercises Interactive Questions Discussions You can see the implementation/coding of these models 10 of 26

The n-queen Problem Any solution? How many solutions? 11 of 26

The n-queen Problem 12 of 26

The n-queen Problem Any solution? How many solutions? Some demos 13 of 26

The n-queen Problem Some questions How about n is (much) larger? Is the solution you have the only one? Number of solutions for n-queen* n: 1 2 3 4 5 6 7 8 9 10 1 0 0 2 10 4 40 92 352 724 n: 11 12 13 14 15 2,680 14,200 73,712 365,596 2,279,184 from wikipedia 14 of 26

The n-queen Problem Why modeling? Large computational time We have large problems We have problems of different sizes We have different problem (but can be modeled the same, see later) 15 of 26

The n-queen Problem model 1 Variables x i,j 1, if there is a queen in row i, column j; 0, otherwise Domain x i,j = {0, 1} 16 of 26

The n-queen Problem model 1 Constraints 1. One queen each row n j=1 x i,j = 1, i = 1,, n 2. One queen each column n i=1 x i,j = 1, j = 1,, n 17 of 26

The n-queen Problem model 1 Constraints 3. One queen diagonally Explicitly record all compatible values between each pair of variables Or Use function to represent the relationship between variables 18 of 26

The n-queen Problem model 2 Variables x 1, x 2,, x n : position of queens on the chessboard Domain {0 n 2-1}: tile index of each queen placed 19 of 26

The n-queen Problem model 2 Constraint R = x i / n + 1 C = x i mod n + 1 Given R 1, R 2 and C 1, C 2 of two queens positions 1. One queen each row R 1 R 2 2. One queen each column C 1 C 2 20 of 26

The n-queen Problem model 2 Constraint R = x i / n + 1 C = x i mod n + 1 Given R 1, R 2 and C 1, C 2 of two queens positions 3. One queen diagonally R 1 R 2 C 1 C 2 R 1 R 2 C 2 C 1 21 of 26

The n-queen Problem model 3 Variables x 1, x 2,, x n : rows of the chessboard Domain {1 n}: column index of each queen placed 22 of 26

The n-queen Problem model 3 Constraint 1. One queen each column for all i, j = {1,, n}, x i x j 2. One queen diagonally x i - x j i - j & x i - x j j - i 3. One queen each row? Row constraint is in the formulation 23 of 26

The n-queen Problem models The search space contains all possible assignments For the above three models module 3: {x 1,, x n }, {1,, n} module 2: {x 1,, x n }, (0,, (n 2 1)} module 1: {x i,j }, {0, 1} model variables domain search space n=4 n = 8 n = 10 n = 20 3 n n n! (or n n ) 24 4 E4 3.6 E6 2.4 E18 2 n n 2 (n 2 ) n 6.6 E4 2.8 E14 1 E20 1.1 E52 1 n 2 2 2 (n2 ) 6.6 E4 1.84 E19 1.27 E30 2.6 E120 24 of 26

The n-queen Problem models Fewer number of variables with small domains of variables are preferable Smaller search space Problems solved more quickly Fewer number of variables with large domains of variables are preferable model variables domain search space n=4 n = 8 n = 10 n = 20 3 n n n! 24 4 E4 3.6 E6 2.4 E18 2 n n 2 (n 2 ) n 6.6 E4 2.8 E14 1 E20 1.1 E52 1 n 2 2 2 (n2 ) 6.6 E4 1.84 E19 1.27 E30 2.6 E120 25 of 26

Summary Modeling in constraint programming Case study on 8-queen problem Comparison on 3 models Model in constraint programming Few number of variables Small domain 26 of 26