C463 / B551 Artificial Intelligence

Informed Search

Informed Search

Examples

Heuristic Examples

The A* Search

def A_star(initial):
   open_list = [initial]
   close_list = []
   goal = False
   while open_list and not goal:
      state = pop(open_list)
      if state in close_list: continue
      else: close_list.append(state)
      if (reach_goal(state)):
         goal = state
      else:
         children = expand-state(state)
         open_list += children
         open_list.sort(f_value)
   return goal

Small Example of Graph
 

Admissible Heuristic

Consistent Heuristic

Optimality and Completeness

Example

Starting from: timisoara. Goal: bucharest.

lugoj: g = 111, h = 244, f = 355
((lugoj 355) (arad, 484))
mehadia: g = 181, h = 241, f = 422
((mehadia 422) (arad 484))
((arad 484) (dobreta 498))
((dobreta 498) (sibiu 511) (zerind 567))
((sibiu 511) (craiova 525) (zerind 567))
((craiova 525) (rimnicu 531) (fagaras 535) (zerind 567))
((rimnicu 531) (fagaras 535) (zerind 567) (pitesti 611))
((pitesti 533) (fagaras 535) (zerind 567))
((fagaras 535) (bucharest 546) ((zerind 567))
((bucharest 546) (zerind 567) (bucharest 568))

Path: timisoara->arad->sibiu->rimnicu->pitesti->bucharest

Recursive Best-First Search (RBFS)

; Lisp version
(defun rbfs (state best-alt)
  (cond ((reach-goal state) state)
    ((not state) nil)
    (t (setq children (expand-state state)
             goal nil)
       (while (and children (not goal))
         (sort children f-value)
         (setq child (car children))
         (setq ba (f-value (cadr children)))
         (if (or (not ba) (< best-alt ba))
             (setq ba best-alt))
         (if ((> (f-value child best-alt)) 
                (setq children nil))
            ((setq goal (rbfs child ba)) 
                goal))))))

#Python version
def rbfs(state, best_alt):
   if not state or reach_goal(state): 
      return state
   else:
      children = expand_state(state)
      goal = False
      while not goal:
         children.sort(f_value_compare)
         child = children[0]
         if f_value(child) > f_value(state):
            f_value(state) = f_value(child)
         if f_value(child) > best_alt: 
            return False
         alt = best_alt
         if len(children) > 1 and f_value(children[1]) < best_alt:
            alt = f_value(children[1])
         goal = rbfs(child, alt)
      return goal
      

Iterative Deepening A* - IDA*

; Lisp version
(defun ida* (state limit)
  (cond ((reach-goal state) state)
    ((not state) nil)
    (t (setq children 
             (sort (expand-state state) f-value)
             child (pop children) 
             goal nil)
       (while (and child (not goal))
         (cond ((> (f-value child limit)) 
                (setq child nil))
               ((setq goal (ida* child limit)) 
                 goal)
               (t (setq child 
                        (pop children))))))))

#Python version
def ida*(state, limit)
   if not state or reach-goal(state): 
      return state
   else: 
      children = expand_state(state)
      goal = False
      while not goal:
         children.sort(f_value_compare)
         child = children[0]
         if f_value(child) > f_value(state):
            f_value(state) = f_value(child)
         if f_value(child) > limit:
            return False
         goal = ida*(child, limit)
      return goal

Simplified Memory-Bounded A* - SMA*

Pattern Databases