G53CLP Constraint Logic Programming Modeling CSPs – Case Study II Dr Rong Qu.

Slides:



Advertisements
Similar presentations
Examples for Discrete Constraint Programming
Advertisements

For(int i = 1; i
Quantitative Methods Session 16 – Matrices Pranjoy Arup Das.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
G53CLP Constraint Logic Programming Modeling CSPs – Case Study I Dr Rong Qu.
G53CLP Constraint Logic Programming Constraint Optimisation Problems – Demos in OPL Studio Dr Rong Qu.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Foundations of Constraint Processing, Fall 2005 October 21, 2005CSPs and Relational DBs1 Foundations of Constraint Processing CSCE421/821, Fall 2005:
CPSC 322, Lecture 11Slide 1 Constraint Satisfaction Problems (CSPs) Introduction Computer Science cpsc322, Lecture 11 (Textbook Chpt 4.0 – 4.2) January,
1 Lab Session-4 CSIT121 Fall 2004 Scope of Variables Top Down Design Problem The Solution Lab Exercise for Demo.
1 Lab 2 CSIT-120 Fall 2000 Session II-A (September 14th) Operations on Data Lab Exercise 2-A Data Types Variables Lab Exercise 2-B Session II-B (September.
Constraints.py.
SOLVING SUDOKU WITH MATLAB VERIFICATION FUNCTION correctness verification of the puzzle: checks if the current element appears twice in the same line,
Functions Teacher Twins©2014.
4.4 Equations as Relations
Chapter 3: Using Spreadsheets in Analytical Chemistry CHE 321: Quantitative Chemical Analysis Dr. Jerome Williams, Ph.D. Saint Leo University.
1 © 2010 Pearson Education, Inc. All rights reserved © 2010 Pearson Education, Inc. All rights reserved Chapter 9 Matrices and Determinants.
MIT and James Orlin © –Developed by James Orlin, MIT Animation of the Gauss-Jordan Elimination Algorithm.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Multidimensional Arrays.
Functions. Warm Up Solve each equation. 1.2x – 6 = x = X + 29 = x – 5 – 4x = 17 x = 14 x = - 7 x = -15 x = 11.
Formal Methods & Verification: Project 1 Sudoku for Nonomino board Farn Wang.
Sudoku Solver Comparison A comparative analysis of algorithms for solving Sudoku.
Sudoku Boolean Logic Representation Upper left square.
SUDOKO PROBLEM: Modeled as an ILP* Daryl L. Santos, Ph.D. Professor – Systems Science and Industrial Engineering Thomas J. Watson School of Engineering.
Objective : Solving systems of linear equations by graphing System of linear equation two or more linear equations How do I solve linear systems of equations?
HW #2. Due Mar 27 23:59 Do NOT forget to submit both a hardcopy solution to the HW box and a softcopy solution to TA (Youngjoo Kim):
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Math – What is a Function? 1. 2 input output function.
CSPs Tamara Berg CS Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
G53CLP Constraint Logic Programming
How Do I Solve This Thing?. You are familiar with Sudoku puzzles. For this variation, place the integers 1 – 9 into each row or column such that the.
Monster (“Mega”) Sudoku
Backtracking & Brute Force Optimization Intro2CS – weeks
N-queens problem Original problem: How to place 8 queens on an 8x8 chessboard so that no two queens attack each other N-queen problem: Generalization for.
APPLICATIONS OF MULTIPLYING BINOMIALS. 1. WHAT IS THE AREA OF THE BELOW SHAPE? 3x+4 X+8.
CompSci Problem Solving: Sudoku  Rules of the Game Sudoku is played with a 9 by 9 "board" consisting of nine 3 by 3 sub-boards. The symbols 1 -
Chapter 8 Systems of Linear Equations in Two Variables Section 8.3.
4.1 An Introduction to Matrices Katie Montella Mod. 6 5/25/07.
CS1101: Programming Methodology Aaron Tan.
Chapter 1 Connections to Algebra Review
Equations Quadratic in form factorable equations
CSP in Python.
Introduction to Matrices
Do Now: Can you input all real numbers into the x variable in the following functions? If not what numbers can x not take on?
Open Office Calc Session 01 Class Management Report
BIS 311 Innovative Education-- snaptutorial.com
PRG 211 CART Education for Service--prg211cart.com.
Functions and their Graphs
Linear Functions SOL 8.14, SOL 8.16, SOL 8.17.
Identifying functions and using function notation
Introduction to Functions
Objective: Today we will investigate the ‘magic’ in magic squares.
Using WinQSB to solve Linear Programming Models
Special Problems (Solve)
Multidimensional Arrays
CS Software Studio Assignment 1
2.1: Represent Relations and Functions HW: p.76 (4-20 even, all)
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
Relations, Domain and Range
HW #2. Due Apr 25 23:59 Do NOT forget to submit both a hardcopy solution to the HW box and a softcopy solution to TA.
RELATIONS & FUNCTIONS CHAPTER 4.
Year 2 Summer Term Week 8 Lesson 3
Equations Quadratic in form factorable equations
Functions-Exercises.
Warm-Up #3
Exercise Solve x – 14 = 35. x = 49.
Exercise Every positive number has how many real square roots? 2.
1.3 NEW FUNCTIONS FROM OLD.
Unit 1 Getting Ready Part II
Presentation transcript:

G53CLP Constraint Logic Programming Modeling CSPs – Case Study II Dr Rong Qu

2 Solving Sudoku Variables pos i,j : number placed at position (i,j) Domain pos i,j = {1, …, 9} G53CLP – Constraint Logic ProgrammingDr R. Qu

3 Solving Sudoku Constraints {1, …, 9} on each row {1, …, 9} on each column {1, …, 9} in each 3X3 square G53CLP – Constraint Logic ProgrammingDr R. Qu

4 Solving Sudoku Constraints 1. All different each row 2. All different each column 3. All different each 3X3 square How to model constraint 3? G53CLP – Constraint Logic ProgrammingDr R. Qu

5 Solving Sudoku Constraints All different pos[i,j] = {1, …, 9} i = {1, 2, 3}; {4, 5, 6} or {7, 8, 9} j = {1, 2, 3}; {4, 5, 6} or {7, 8, 9} G53CLP – Constraint Logic ProgrammingDr R. Qu

Solving Sudoku – Demo

7 Data File & Project in OPL Input data in OPL Project in OPL Add/insert model file.mod Add/insert data file.dat Data type declared in model file.mod will look up the data file.dat G53CLP – Constraint Logic ProgrammingDr R. Qu

8 Solving Sudoku in OPL //.dat file input= [[ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]]; G53CLP – Constraint Logic ProgrammingDr R. Qu

9 Solving Sudoku in OPL //.mod file range dim1 1..9; range dim2 1..9; range bindex 0..2; int input[dim1,dim2] =...;//read in the.dat {int} setnum[f in bindex] = {x | x in dim1: x 3*f }; var int pos[dim1,dim2] in 1..9; G53CLP – Constraint Logic ProgrammingDr R. Qu

10 Solving Sudoku in OPL solve{ forall(i in 1..9) forall(j in dim2 : input[i,j] <> 0) pos[i,j] = input[i,j] ; … }; G53CLP – Constraint Logic ProgrammingDr R. Qu

11 Solving Sudoku in OPL solve{ … forall(j in dim2) alldifferent(all(i in dim1) pos[i,j]); forall(i in dim1) alldifferent(all(j in dim2) pos[i,j]); … }; G53CLP – Constraint Logic ProgrammingDr R. Qu

12 Solving Sudoku in OPL solve{ … … forall(b1 in bindex){ forall(b2 in bindex){ alldifferent(all(i in setnum[b1], j in setnum[b2]) pos[i,j]); } } }; G53CLP – Constraint Logic ProgrammingDr R. Qu

13 Exercise – Coins in Bank You have a bag of coins to save in your bank Weights of coins If the bag of coins weighs 131g, how much in total? How about 4g? How many possible solutions? How can you solve this problem? Lab session next week £150p20p10p5p2p1p Weight(g) G53CLP – Constraint Logic ProgrammingDr R. Qu