صفحه 1:
An example (Clocksin and Mellish) Searching a maze Problem: \We need to enter a palace that has many rooms to look for a phone which is in one of the rooms. Solution: We go from room to room to get to a room that has hone. 0 3 boing around in cycles, we keep a record of the rooms tf sit. We use the list of rooms visited and every time we go t we check the list to make sure it is not on the list. 2 to a room that we have visited before, we go back to th¢ us room and try a different room to go to. If there are no rooms to go to from the current room then we backtrack to the previous room to try a

صفحه 2:
An algorithm 1. Go to the door of a room 2. If the room is on the list of rooms visited, ignore the room and go to 1. 3. Add the room to the list of rooms visited 4. Look for a telephone in the room 5. If there is no telephone, go to step 1. Otherwise, stop and the list has the path that we took to come to the correct room. Lecture 23 Maze Searching/Farmer, Goat, SE Oe ‏زر‎ 27

صفحه 3:
Representing the information about the doors and the room d containing a phone as a series of facts: door(a, b). door(b, c). door(b, e). 9 door(c, d). door(d, e). 72 door(e, f). door(e, g). hasphone(g). Lecture 23 Maze hing/Farmer, Goat, > ‏لوج و اجو رو‎

صفحه 4:
go(X, X, T). % we are already there go(X, Y, T) :- door(X, Z), % there is a door from X to Z not(member(Z, T)), % Z not visited before go(Z, Y, [Z|T]). % go from Z to Y and add Z to the list s this complete? ?- go(b,g,t J). Yes ?- go(d,b,[ ۰ No Why? 1001-5 are one way doors 272 ccording to the facts epresenting them. Lecture 23 Maze 4 hi G

صفحه 5:
Solution 1 Instead of declaring duplicate facts for each door we can use an هدع گس ها “door(a, b). door(b, c). door(b, e). door(c, d). toe b 5 door(d, e). door(e, f). 3 door(e, g). 72 hasphone(g). go(X, X, T). go(X, Y, T) :- door(X, Z), not(member(Z, T)), go(Z, Y, (Z|T)). go(X, Y, T) :- door(Z, X), not(member(Z, T)), go(Z, Y, TIT).

صفحه 6:
Solution 2 We can use disjunction. go(X, X, T). go(X, Y, T) :- (door(X, Z); door(Z, X)), not(member(Z, T)), go(Z, Y, (Z|T]). we nave to be Carerul NOt to lorget tne brackets around the disjoined goals. Not using the brackets: go(X, Y, T) :- door(X, Z); door(Z, X), not(member(Z, T)), go(Z, Y, Z|T)). mena 0 go(X, Y, T) :- door(X, Z); ( door(Z, X), not(member(Z, T)), go(Z, Y, [Z|T)) ). ‏جر‎ is incorrect and certainly not what we meant. Lecture 23 Maze 6 Searching/Farmer, Goat, SE Oe ‏زر‎ 27

صفحه 7:
ing to the room where there is a phone. get_to_phone(X,Y):- go(X, Y, [ ]), hasphone(Y) ?- get_to_phone(a,Y). ۲ 9 Yes The solution obove uses a strategy known as the “generate and test” strategy. A possible solution is generated and then tested until a solution is found or no more possible solutions can be generated. In the maze example the “go” clause generates solutions and “hasphone” clause is used to test the generated krmassitie roth qisondhe dS emeratadhddestgone atiegytis, tl uthowieveringpfreffiaieoia to room. The above rule would the een written as: st_to_phone(X,Y):-hasphone( Y ), go( X, Y, [ ]). Lecture 23 Maze z Searching/Farmer, Goat, SE Oe ‏زر‎ 27

صفحه 8:
The Russian Farmer Problem Lecture 23 Maze hi

صفحه 9:
(F,W,G,C) 41101 1 £ 1 1 rl) @LL) @ br) ‏با یام‎ | G@LLy (Lr, 1) | Mea 1¥ (Lr) 0 iS es 1 1 1 arr) Gri SC ie) ‏دبای‎ ‎yin) 117) ‏سوه ی‎ fy rely) 02 517 5 11 (r, 1,1, r) aoe in (aren aed allo Ga Darla) Pa Lees 1, r) ‏و گرا‎ erie (rr, Lr) ۳, r) a r, Yr), Pt) Lecture 23 Maze 9 hi 6

