search
Download
Skip this Video
Download Presentation
Search

Loading in 2 Seconds...

play fullscreen
1 / 60

Search - PowerPoint PPT Presentation


  • 199 Views
  • Uploaded on

Search. Problem State Space. What is Problem State Space? What is valid move within the space? Rule of the Game Characteristic of the State Space How to find the Solution Path in the State Space? Search Methods. What is Problem State Space?. 8-Puzzel. 3. 1. 2. 3. 2. 1. 8. 8. 4.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Search' - donkor


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
problem state space
Problem State Space
  • What is Problem State Space?
  • What is valid move within the space?
    • Rule of the Game
  • Characteristic of the State Space
  • How to find the Solution Path in the State Space?
    • Search Methods
what is problem state space
What is Problem State Space?
  • 8-Puzzel

3

1

2

3

2

1

8

8

4

4

6

5

7

6

5

7

2

3

8

3

2

2

3

1

1

4

8

4

8

1

4

7

7

6

5

5

7

6

5

6

a

c

b

state space of 8 puzzle 1
State Space of 8-Puzzle(1)
  • List Representation

(2 0 3 1 8 4 7 6 5) : Initial State

(1 2 3 8 0 4 7 6 5) : Goal State

(0 2 3 1 8 4 7 6 5) : Intermediate States

(2 8 3 1 0 4 7 6 5)

…..

state space of 8 puzzle 2
State Space of 8-Puzzle(2)
  • Position Function

Pos(1, 1) = 2

Pos(1, 2) = 8

….

Or Predicate?

Pos(1, 1, 2) = True

Empty(3, 2) = True

valid moves of 8 puzzle
Valid Moves of 8-Puzzle
  • List

(2 0 3 1 8 4 7 6 5)  (0 2 3 1 8 4 7 6 5)

(2 0 3 1 8 4 7 6 5)  (2 8 3 1 0 4 7 6 5)

(2 0 3 1 8 4 7 6 5)  (2 3 0 1 8 4 7 6 5)

  • Predicate

(empty 1 2) (pos 1 1 x) 

(empty 1 1) (pos 1 2 x)

water jug problem
Water Jug Problem
  • 2 water jugs : 4 liter, 3 liter

Need to get exactly 2 liters of water

  • State space?

(0, 0) : initial (2, 0) : Goal

  • Valid move?
    • (4,0) (1, 3)  (0, 1)(4, 1) (2,3) (2,0 )
    • (0,3)  (3, 0)  (3, 3)  (4, 2)  (0, 2)
examples
Examples
  • Missionaries & Cannibals Problem
  • Blocks world
  • Tower of Hamoi
missionaries cannibals problem
Missionaries & Cannibals Problem
  • 3명의 선교사와 3명의 식인괴물(cannibal)이 강 한 쪽편에 있어요.
  • 보트를 이용해 강을 건너야 하는데, 보트는 1개이고 1번 건너갈 때 최대 2명을 태울수 있어요
    • 그러니까 1명은 노를 저어야하죠......
  • 만약 식인괴물 수가 선교사보다 많으면(같으면 괜찮아요) 선교사가 괴물한테 잡아 먹힙니다. 선교사를 무사히 살려서 6명 모두 강을 건너는 퀴즈.
slide10

;;;; The Missionaries and Cannibals Domain

(defun goal-test (state)

"The goal is to have no missionaries or cannibals left on the first side."

(= 0 (m1 state) (c1 state)))

(defun successors (state)

"Return a list of (action . state) pairs. An action is a triple of the

form (delta-m delta-c delta-b), where a positive delta means to move from

side 1 to side 2; negative is the opposite. For example, the action (1 0 1)

means move one missionary and 1 boat from side 1 to side 2."

(let ((pairs nil))

(loop for action in \'((+1 0 +1) (0 +1 +1) (+2 0 +1) (0 +2 +1) (+1 +1 +1)

(-1 0 -1) (0 -1 -1) (-2 0 -1) (0 -2 -1) (-1 -1 -1))

do (let ((new-state (take-the-boat state action)))

(when (and new-state (not (cannibals-can-eat? new-state)))

(push (cons action new-state) pairs))))

pairs))

