You are on page 1of 57

PRODUCTION SYSTEMS

Production systems (ps) Provide a scheme for structuring AI programs and performing the search process. A PS consists of A collection of condition action pairs called production rules A database of state information A procedure for invoking the production rules
1

A PS is a model for solving an AI problem


Typical PS s Expert system shells which provide environments for the construction of knowledge based ES General problem solving architectures for problem solving (SOAR)

SIMPLE EXAMPLE OF A PRODUCTION SYSTEM


Accept an integer x and produce its roman numeral representation 1. PRODUCTION RULES (a) If x is null then prompt the user and read x. (b) If x is not null and is bigger than 39 then print too big and make x null. (c) If x is not null and is between 10 and 39 then print x and reduce x by 10.
3

(d) If x is not null and is equal to 9 then print IX and reduce x to 0. (e) If x is not null and is between 5 and 8 then print V and reduce x by 5. (f) If x is not null and is equal to 4 then print IV and reduce x to 0. (g) If x is not null and is between 1 and 3 then print I and reduce x by 1. (h) If x is not null and is equal to 0 then print an end of line and make x null.

2. Database : The value of the sole variable x

3. Control Scheme : Test conditions in an arbitrary order until one is true; execute corresponding action; repeat indefinitely.

;Lisp program to convert integer to Roman numerals (Defun Roman (x)) loop (cond ((null x)(print enter number)(setq x (read))) (greaterp x 39) (print too big)(setq x wil)) ((greaterp x 9) (print x)(setq x (diference x 10))) ((equal x 9) print ix)(setq x 0) ((greaterp x 4) (print v)(setq x (diference x 5))) ((equal x 4) print iv)(setq x 0) ((greaterp x 0) (print I) (setqx (sub1 x ))) ((zerop x) (setq x nil ) ) (Go loop))
6

CONTROL STRATEGIES
Whether the problem is solved or not, how quickly the solution is arrived depends on the control strategy. If more than one rule matches the left side of the current state, which one to choose ?

Requirements of a good control strategy - IT Must Cause Motion Control strategies that do not cause motion will never lead to a solution. Example : In the water jug problem the strategy of choosing the first applicable rule from the top of the list of rules would continuously fill the 4-gallon jug. It would never solve the problem.
8

- Control strategy must be systematic Example : In the water jug problem, choosing a rule at random from among the applicable rules causes motion, but same state may be arrived several times, thus many steps are needed than necessary. A systematic Control Strategy causes global as well as local motion

Two systematic control strategies


1. Depth-first search 2. Breadth-first search Depth-first search - Method : Construct a tree with initial state as root Generate its offspring Pursue the branch until it yields a solution or it is a dead end i.e. no child can be generated If a dead end is reached, back tracking occurs, i.e. the most recently visited state is expanded and nodes are revisited
10

ALGORITHM : DFS
1.
If the initial state is a goal stats quit and return success. 2. Otherwise do the following until success or failure is signaled. (a) Generate a successor E of the initial state. If there are no more successors, signal failure. (b) Call DFS with E as the initial state (c) If success is returned, signal success otherwise continue in this loop. A depth first search tree (DFS) for water jug problem.
11

BREADTH FIRST SEARCH



METHOD : Construct a tree with initial state (IS) as root Generate offsprings by applying each of the applicable rules to IS For each leaf node generate its successors Continue the process until some rule produces the goal state
12

ALGORITHM (BFS)
1.
Create a variable called node-list and set it to initial state. 2. Until a goal state is found or node-list is empty do (a) Remove the first element from node-list and call it E. If node-list was empty quit. (b) For each way that each rule can match E, do : Two Levels of BFS for water jug problem (i) Apply the rule to generate a new state (ii) If the new state is a goal state, quit and return this state. (iii) Otherwise, add the new-state to the end of node-list
13

Example : Consider a map of cities of France, Transformed into a graph, which is an explicit representation of a state space. The implicit state space would be generated by applying the operators rather than preexisting.