صفحه 10:
(F,W,G,C) 0 0 1 ely Ge) (E02, 1 ‏ا‎ 8 Gra ١ (Pia 0 ‏رل رام‎ (Bp) 0 ae “Gn Te)

صفحه 11:
go(Start,Target):- path(Start, Target,[Start],Path), write(‘A solution is:’),nl, write_path(Path). path(Start, Target, Visited, Path):- move(Start, NextNode), % Generate a move not( unsafe(NextNode) ), % Check that it is safe not( member(NextNode, Visited) ), % Check for recurrence path(NextNode, Target,[NextNode |Visited],Path),!. nath(Taraqet Tarcet Path Path) 0, Raarhad the.

An example (Clocksin and Mellish) Searching a maze Problem: We need to enter a palace that has many rooms to look for a phone which is in one of the rooms. Solution: We go from room to room to get to a room that has a phone. oid going around in cycles, we keep a record of the rooms t sit. We use the list of rooms visited and every time we go to we check the list to make sure it is not on the list. go to a room that we have visited before, we go back to the ous room and try a different room to go to. If there are no rooms to go to from the current room then we backtrack to the previous room to try a Lecture 23 Maze 1 different alternative.Searching/Farmer, Goat, An algorithm 1. Go to the door of a room 2. If the room is on the list of rooms visited, ignore the room and go to 1. 3. Add the room to the list of rooms visited 4. Look for a telephone in the room 5. If there is no telephone, go to step 1. Otherwise, stop and the list has the path that we took to come to the correct room. Lecture 23 Maze Searching/Farmer, Goat, 2 Representing the information about the doors and the room containing a phone as a series of facts: door(a, b). door(b, c). door(b, e). door(c, d). door(d, e). door(e, f). door(e, g). hasphone(g). Lecture 23 Maze Searching/Farmer, Goat, 3 go(X, X, T). % we are already there go(X, Y, T) :- door(X, Z), % there is a door from X to Z not(member(Z, T)), % Z not visited before go(Z, Y, [Z|T]). % go from Z to Y and add Z to the list Is this complete? ?- go(b,g,[ ]). Yes ?- go(d,b,[ ]). No Why? Doors are one way doors according to the facts epresenting them. Lecture 23 Maze Searching/Farmer, Goat, 4 Solution 1 Instead of declaring duplicate facts for each door we can use an additional rule. door(a, b). door(b, c). door(b, e). door(c, d). door(d, e). door(e, f). door(e, g). hasphone(g). go(X, X, T). go(X, Y, T) :- door(X, Z), not(member(Z, T)), go(Z, Y, [Z|T]). Lecture 23 Maze 5 go(X, Y, T) :- door(Z, X), not(member(Z, T)), go(Z, Y, Searching/Farmer, Goat, [Z|T]). Solution 2 We can use disjunction. go(X, X, T). go(X, Y, T) :- (door(X, Z); door(Z, X)), not(member(Z, T)), go(Z, Y, [Z|T]). We have to be careful not to forget the brackets around the disjoined goals. Not using the brackets: go(X, Y, T) :- door(X, Z); door(Z, X), not(member(Z, T)), go(Z, Y, [Z|T]). would mean go(X, Y, T) :- door(X, Z); ( door(Z, X), not(member(Z, T)), go(Z, Y, [Z|T]) ). ch is incorrect and certainly not what we meant. Lecture 23 Maze Searching/Farmer, Goat, 6 ing to the room where there is a phone. get_to_phone(X,Y):- go(X, Y, [ ]), hasphone(Y) ?- get_to_phone(a,Y). Y=g Yes The solution obove uses a strategy known as the “generate and test” strategy. A possible solution is generated and then tested until a solution is found or no more possible solutions can be generated. In the maze example the “go” clause generates solutions and “hasphone” clause is used to test the generated possible solutions. The “Generate and test” strategy is, th knew where the phone was, we would have gone directly notfrom efficient. uthowever, wondering room to room. The above rule would the been written as: et_to_phone(X,Y):-hasphone( Y ), go( X, Y, [ ] ). Lecture 23 Maze Searching/Farmer, Goat, 7 The Russian Farmer Problem Lecture 23 Maze Searching/Farmer, Goat, 8 (F,W,G,C) (l, l, l, l) X X (r, r, l, l) (r, l, l, l) X (l, l, l, l) X (r, l, r, l) (r, l, l, r) (r, l, r, l) (r, l, r, r) (l, l, r, l) X (r, r, r, l) X X (l, r, r, l) (l, l, l, r) (l, r, l, l) (l, l, r, l) X (r, r, r, l) (r, r, l, r) X (l, l, l, r) l, r) (l, l, r, l) X X (l, r, l, l) X (l, l, r, r) X (r, r, l, r) (r, l, r, r) (r, r, l, l) X (r, l, l, r) X (l, r, l, r) X (l, l, l, r) (l, r, (l, r, l, l) X (r, r, l, r) (r, r, l, r) X (r, r, r, r) Lecture 23 Maze Searching/Farmer, Goat, X (r, r, r, r) 9 (F,W,G,C) (l, l, l, l) (r, l, r, l) (l, l, r, l) (r, r, r, l) (l, r, l, l) (r, l, r, r) (l, l, l, r) (r, r, l, r) (r, r, l, r) (l, r, l, r) (l, r, l, r) (r, r, r, r) Lecture 23 Maze Searching/Farmer, Goat, 10 go(Start,Target):path(Start, Target,[Start],Path), write(‘A solution is:’),nl, write_path(Path). path(Start, Target,Visited,Path):move(Start, NextNode), % Generate a move not( unsafe(NextNode) ), % Check that it is safe not( member(NextNode,Visited) ), % Check for recurrence path(NextNode, Target,[NextNode |Visited],Path),!. Lecture 23 Maze 11 Searching/Farmer, Goat,

51,000 تومان