G52AIP Artificial Intelligence Programming - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

G52AIP Artificial Intelligence Programming

Description:

... dim1 1..9; range dim2 1..9; range bindex 0..2; int input[dim1, ... alldifferent(all(i in dim1) pos[i,j]); forall(i in dim1) alldifferent(all(j in dim2) pos[i,j] ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 15
Provided by: rxq
Category:

less

Transcript and Presenter's Notes

Title: G52AIP Artificial Intelligence Programming


1
G52AIPArtificial Intelligence Programming
Dr Rong Qu
  • Modeling CSPs Case Study II

2
Solving Sudoku
  • Variables
  • posi,j number placed at position (i,j)
  • Domain
  • posi,j 1, , 9

3
Solving Sudoku
  • Constraints
  • 1, , 9 on each row
  • 1, , 9 on each column
  • 1, , 9 in each 3X3 square

4
Solving Sudoku
  • Constraints
  • All different each row
  • All different each column
  • All different each 3X3 square
  • How to model constraint 3?

5
Solving Sudoku
  • Constraints
  • All different posi,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

6
  • 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

8
Solving Sudoku in OPL
  • //.dat file
  • input
  • 0 6 0 0 5 0 0 2 00 0 0 3 0 0 0 9 07 0 0 6
    0 0 0 1 00 0 6 0 3 0 4 0 00 0 4 0 7 0 1 0
    00 0 5 0 9 0 8 0 00 4 0 0 0 1 0 0 60 3 0
    0 0 8 0 0 00 2 0 0 4 0 0 5 0

9
Solving Sudoku in OPL
  • //.mod file
  • range dim1 1..9
  • range dim2 1..9
  • range bindex 0..2
  • int inputdim1,dim2 ... //read in the .dat
  • int setnumf in bindex x x in dim1 x lt
    (43f) x gt 3f
  • var int posdim1,dim2 in 1..9

10
Solving Sudoku in OPL
  • solve
  • forall(i in 1..9)
  • forall(j in dim2 inputi,j ltgt 0)
  • posi,j inputi,j

11
Solving Sudoku in OPL
  • solve
  • forall(j in dim2)
  • alldifferent(all(i in dim1) posi,j)
  • forall(i in dim1)
  • alldifferent(all(j in dim2) posi,j)

12
Solving Sudoku in OPL
  • solve
  • forall(b1 in bindex)
  • forall(b2 in bindex)
  • alldifferent(all(i in setnumb1, j in
    setnumb2) posi,j)

13
Solving Sudoku in OPL
14
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?
Write a Comment
User Comments (0)
About PowerShow.com