Artificial Intelligence Problems

23

description

Water Jug Problem, Depth First Search, Breadth First Search

Transcript of Artificial Intelligence Problems

Page 1: Artificial Intelligence Problems
Page 2: Artificial Intelligence Problems

General Problem SolvingGeneral Problem SolvingTo build a system to solve a particular

problem, following steps are required –Define the problem preciselyAnalyze problemIsolate and represent the task

knowledgeChoose the best problem solving

techniquesApply it to the particular problem.

Page 3: Artificial Intelligence Problems

State Space SearchThe representation of configuration of possible arrangements in a problem, as a legal set of rules, from one state (configuration) to another state is referred as state space.

3

Page 4: Artificial Intelligence Problems

State Space Search1. Define a state space that contains all the

possible configurations of the relevant objects.

2. Specify the initial states.

3. Specify the goal states.

4. Specify a set of rules: What are unstated assumptions? How general should the rules be? How much knowledge for solutions should be in

the rules?4

Page 5: Artificial Intelligence Problems

Water Jug Problem“You are given two jugs, a 4-litre one and a 3-litre one. Neither has any measuring markers on it. There is a pump that can be used to fill the jugs with water. How can you get exactly 2 litres of water into 4-litre jug.”

5

Page 6: Artificial Intelligence Problems

State Space Search – SolutionState: (x, y) x = 0, 1, 2, 3, or 4 y = 0, 1, 2, 3

Start state: (0, 0).Goal state: (2, n) for any n. Attempting to end up in a goal state.

(x, y) (4, y)6

Page 7: Artificial Intelligence Problems

RulesS.No Condition Action Explanation1 if x 4 (4, y) Fill the 4 litres jug2 (x, y)

if y 3

(x, 3) Fill the 3 litres jug

3 (x, y)

if x 0

(x d, y) Pour some water out of 4 litres jug

4 (x, y)

if y 0

(x, y d) Pour some water out of 3 litres jug

5 (x, y)

if x 0

(0, y) Empty the 4 litres jug on the ground

6 (x, y)

if y 0

(x, 0) Empty the 3 litres jug on the ground

7

Page 8: Artificial Intelligence Problems

S.No Condition Action Explanation

7 (x, y)

if x y 4, y 0

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

8 (x, y)

if x y 3, x 0

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

9 (x, y)

if x y 4, y 0

(x y, 0) Pour all the water from the 3 litres jug into the 4 litres jug.

10 (x, y)

if x y 3, x 0

(0, x y) Pour all the water from the 4 litres jug into the 3 litres jug.

11 (x, 2)

x>0

(0,2) Empty the x litres from the 4 litres jug on the ground

12 (0, 2) (2, 0) Pour the 2 litres from the 3 litres jug into the 4 litres jug 8

Page 9: Artificial Intelligence Problems

Solution to Water Jug ProblemFollowing is the trace of above production rules as directed

Water in 4 L Jug Water in 3 L Jug Rule Applied

  0 0 INITIAL STATE

2

0 3 9

3 0 2

3 3 7

4 2 5

0 2 9

2 0 GOAL STATE 9

Page 10: Artificial Intelligence Problems

Formal description of a ProblemTo provide a formal description of a

problem, we must do the following –Define a state space that contains all the

possible configuration of the relevant objects.

Specify one or more states within that space that describe possible situations from which the problem solving process may start. These states are called INITIAL STATE.

10

Page 11: Artificial Intelligence Problems

Formal description of a ProblemSpecify one or more states that would be

acceptable as solution to the problem. These states are called GOAL STATE.

Specify a set of rules that describe the actions (operators) available.

11

Page 12: Artificial Intelligence Problems

Production SystemA production system consists of –A set of rules – each consisting of a left side (a

pattern) that determines the applicability of the rule and a right side that describes the operation to be performed if the rule is applied.

One of more knowledge databases – that contain whatever information is appropriate for the particular task. Some parts of the database may be permanent, while other parts of it may pertain only to the solution of the current problem. Information in these databases may be structured in any appropriate way.

12

Page 13: Artificial Intelligence Problems

Production SystemA control strategy – that satisfies the

order in which the rules will be compared to the database and a way of resolving the conflicts that arise when several rules match at once.

A rule applier.

13

Page 14: Artificial Intelligence Problems

Control StrategiesThe requirements of good control

strategies are –It cause motionIt should be systematicControl strategies are techniques to decide

which rule to apply next during the process of searching for the solution to a problem. Control strategies that do not cause motion will never lead to a solution.

14

Page 15: Artificial Intelligence Problems

Control StrategiesThe requirement that control strategy be systematic corresponds to the need for global motion (over the course of several steps) as well as for local motion (over the course of a single step).

15

Page 16: Artificial Intelligence Problems

Forward chainingForward chaining is a process of searching in which we start with a given initial state and when we connect it (chain it) with the next state closest to goal state compared with all successor states of the initial state. Thus we find a path (i.e. chain of states) consisting of various states starting from initial state to goal state.

16

Page 17: Artificial Intelligence Problems

Backward chainingBackward chaining is a reverse of forward chaining. In this process of searching we start with a goal state and then we connect it (chain it) with the next state closest to the initial state compared with the all predecessor states of the goal state. Thus we find a path (i.e. chain of states) consisting of various states starting from goal state to initial state.

17

Page 18: Artificial Intelligence Problems

Depth First SearchExpand one of the nodes

at the deepest level.Depth first search works

by taking a node, checking its neighbors, expanding the first node it finds among the neighbors, checking if that expanded node is our destination, and if not, continue exploring more nodes.

18

Page 19: Artificial Intelligence Problems

Depth First Search – AlgorithmPlace the starting node s on the queue.If the queue is empty, return failure and

stop.If the first element on queue is a goal

node g, return success and stop. Otherwise,

Remove and expand the first element, and place the children at the front of the queue (in any order)

Return to step 2. 19

Page 20: Artificial Intelligence Problems

Depth First Search – AdvantagesDFS requires less memory since only the

nodes on the current path are stored. This contrasts with BFS, where all parts of the tree that has so far been generated must be stored.

By chance, DFS may find solution without examining much of the search space at all. This contrasts with BFS in which all parts of the tree must be examined to level n before any nodes on level n+1 can be examined.

20

Page 21: Artificial Intelligence Problems

Breadth First SearchExpand all the

nodes of one level first.

In breadth first search, newly explored nodes are added to the end of your Open list.

21

Page 22: Artificial Intelligence Problems

Breadth First Search – Algorithm

Place the starting node s on the queue.If the queue is empty, return failure and

stop.If the first element on the queue is a goal

node g, return success and stop. Otherwise,

Remove and expand the first element from the queue and place all the children at the end of the queue in any order.

Return to step 2.22

Page 23: Artificial Intelligence Problems

Breadth First Search – AdvantagesBFS will not get trapped exploring a blind alley.

This contrasts with DFS searching, which may follow a single, unfruitful path for a very long time, perhaps forever, before the path actually terminate in the state that has no successors.

If there is a solution, then BFS search is guaranteed to find it. Furthermore, if there are multiple solutions, then a minimal solution will be found. This is guaranteed by the fact that longer paths are never examined until the shorter paths have already been examined.

23