1 Search Problems (read Chapters 3 and 4 of Russell and Norvig) • Many (perhaps most) AI problems can be considered search problems. • This can be modeled on geographical search. • Start with a list of actions that can be taken at various geographical points on the map and their consequences, formulated as conditionals of the form ((precondition & action) -> result) (proclaim '(special *planning-conditionals*)) (defun pcond (precondition action) (list '-> (list '& precondition (concatenate 'string "go to " action)) action))
Search Problems. (read Chapters 3 and 4 of Russell and Norvig) Many (perhaps most) AI problems can be considered search problems. This can be modeled on geographical search. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
Search Problems
(read Chapters 3 and 4 of Russell and Norvig)
• Many (perhaps most) AI problems can be considered search problems.
• This can be modeled on geographical search.
• Start with a list of actions that can be taken at various geographical points on the map and their consequences, formulated as conditionals of the form
((precondition & action) -> result)
(proclaim '(special *planning-conditionals*))
(defun pcond (precondition action)
(list '-> (list '&
precondition
(concatenate 'string "go to " action))
action))
2
Search Problems
(defun precond (condit) (second (second condit)))
(defun action (condit) (third (second condit)))
(defun result (condit) (third condit))
3
Road Map of Romania
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
4
Find Bucharest
(setf *planning-conditionals*
(list
(pcond "Oradea" "Zerind")
(pcond "Oradea" "Sibiu")
(pcond "Arad" "Sibiu")
(pcond "Sibiu" ”Fagaras")
(pcond "Arad" "Timisoara")
(pcond "Timisoara" "Lugoj")
(pcond "Lugoj" "Mehadia")
(pcond "Mehadia" "Craiova")
(pcond "Craiova" "Rimnicu Vilcea")
(pcond "Rimnicu Vilcea" "Sibiu")
(pcond "Rimnicu Vilcea" "Pitesti")
(pcond "Pitesti" "Bucharest")
(pcond ”Fagaras" "Bucharest")
... ))
5
Find Bucharest• Given a starting point, a route to Bucharest will consist of a list of actions which, if
performed in order, will end with our being in Bucharest.
• Routes can be characterized recursively:
• If there is a conditional ((town1 & action) -> town2) in *planning-conditionals* then (list action) is a route from town1 to town2.
• If there is a conditional ((town1 & action) -> town) in *planning-conditionals* and route is a route from town to town2, then (cons action route) is a route from town1 to town2.
6
Find Bucharest• If we allow loops, there are infinitely many routes, so let us preclude loops.
• Non-circular routes that do not reuse actions in a list used-actions of actions can be characterized recursively:
• If there is a conditional ((town1 & action) -> town2) in *planning-conditionals* and action is not a member of used-actions, then (list action) is a non-circular route from town1 to town2.
• If there is a conditional ((town1 & action) -> town) in *planning-conditionals* and route is a non-circular route from town to town2 that does not reuse any members of (cons action used-actions) , then (cons action route) is a non-circular route from town1 to town2.
• A non-circular route from town1 to town2 is a non-circular route that does not reuse “go to town1”.
A B
C
D
E F
7
Find Bucharest• To avoid circularity, we must keep track of the actions already tried and not try them
again. We also want to avoid going back through the starting point.
Trying: go to Mehadia .Trying: go to Dobreta . .Trying: go to Craiova . . .Trying: go to Rimnicu Vilcea . . . .Trying: go to Sibiu . . . . .Trying: go to Fagaras . . . . . .Completing route with: go to Bucharest . . . . .Trying: go to Oradea . . . . . .Trying: go to Zerind . . . . . . .Trying: go to Arad . . . . . . . .Trying: go to Timisoara . . . . .Trying: go to Arad . . . . . .Trying: go to Zerind . . . . . . .Trying: go to Oradea . . . . . .Trying: go to Timisoara . . . .Trying: go to Pitesti . . . . .Completing route with: go to Bucharest . . .Trying: go to Pitesti . . . .Completing route with: go to Bucharest . . . .Trying: go to Rimnicu Vilcea . . . . .Trying: go to Sibiu . . . . . .Trying: go to Fagaras . . . . . . .Completing route with: go to Bucharest . . . . . .Trying: go to Oradea . . . . . . .Trying: go to Zerind . . . . . . . .Trying: go to Arad . . . . . . . . .Trying: go to Timisoara . . . . . .Trying: go to Arad . . . . . . .Trying: go to Zerind . . . . . . . .Trying: go to Oradea . . . . . . .Trying: go to Timisoara
11
Find Bucharest• Sometimes we just want to find a single route
Going from Urziceni to Timisoarabreadth-first search
15
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
16
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
17
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
18
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
19
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
20
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
21
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
22
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
23
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
24
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
25
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
26
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
27
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
28
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
29
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
30
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
31
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoarabreadth-first search
32
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
33
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
34
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
35
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
36
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
37
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
38
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
39
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
40
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
41
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
42
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
43
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
44
Oradea
Zerind
Arad
Timisoara
Dobreta
Mehadia
Lugoj
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
CralovaGiurgiu
BucharestUrziceni
Etorie
Hirsova
Vasiui
Iasi
Neamt
Going from Urziceni to Timisoara depth-first search search
45
General Search• For breadth-first search, we must store all the "partial routes" of length n, then
systematically extend each one by adding a single additional step in as many ways as possible, and then repeat this indefinitely until we find a route from town1 to town2.
• A mechanism for doing this is to maintain a queue of partial routes. The members of the queue will be called "nodes. They are lists of actions, and it is convenient to make the first member of each list the town the route ends at.
• A search strategy is an algorithm for selecting which node on the queue to try extending next.
• Generally, the most efficient way of implementing search strategies is to use them to order the queue, and then always select the first member of the queue for expansion.
• So we will take a strategy to be a function which, when applied to a new node and an existing queue returns a new queue which results from inserting the node into the old queue in the appropriate place.
46
General Search• Search for route from town1 to town2
• Initialize queue to (list (list town1))
• Initialize towns-tried to (list town1)
• Enter loop
– If the queue is empty, return from loop.
– Let node be the first element on the queue. Remove it from the queue. Let town0 be the first member (the "destination") of node.
– for each planning conditional ((town0 & go-to-town) -> town) where town is not a member of towns-tried, let new-route be the result of adding go-to-town to the route in node and:
• If town = town2, return new-route.
• Otherwise, add town to towns-tried, and add (cons town new-route) to the queue, ordering the queue according to the search strategy.
General Search Using Structures;; heuristic search orders the nodes on the queue in terms of their evaluations:(defun heuristic-search (node queue) (compute-evaluation node) (ordered-insert node queue #'(lambda (x y) (< (evaluation x) (evaluation y)))))
(defun ordered-insert (x queue R) "queue is a list ordered by R, and x is a new member to be inserted into the right position in the ordering. This returns the new ordered list." (let ((head nil) (tail queue)) (loop (when (null tail) (return (reverse (cons x head)))) (let ((y (first tail))) (cond ((funcall R y x) (push y head) (setf tail (cdr tail))) (t (push x tail) (dolist (z head) (push z tail)) (return tail)))))))
Optimal Search• Search for route from town1 to town2• Initialize queue to (list (make-town-node :town-name town1))
• Initialize towns-tried to (list town1)
• Enter loop
– If the queue is empty, return from loop.
– Let node be the first element on the queue. Remove it from the queue. Let town0 be the town-name of node.
– If town0 = town2, return the route-to the node.
– for each planning conditional ((town0 & go-to-town) -> town) where town is not a member of towns-tried, let new-route be the result of adding go-to-town to (route-to node) and add town to towns-tried, and add
("go to Bucharest" "go to Fagaras" "go to Sibiu" "go to Rimnicu Vilcea" "go to Craiova" "go to Dobreta" "go to Mehadia" "go to Lugoj" "go to Timisoara")