cs 361 2015 lec 1-2

21
CS 361 Lac 1-2

Upload: alaa-zaghloul

Post on 18-Aug-2015

54 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cs 361 2015 lec 1-2

CS 361

Lac 1-2

Page 2: Cs 361 2015 lec 1-2

Artificial Intelligence (AI)

Page 3: Cs 361 2015 lec 1-2

WHAT IS AI?

AI is the study of how to make

computers make things which at the

moment people do better.

Page 4: Cs 361 2015 lec 1-2

DEFINING THE PROBLEM

Defining the problem as State Space

Search

Initial state

Goal state

Rules: Matching ----- forward ----> Action

Page 5: Cs 361 2015 lec 1-2

EXAMPLE (1): WATER JUG PROBLEM

If you have 2 jugs (4 gallon - 3 gallon), how can you get exactly 2 gallons into the 4 gallon jug?

The state space for this problem can be described as the set of ordered pairs of integers (x,y) such that x = 0, 1,2, 3 or 4 and y = 0,1,2 or 3; x represents the number of gallons of water in the 4-gallon jug and y represents the quantity of water in 3-gallon jug

The start state is (0,0) The goal state is (2,n)

Page 6: Cs 361 2015 lec 1-2

PRODUCTION RULES FOR WATER JUG PROBLEM

No

Current state Next State

Description

1 (x,y) if x < 4 (4,y) Fill the 4 gallon jug

2 (x,y) if y <3 (x,3) Fill the 3 gallon jug

3 (x,y) if x > 0 (x-d, y) Pour some water out of the 4 gallon jug

4 (x,y) if y > 0 (x, y-d) Pour some water out of the 3-gallon jug

5 (x,y) if x>0 (0, y) Empty the 4 gallon jug

6 (x,y) if y >0 (x,0) Empty the 3 gallon jug on the ground

7 (x,y) if x+y >= 4 and y >0

(4, y-(4-x)) Pour water from the 3 –gallon jug into the 4 –gallon jug until the 4-gallon jug is full

8 (x, y) if x+y >= 3 and x>0

(x-(3-y), 3) Pour water from the 4-gallon jug into the 3-gallon jug until the 3-gallon jug is full

9 (x, y) if x+y <=4 and y>0

(x+y, 0) Pour all the water from the 3-gallon jug into the 4-gallon jug

10 (x, y) if x+y <= 3 and x>0

(0, x+y) Pour all the water from the 4-gallon jug into the 3-gallon jug

Page 7: Cs 361 2015 lec 1-2

TO SOLVE THE WATER JUG PROBLEM

Gallons in the 4-gallon jug

Gallons in the 3-gallon jug Rule applied

0 0 2

0 3 9

3 0 2

3 3 7

4 2 5

0 2 9

2 0  

Page 8: Cs 361 2015 lec 1-2

THE WATER JUGS PROBLEM – SEARCH TREE

0 , 0

4 3

0 , 3

4 , 0

0 , 0

3 , 0

4 , 3

1 , 3

4 , 3

0 , 0

0 , 3

4 , 0

0 , 0

4 , 0

0 , 3

3 , 3

0 , 3

4 , 3

1 , 0

3 , 0

4 , 2

4 , 3

0 , 3

0 , 1

4 , 0

0 , 0

1 , 3

4 , 0

3 , 3

4 , 3

0 , 2

0 , 0

0 , 3

4 , 1

1 , 0

0 , 3

4 , 2

0 , 0

2 , 0

2 , 3

0 , 1

4 , 3

4 , 0

Page 9: Cs 361 2015 lec 1-2

PROBLEM SEARCH

Blind Search

… Blind Search – Breadth First

… Blind Search – Depth First

Heuristic Search

Page 10: Cs 361 2015 lec 1-2

THE WATER JUGS PROBLEM – SEARCH TREE

0 , 0

4 3

0 , 3

4 , 0

0 , 0

3 , 0

4 , 3

1 , 3

4 , 3

0 , 0

0 , 3

4 , 0

0 , 0

4 , 0

0 , 3

3 , 3

0 , 3

4 , 3

1 , 0

3 , 0

4 , 2

4 , 3

0 , 3

0 , 1

4 , 0

0 , 0

1 , 3

4 , 0

3 , 3

4 , 3

0 , 2

0 , 0

0 , 3

4 , 1

1 , 0

0 , 3

4 , 2

0 , 0

2 , 0

2 , 3

0 , 1

4 , 3

4 , 0

Page 11: Cs 361 2015 lec 1-2

BLIND SEARCH – BREADTH FIRST

0 , 0

4 3

0 , 3

4 , 0

3 , 0

4 , 3

1 , 3

3 , 3

1 , 0

4 , 2

0 , 1

0 , 2

4 , 1

2 , 0

Page 12: Cs 361 2015 lec 1-2

THE WATER JUGS PROBLEM – SEARCH TREE

0 , 0

4 3

0 , 3

4 , 0

0 , 0

3 , 0

4 , 3

1 , 3

4 , 3

0 , 0

0 , 3

4 , 0

0 , 0

4 , 0

0 , 3

3 , 3

0 , 3

4 , 3

1 , 0

3 , 0

4 , 2

4 , 3

0 , 3

0 , 1

4 , 0

0 , 0

1 , 3

4 , 0

3 , 3

4 , 3

0 , 2

0 , 0

0 , 3

4 , 1

1 , 0

0 , 3

4 , 2

0 , 0

2 , 0

2 , 3

0 , 1

4 , 3

4 , 0

Page 13: Cs 361 2015 lec 1-2

BLIND SEARCH – DEPTH FIRST

0 , 0

4 3

0 , 3

3 , 0

4 , 3

3 , 3

4 , 2

0 , 2

2 , 0

Page 14: Cs 361 2015 lec 1-2

EXAMPLE (2): WATER JUG PROBLEM

You are given three jugs, a 10-gallon one, 7-gallon one, and 3-gallon one.

Neither have any measuring markers on it.

There is a pump that can used to fill the jugs with water.

Use Breadth First and Depth First search to get exactly 5-gallons of water into 7-gallon jug.

The start state is (0,0,0) The goal state is (n,5,n)

Page 15: Cs 361 2015 lec 1-2

EXAMPLE (3): TRAVERSING A MAZE The wall follower, the best-known rule for

traversing mazes, is also known as either the left-hand rule or the right-hand rule.

Page 16: Cs 361 2015 lec 1-2

TRAVERSING A MAZE PROBLEM – SEARCH TREE

A

CB D

FE HG I

KJ

NML

Page 17: Cs 361 2015 lec 1-2

TRAVERSING A MAZE PROBLEM – BREADTH FIRST

A

B D

I

K

M

Page 18: Cs 361 2015 lec 1-2

TRAVERSING A MAZE PROBLEM – SEARCH TREE

A

CB D

FE HG I

KJ

NML

Page 19: Cs 361 2015 lec 1-2

TRAVERSING A MAZE PROBLEM – DEPTH FIRST

A

B D

I

K

M

Page 20: Cs 361 2015 lec 1-2

EXAMPLE (4): TRAVERSING A MAZE

Page 21: Cs 361 2015 lec 1-2

END