14

LISP PROGRAM DEPTH FIRST SEARCH


(Defun depth-first-search (start-node goal-node) (prog (open closed N L) (setq open (list start-node)) (putprop start-node nil pointer) Loop (cond ((null open) (return failure))) (setq N (car open)) (setq open (cdr open)) (setq closed (cons N closed)) (cond ((eq N goal-node) (return (extract-path N)))) (setq L (successors N)) (setq L (set-diff L closed)) (setq open (append L (set-diff open L))) (mapcar (lambda (x) (putprop x N pointer)) L) (go loop) ))

15

(defun extract-path (n) (cond ((null n) nil) (t (append (extract-path (get n pointer)) (list n ) )) ) ) defun successors (N) (GET N ADJCNT) (defun ((null L1 L2) (cond ((Null L1) nil ) (( MEMBER (CAR (CDR L1 L2)) (( T cons (car L1) (set-diff (cdr L1) L2))))) for bfs step 5 i.e. (setq L (set-diff L closed)) (setq open (append L (set-diff open L))) is replaced with (setq L (set-diff(set-diff L open) closed)) (setq open (append open L )) (new nodes are put on the end of open)
16

Adjacency data (For each city, the other cities directly, connected to it) (putprop brest (rennes) adhct) (putrop rennes (laen paris brist nantes) adjct) (putprop paris (Calais nancy) Dijon limoges rennes Caen) adjct : Depth-first-search remes aviiur) Given the round about route (rennes caen, calajs nancy strasdooy Dijon lyon 17 grendble avignon)

BFS 1. Never gets trapped exploring a path which does not lead to a solution. 2. Guaranteed to find a solution if it exits. If multiple solutions exists a minimal one will be found 3. Requires more memory (All the tree that has so far been visited must be stored) 4. All nodes in level n must be examined before any node on level n + 1 can be examined 5. Only the best solution is found

DFS May explore a single unfruitful path for a long time. May find a long path when a shorter path exists Requires less memory (Only the nodes on the current path are to be stored) By chance a solution may be found without examining much of the nodes Can stop when any one solution is found
18

THE TRAVELLING SALESPERSON PROBLEM


A list of cities a sales persons has to visit exactly once. Direct routs between each pair of cities. The salesperson has to start at any one of the cities and make a round trip . Find the shortest route

19

The number of paths among N different cities is N-1, N-2, 3.2.1 = (N-1) ! The time to examine a single path is proportional to N The total tine to perform the search is proportional to N ! If N = 10, 10! =3, 625, 800 If N = 25, the number will be very large This phenomenon is called combinatorial explosion
20

BRANCH AND BOUND TECHNIQUE

Generate complete paths keeping track of the shorted path found so far Stop exploring any path, as soon as its partial length exceeds the shortest path found so far The method is efficient but still requires exponential time.
21

HEURISTIC SEARCH
Control strategy to solve hard problems efficiently Need not cause motion and need not be systematic but provides a very good solution; the solution may not be the best A heuristic is a rule of thumb or judgemental technique used in problem solving Heuristic methods lead to a solution some of the time but provide no guarantee of success They reduce the number of a alternatives, and thereby obtain a solution in a tolerable amount of time
22

SOLUTION OF TRAVELLING SALESPERSON PROBLEM


USING HEURISTIC SEARCH 1. Arbitrarily select a start city 2. To select the next city, look at all cities not yet visited and select the one closest to the current city, go to it next Repeat step 2 until all cities have been visited Execution time = 1+2+3+ . +(N-1)+N = N(N+1)/2 = 0(N2) 23

Some special purpose heuristics Problem :Discovering interesting ideas consider a function Y = f ( x , y) = x + y Heuristic : Two arguments are identical leads to the idea of squaring Y = f (x, y) = x U y The heuristic leads to the idea of identify function
24

REASONS FOR USING HEURISTICS


Without heuristics we end up in a combinatorial explosion Rarely we need the optimum solution; a good approximation usually serves well. People when they solve problems are not optimizers but satisfiers. As soon as they find a good solution, they quit Example : Searching for a parking space The approximations produced by heuristics may not be very good in the worst case, worst cases rarely arise in the real world.

25

In a rule based search process, heuristic knowledge can be incorporated In the rules themselves as in a chess playing system not simply the set of legal moves, but a set of sensible moves determined by the rule writer may be described. As a heuristic function that evaluates problem states and determines how desirable they are. The heuristic function is evaluated to a number.
26

PROBLEM CHARACTERISTICS
Heuristic Search is a general method to solve a large class of problems. To choose a specific appropriate method for a problem, it is necessary to analyse the problem along several key dimensions. 1. Is the problem decomposable into a set of independent smaller or easier subproblems?
27

Example of a decomposable problem

28

Example of a non-decomposable problem


Consider the BLOCKS WORLD problem

29

Available operators:
1. If block x has nothing on it, pick up x and put it on table CLEAR (x) ON (x, TABLE) 2. CLEAR (x) and CLEAR (y) ON (x,y) The goal state can be represented as ON(B,C) and ON(A,B) To achieve ON(B,C) from start state we can apply ON (C,TABLE) and ON(B,C)
30

Example of a non-decomposable problem contd..

31

Example of a non-decomposable problem contd..

While achieving the second sub-goal, the first sub-goal is not achieved, as the two sub-problems are not independent. They interact and these interactions must be considered in order to arrive at a solution for the entire problem.

32

2.Can solution steps be ignored or undone?


Mathematical theorem proving : Suppose we prove a lemma, but it is not useful We prove another lemma which is useful to prove the theorem We didn't lose anything except some effort Simple control strategy to solve the problem

33

Consider 8 - Puzzle problem

34

Can solution steps be ignored or undone? Contd..

suppose we slide 5 into empty cell. To slide 6 into the empty cell, we need to undo the previous step. To undo an incorrect step, you need to record the order in which operations are performed. Mistakes can be recovered but not easily. Slightly more complicated control strategy

35

Can solution steps be ignored or undone? Contd..


Problem of playing chess A great deal of effort for making each decision A stupid move realized after a couple of moves cannot be corrected. Cannot play as though it had never made a stupid move Ignorable problems solution steps can be ignored Recoverable problems solution steps can be undone Irrecoverable problems solution steps cannot be undone
36

3. Is the Universe predictable ?


8 Puzzle problem : A certain outcome problem is one in which we can plan a sequence of moves to reach a resulting state
Planning can be used to generate a sequence of operations that guarantee to lead to a solution Playing Bridge is an uncertain outcome problem Cannot exactly know where all the cards are and what the other player will do on his turn
37

Probabilities of various outcomes are used to choose a plan Planning can generate a sequence of operators with a good probability of leading to a solution. A number of solution paths have to be explored Hardest problems -Irrecoverable, uncertain outcome Other examples : controlling a robot arm - Obstacles into the path - Gears might stick -Error may cause the arm to knock over a stack of things Helping a lawyer decide how to defend his client against murder case.
38

4. Is a good solution absolute or relative ? Consider the following database of facts 1. Marcus was a man 2. Marcus was a Pompeian 3. Marcus was born in 40 A.D 4. All men are mortal 5. All Pompeian's died when the volcano erupted in 79 A.D 6. No mortal lives longer than 150 years 7. It is now 2003 A.D

39

Consider the question Is Marcus alive? There are two reasoning paths leading to the answer Marcus is dead. Path 1 Axioms used 8. Marcus is mortal 1,4 9. Marcuss age is 1963 years 3,7 10.Marcus is dead 8,9,6 Reasoning path- 2 11.All Pompeian's are dead now 7,5 12.Marcus is dead 11,2
40

Comments : We are interested in only the answer to the question - it does not matter which path we follow If one path leads successfully to the answer, there is no need of exploring the other path

41

Now consider the following table of distances (Km) for traveling sales person problem : New Delhi Bombay Madras Calcutta New Delhi 2200 2350 2800 Bombay 2200 3000 2500 Madras 2350 3000 1200 Calcutta 2800 2500 1200 -

42

The goal is to find the shortest path that visits each city exactly once.

First Path is not definitely the solution. This example illustrates any-path problem or best-path problem.

43

5. Is the solution a state or a path to a state?

consider the sentence The bank president ate a dish of pasta salad with the fork. In interpreting the sentence, some of the sources of ambiguity are

44

Is the solution a state or a path to a state? Contd..

45

Is the solution a state or a path to a state? Contd..


PASTA SALAD SALAD contains pasta or not? Dog

food does not contain dog With the fork modifies the verb eat; He ate with vegetables or He ate with friends, then structure would be different. Thus search would be required for complete interpretation for the sentence. For the above NLU problem, no need to record the processing by which the interpretation was found.
46

Is the solution a state or a path to a state? Contd..

In the water jug problem, it is not sufficient to say that the final state is (2,0), but the path or a sequence of operations leading to the goal state are required . NLU problem- solution is a state Water jug problem path to a state

47

6. What is the role of knowledge ?


Playing Chess requires rules for determining the legal moves and control mechanism to implement search. Additional knowledge as good strategy and tactics help to constrain the search and speed up the execution. Consider the problem of scanning daily newspapers and to decide which paper supports which party. - For this problem, a great deal of knowledge as names of candidates in each party, opposing government means supporting opposition party etc. is required.

48

7. Does the task require interaction with a person?


Does the task require interaction with a person? Theorem proving is a solitary problem. : The program is capable of finding a proof without interaction Expert system is a conversational problem .Communication is required either to provide additional assistance to computer or to provide additional information to the user.
49

Types of Productive (PS) systems


Monotonic production system : The application of a rule prevents the application of another rule that could also have been applied at the time the first rule was selected. A PS which is not monotonic is called non monotonic.

50

Partially commutation (PS) : It is a PS with the property if the sequence of rules transforms state x into state y, then any permutation of these rules also transforms state x into state y. A commutative PS is one that is monotonic and partially commutative. Formally all kinds of problems can be solved by all kinds of system. Practically there is a relationship between the kinds of problems and kinds of systems.
51

Examples :
Monotonic Partially commutative Theorem proving No monotonic Robot navigation blocks word 8-puzzle Bridge

Not Partially commutative

Chemical synthesis

52

Monotonic & partially commutative systems are for ignorable problems Non Monotonic & partially commutative systems are for recoverable problems. Issues in the design of search problems : Search process can be viewed as a traversal of tree.Each node represents a problem state and each arc represents a relationship between the states. In practice, most of the tree need not be explored for reaching a solution. Most search programs represent the tree implicitly in the rules and generate explicitly those parts 53 that they decide to explore.

Issues in search technique : The direction in which to conduct the test forward versus backward reasoning (to search from start state to goal state or from goal to start) How to select applicable rules or how to match rules against states How to represent each node of the search process (knowledge representation problem). The search space may be an arbitrary directed graph rather than a tree as same nodes may be generated as part of several paths.
54

Search trees versus search graphs

55

Search trees versus search graphs contd..


Using tree search requires no book keeping but lot of effort is wasted in expanding the same nodes. By traversing a directed graph, the waste of effort can be avoided with additional book keeping. BFS keeps track of nodes generated, but DFS does not DFS could be modified with the expense of additional storage.
56

Algorithm to search duplicate nodes in search graph


1. Examine the set of nodes generated to see if the new node already exists. 2. If it does not, add it to the graph 3. If it does already exists, do the following : a) Set the node being expanded to point to the already existing node. b) If the new path is better than the old path, record the new path and propagate the change.
57