(defun main ()

(print-actions (solve))

\'done)

(defun solve ()

(labels ((iter (state path)

(if (goal-test state)

(reverse path)

(let ((ss (remove-cyclic (successors state) path)))

(and ss (some #\'(lambda (s)

(iter (cdr s) (cons s path)))

(suffle ss)))))))

(iter (make-cannibal-state) (list (cons \'Begin (make-cannibal-state))))))

(defun remove-cyclic (succs path)

(remove-if #\'(lambda (s) (member s path :test #\'(lambda (a b)

(equal (cdr a) (cdr b))))) succs))

(defun print-actions (path)

(format t "~&~10A ~{~4S~}" "Action" \'(m1 c1 b1 m2 c2 b2))

(mapc #\'(lambda (p)

(format t "~&~10A~{~4d~}" (car p) (cdr p))) path))

(defun suffle (lst)

(sort (copy-list lst) #\'> :key #\'(lambda (x) (declare (ignore x)) (random 1.0))))

slide11

(defstruct (cannibal-state (:conc-name nil) (:type list))

"The state says how many missionaries, cannibals, and boats on each

side. The components m1,c1,b1 stand for the number of missionaries,

cannibals and boats, respectively, on the first side of the river.

The components m2,c2,b2 are for the other side of the river."

;; We need to represent both sides (rather than just one as on [p 68])

;; because we have generalized from 3+3 people to M+C. Incidently, we

;; also generalized from 1 boat to B boats.

(m1 3) (c1 3) (b1 1) (m2 0) (c2 0) (b2 0))

(defun take-the-boat (state action)

"Move a certain number of missionaries, cannibals, and boats (if possible)."

(destructuring-bind (delta-m delta-c delta-b) action

(if (or (and (= delta-b +1) (> (b1 state) 0))

(and (= delta-b -1) (> (b2 state) 0)))

(let ((new (copy-cannibal-state state)))

(decf (m1 new) delta-m) (incf (m2 new) delta-m)

(decf (c1 new) delta-c) (incf (c2 new) delta-c)

(decf (b1 new) delta-b) (incf (b2 new) delta-b)

(if (and (>= (m1 new) 0) (>= (m2 new) 0)

(>= (c1 new) 0) (>= (c2 new) 0))

new

nil))

nil)))

(defun cannibals-can-eat? (state)

"The cannibals feast if they outnumber the missionaries on either side."

(or (> (c1 state) (m1 state) 0)

(> (c2 state) (m2 state) 0)))

CL-USER 1 > (main)

Action M1 C1 B1 M2 C2 B2

BEGIN 3 3 1 0 0 0

(0 2 1) 3 1 0 0 2 1

(0 -1 -1) 3 2 1 0 1 0

(0 2 1) 3 0 0 0 3 1

(0 -1 -1) 3 1 1 0 2 0

(2 0 1) 1 1 0 2 2 1

(-1 -1 -1) 2 2 1 1 1 0

(2 0 1) 0 2 0 3 1 1

(0 -1 -1) 0 3 1 3 0 0

(0 2 1) 0 1 0 3 2 1

(-1 0 -1) 1 1 1 2 2 0

(1 1 1) 0 0 0 3 3 1

DONE

CL-USER 2 >

tower of hamoi

C

A

B

Tower of Hamoi
  • 문제는 막대 A에 쌓여있는 원판 3개를 막대 C로 옮기는 것이다. 단 다음의 조건을 지켜야 한다.
    • 한 번에 하나의 원판만 이동할 수 있다
    • 맨 위에 있는 원판만 이동할 수 있다
    • 크기가 작은 원판위에 큰 원판이 쌓일 수 없다.
    • 중간의 막대를 임시적으로 이용할 수 있으나 앞의 조건들을 지켜야 한다.
slide13

C

C

B

B

A

A

C

C

A

B

B

A

C

C

A

B

B

A

C

C

B

B

A

A

3개의 원판인 경우의 해답
  • 3개중 위 2개의 원판을 A->B
  • A의제일 큰 원판을 A->C
  • B 에있는 2개의 원판을 B->C
slide14
문제의 일반화

n-1개의 원판을 A에서 B로 옮기고

n번째 원판을 A에서 C로 옮긴 다음,

n-1개의 원판을 B에서 C로 옮긴다.

필요한 변수

원판의 개수 : n

어디에서 어디로? : from  to

임시막대 1개 : tmp

따라서, 함수의 prototype

n-1개의 원판

1개의 원판

C

B

A

C

B

A

C

B

A

C

B

A

n개의 원판인 경우
  • void hanoi_tower(int n, char from, char tmp, char to)
void hanoi tower int n char from char tmp char to
void hanoi_tower(int n, char from, char tmp, char to) ?
  • if(n==1)

1. 1번 원판을 fromto 즉, AC로옮긴다.

  • else n>=1 이면{

2. from의맨아래 원판을 제외한 (n-1)개의 원판을 fromtmp, 즉AB로 옮긴다.

3. 2번에서 옮기지 않은 from의 1번원판을 fromto, AC로 옮긴다.

4. 임시막대인 tmp의 원판들을 to로 옮긴다.

}

2. hanoi_tower(n-1, from, to, tmp);

4. hanoi_tower(n-1, tmp, from, to);

slide16
하노이탑 실습
  • #include <stdio.h>
  • void hanoi_tower(int n, char from, char tmp, char to)
  • {
    • if( n==1 ) printf("원판 1을 %c 에서 %c으로 옮긴다.\n",from,to);
    • else {
    • hanoi_tower(n-1, from, to, tmp);
      • printf("원판 %d을 %c에서 %c으로 옮긴다.\n",n, from, to);
    • hanoi_tower(n-1, tmp, from, to);
    • }
  • }
  • intmain(void)
  • {
  • hanoi_tower(4, \'A\', \'B\', \'C\');
  • }
characteristics of state space
Characteristics of State Space
  • Decomposable?

goal -- subgoals

  • Blind vs Informed (heuristic) Search
  • Revocable vs Irrevocable

backtracking

  • Predictable vs Stochastic
  • Optimal vs Plausible Solution
search algorithm
Search Algorithm
  • Guarantee to find a solution ?
  • Always terminate ?
  • Guarantee the solution to be optimal

-- admissible

  • Complexity - time and space
  • How can the complexity be reduced ?
  • Characteristics of the space?

State Space Search

strategies of ss search
Strategies of SS Search
  • Data-Driven vs. Goal Driven
    • Forward chaining / Backward chaining
    • Symptom  diagnosis : Forward

eg. Fever, cough  flu

    • Goal/Sub-goal : Backward

eg. Good Husband?

Rich? Or Handsome & Edu

forward vs backward
Forward vs Backward
  • When is forward (backward) better?
  • Bi-Directional
  • Factors deciding Forward/Backward

- Size of the known states: initial, goal

small to big

- Branching Factor : converging

- computational simplicity

eg. Water jug problem

weak methods
Weak Methods
  • General Purpose Control Strategies
  • Simplicity is the KEY of Weak Methods
  • Usually

- Not Optimal

- No Backtracking

- No Guarantee to the Solution

  • Generate & Test
  • Hill Climbing
  • Best First Search
  • Means-Ends Analysis
  • Etc.
heuristic function
Heuristic Function
  • Heuristics : Knowledge obtained from human experience
  • Heuristic function h : SS  number

a preference measure for each position of the state space

  • What is the heuristic function for 8-puzzle?
  • Necessary for Informed Search (cf. Blind)
generate test
Generate & Test
  • British Museum Algorithm
  • Guess a Solution & Test if it is right
  • DENDRAL : molecular structure analysis

plan-generate-test (constraint)

  • AM (Automated Mathematician)

Number Theory – generate a conjecture

  • Generate & Test is especially useful when combined with other strategy
hill climbing
Hill Climbing
  • Greed Method
  • Iterative Improvement Algorithm
  • Select the Best Looking Candidate

Use heuristic function

  • Stop when no more better looking candidates  Assume it is the Goal!
  • No Backtracking : Simplicity!!
hill climbing algorithm
Hill Climbing Algorithm
  • Hill-climbing: Attempt to maximize Eval(X) by moving to

the highest configuration in our moveset.

1. Let X := initial config

2. Let E := Eval(X)

3. Let N = moveset_size(X)

4. For ( i = 0 ; i<N ; i := i+1)

Let Ei := Eval(move(X,i))

5. If all Ei’s are ≤ E, terminate, return X

6. Else let i* = argmaxi Ei

7. X := move(X,i*)

8. E := Ei*

9. Goto 3

hill climbing issues
Hill Climbing Issues
  • Low Memory Requirement

-- No backtracking

  • Moveset (next move) design is critical
  • Evaluation Function design is critical
  • If the number of move is too big

-- Inefficient

  • Too small?

-- Easily stuck (plateau)

problems of hill climbing
Problems of Hill Climbing
  • Local Maxima (단기최적화)
  • Plateau(고원)
  • Ridge(산등성이)
avoiding problems in h c
Avoiding Problems in H.C.
  • Many Starting Points
  • Random Jump : Mutation

(Genetic Algorithm)

  • Simulated Annealing

Stochastic Method

simulated annealing algorithm
Simulated Annealing Algorithm

1. Let X := initial config

2. Let E := Eval(X)

3. Let i = random move from the moveset

4. Let Ei := Eval(move(X,i))

5. If E < Ei then

X := move(X,i)

E := Ei

Else with some probability, accept the move even though

things get worse:

X := move(X,i)

E := Ei

6. Goto 3 unless bored.

simulated annealing
Simulated Annealing

If Ei >= E then definitely accept the change.

If Ei < E then accept the change with probability

exp (-(E - Ei)/Ti) (called the Boltzman distribution)

…where Ti is a “temperature” parameter that

gradually decreases.

  • High temp: accept all moves (Random Walk)

Low temp: Stochastic Hill-Climbing

  • When enough iterations have passed without improvement,

terminate.

means ends analysis 1
Means Ends Analysis(1)
  • Bi-Directional Method
  • GPS(General Problem Solver) – Newell
  • Operator, Pre-condition, Result Table
  • Choose the operator that reduce the difference most
  • Recursively reduce the first and rest parts with other operators
means ends analysis 2
Means Ends Analysis(2)

GPS(I, G, O); I:initial, G: goal, O: op table

select o from O which reduce the difference

GPS(I, pre-condition(o), O)

print(o)

GPS(result(o), G, O)

end

  • Going to Central Park, N.Y

GPS(Konkuk, C.Park, O-Table)

  • Operation Table

op pre result

------------------------------------------------

AirPlane Inchon J.F.K

AirBus 버스터미널 Inchon

Taxi Konkuk Shinchon

Subway J.F.K C.Park

implementing search 1
Implementing Search(1)
  • Blind Search

-- Search does not depend on the nature of the positional value

-- Systematic Search Method

* Breadth-First Search

* Depth-First Search

* Iterative Deepening Search

** Lowest Cost First Search

  • Heuristic Search
implementing search 2
Implementing Search(2)
  • Blind Search
  • Heuristic Search

* Hill Climbing

* Best First Search

* A* Algorithm

blind search
Blind Search
  • Abstract Data Type - Tree
  • (defun make-TREE(label value children)
  • (list ‘tree label value children))
  • (defun TREE-label (tree) (second tree))
  • (defun TREE-value(tree) (third tree))
  • (defun TREE-children(tree)(fourth tree))
  • (defun TREE-print(tree)
  • (princ(TREE-label tree)))
depth first search
Depth First Search
  • (defun dfs(nodes goalp next)
  • (cond ((null nodes) nil)
  • ((funcall goalp (first nodes)) (first nodes))
  • (t (dfs (append (funcall next (first nodes))
  • (rest nodes))
  • goalp
  • next))))
function dfs
Function DFS
  • > (setq tree
  • (make-TREE ‘a 6
  • (list (make-TREE ‘b 3
  • (list(make-TREE ‘d 5 nil)
  • (make-TREE ‘e 4 nil))))))
  • //더 추가해서 만들어 보도록 하세요
  • > (dfs (list tree)
  • #’(lambda(x) (TREE-print x)
  • (eq ‘g (TREE-label x)))
  • #’TREE-children)
slide38

1

3

2

4

5

9

6

8

7

Depth-First Search Example

breadth first search
Breadth First Search
  • (defun bfs(nodes goalp next)
  • (cond ((null nodes) nil)
  • ((funcall goalp (first nodes)) (first nodes))
  • (t (bfs (append (rest nodes)
  • (funcall next (first nodes)))
  • goalp
  • next))))
slide40

1

3

2

4

5

9

6

8

7

Breadth-First Search Example

comparison of bfs and dfs
Comparison of BFS and DFS
  • BFS always terminate if goal exist

cf. DFS on infinite tree

  • BFS Guarantee shortest path to the goal (admissible)

eg. Multiple Goals

  • Space requirement
    • BFS - Exponential
    • DFS - Linear

Which is better ? BFS or DFS ?

iterative deepening search
Iterative Deepening Search
  • Compromise of BFS and DFS
  • Branch and Bound
  • Set the Limit then DFS
  • If Fail, extend the limit (one step)
  • Save on Storage, guarantee shortest path
function ids
Function ids
  • (defun ids (start goalp next depth)
  • (or (dfs-fd start goalp next 0 depth)
  • (ids start goalp next (1+ depth))))
  • (defun dfs-fd(node goalp next depth max)
  • (cond((funcall goalp node) node)
  • ((= depth max) nil)
  • (t (some #’(lambda (n)
  • (dfs-fd n goalp next (1+ depth) max))
  • (funcall next node)))))
heuristic search
Heuristic Search
  • Blind search assumes no information about the domain – Too expensive
  • Heuristic Information can be helpful
  • Heuristic Function

f(n) = g(n) + h(n)

f: total cost

g: cost from start to node n (real value)

h: cost from node n to goal

(usually unknown)

lowest cost first search
Lowest Cost First Search
  • Borderline between Blind and Heuristic Search
  • Cost value is assigned to each arc
  • Moveset (candidate list) is a priority queue ordered by path cost

Eg. Dijkstra’s algorithm

  • When Arc cost is unit value, BFS
best first search
Best First Search
  • Moveset (candidate list) is a priority queue ordered by heuristic cost h(n)
  • Does not guarantee the Shortest Path
  • Does not always terminate even though there is a solution
  • Performance depends on the h function
best first search program
Best First Search - Program
  • (defun best(nodes goalp next comparep)
  • (cond ((null nodes) nil)
  • ((funcall goalp (first nodes)) (first nodes))
  • (t (best (sort (append
  • (funcall next (first nodes))
  • (rest nodes))
  • comparep)
  • goalp
  • next
  • comparep))))
a algorithm
A* Algorithm
  • Best First Search only considers h
  • Lowest Cost First only considers g
  • A* algorithm takes f (note. f = g + h)
  • A* is optimal if h never overestimates the cost (optimistic)

- h is admissible

  • See the extra slide about A* algorithm
and or graph
And/Or Graph
  • Divide a problem into sub-problems and solve them individually
    • divide and conquer
  • And/Or Graph
    • Node: sub-problems
    • Links: And Link, Or Link
      • And : connect parent and sub-problems
      • Or : represents alternatives
searching and or graph 1
Searching And/Or Graph(1)
  • Objective of Search
    • To show whether start node is Solvable?
    • or Unsolvable ?
  • Definition of Solvable
    • Terminal node is solvable
    • A non-terminal OR node is solvable if at least one of its successor is solvable
    • A non-terminal AND node is solvable iff all of its successors are solvable
slide51

Searching And/Or Graph(2)

  • Definition of UnSolvable
    • Non-Terminal node with no successor is unsolvable
    • A non-terminal OR node is unsolvable iff all of its successors are unsolvable
    • A non-terminal AND node is unsolvable if at least one of its successors is unsolvable
  • Search terminate when start node is labeled either solvable or unsolvable
island driven search
Island Driven Search
  • Idea: Find a set of islands between s, g

s  i1  i2  ….  im-1  g

  • Problem is to identify the islands

Optimal solution not guaranteed

  • Hierarchical abstraction can be used
game tree search
Game Tree Search
  • Game Tree : Special case of AND/OR Graph
  • Objective of Game Tree Search
    • To find good first move
  • Static Evaluation Funtion e
    • Measure the worth of a tip node
      • if p is win for MAX, then e(p)= infinity
      • if p is win for MIN, then e(p) = - infinity
minimax procedure
MiniMax Procedure
  • Select the maximum worth alternative
  • Under Assumption of that the opponent do his best
  • Back-Up Value(BUV)

1. At tip node p, BUV is e(p)

2. At max node, BUV is max BUV of children

3. At min node, BUV is min BUV of children

minimax for tic tac toe
MiniMax for Tic-Tac-Toe
  • Two player, X and O, X play first
  • Static Evaluation function
    • If p is not a winning position

e(p) = (#complete rows, columns, or diagonal that are still open for X) - (#complete rows, columns, or diagonal that are still open for O)

    • If p is a win for X, e(p) = infinity
    • if p is a win for O, e(p) = -infinity
slide56

1

-1

X

X

1

X

O

O

-2

6 - 5

X

X

O

X

X

X

O

5 - 4

6 - 4

O

X

5 - 5

6 - 5

O

X

5 - 5

O

O

O

O

X

X

O

X

X

X

O

4 - 5

5 - 6

5 - 5

5 - 6

5 - 5

4 - 6

alpha beta procedure
Alpha-Beta Procedure
  • Improvement of MiniMax Procedure
    • combining search procedure & evaluation

max

S

A

B

C

1

-2

-1

0

1

production system
Production System
  • Model of Search and Human Problem Solving
  • Heavily used in AI (Expert) system
  • Production System components
    • Production rules (or production)
      • also called Long-term memory
    • Working Memory
      • also called Short-term memory
    • Recognize-act cycle
      • also called control structure, engine
production rules
Production Rules
  • Production
    • condition part and action part
    • premise and conclusion
    • LHS and RHS
  • Condition Part - pattern matching
  • Action Part - problem solving step
  • Single chunk of knowledge
  • Good for representing Judgmental knowledge
control of production system
Control of Production System
  • Data Driven vs Goal Driven
  • Forward vs Backward Search
  • Bidirectional Search
ad