Skip to content

Commit

Permalink
Merge pull request #86 from samagra14/4e_search
Browse files Browse the repository at this point in the history
Adds 4e algorithms.
  • Loading branch information
norvig committed Jul 25, 2018
2 parents 7d06ab9 + c111831 commit 72206d6
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 1 deletion.
22 changes: 22 additions & 0 deletions md/Breadth-First-Search.md
@@ -1,5 +1,27 @@
# BREADTH-FIRST-SEARCH

## AIMA4e

__function__ BREADTH-FIRST-SEARCH(_problem_) __returns__ a solution, or failure
 __if__ problem's initial state is a goal __then return__ empty path to initial state
 _frontier_ ← a FIFO queue initially containing one path, for the _problem_'s initial state
 _reached_ ← a set of states; initially empty
 _solution_ ← failure
 __while__ _frontier_ is not empty __do__
   _parent_ ← the first node in _frontier_
   __for__ _child_ __in__ successors(_parent_) __do__
     _s_ ← _child_.state
     __if__ _s_ is a goal __then__
       __return__ _child_
     __if__ _s_ is not in _reached_ __then__
       add _s_ to _reached_
       add _child_ to the end of _frontier_
 __return__ _solution_

---
__Figure 3.9__ Breadth-first search algorithm.


## AIMA3e
__function__ BREADTH-FIRST-SEARCH(_problem_) __returns__ a solution, or failure
 _node_ ← a node with STATE = _problem_.INITIAL\-STATE, PATH\-COST = 0
Expand Down
23 changes: 23 additions & 0 deletions md/Depth-Limited-Search.md
@@ -1,5 +1,28 @@
# DEPTH-LIMITED-SEARCH

## AIMA4e

__function__ DEPTH-LIMITED-SEARCH(_problem_, _l_) __returns__ a solution, or failure, or cutoff
 _frontier_ ← a FIFO queue initially containing one path, for the _problem_'s initial state
 _solution_ ← failure
 __while__ _frontier_ is not empty __do__
   _parent_ ← pop(_frontier_)
   __if__ depth(_parent_) > l __then__
     _solution_ ← cutoff
     __else__
       __for__ _child_ __in__ successors(_parent_) __do__
         __if__ _child_ is a goal __then__
           __return__ _child_
         add _child_ to __frontier__
 __return__ _solution_

---
__Figure 3.14__ An implementation of depth-limited tree search. The algorithm has two dif-
ferent ways to signal failure to find a solution: it returns failure when it has exhausted all
paths and proved there is no solution at any depth, and returns cutoff to mean there might be
a solution at a deeper depth than l. Note that this algorithm does not keep track of reached
states, and thus might visit the same state multiple times on different paths.

## AIMA3e
__function__ DEPTH-LIMITED-SEARCH(_problem_,_limit_) __returns__ a solution, or failure/cutoff
 __return__ RECURSIVE\-DLS(MAKE\-NODE(_problem_.INITIAL\-STATE),_problem_,_limit_)
Expand Down
12 changes: 12 additions & 0 deletions md/Hill-Climbing.md
@@ -1,5 +1,17 @@
# HILL-CLIMBING

## AIMA4e

__function__ HILL-CLIMBING(_problem_) __returns__ a state that is a local maximum
 _current_ ← _problem_.INITIAL\-STATE
 __loop do__
   _neighbor_ ← a highest\-valued successor of _current_
   _if_ VALUE(_neighbour_) ≤ VALUE(_current_) __then return__ _current_
   _current_ ← _neighbor_

---
__Figure 4.2__ The hill-climbing search algorithm, which is the most basic local search technique. At each step the current node is replaced by the best neighbor.

## AIMA3e
__function__ HILL-CLIMBING(_problem_) __returns__ a state that is a local maximum
 _current_ ← MAKE\-NODE(_problem_.INITIAL\-STATE)
Expand Down
2 changes: 1 addition & 1 deletion md/Iterative-Deepening-Search.md
@@ -1,6 +1,6 @@
# ITERATIVE-DEEPENING-SEARCH

## AIMA3e
## AIMA3e / AIMA4e
__function__ ITERATIVE-DEEPENING-SEARCH(_problem_) __returns__ a solution, or failure
 __for__ _depth_ = 0 to ∞ __do__
   _result_ ← DEPTH\-LIMITED\-SEARCH(_problem_,_depth_)
Expand Down
21 changes: 21 additions & 0 deletions md/Simulated-Annealing.md
@@ -1,5 +1,26 @@
# SIMULATED-ANNEALING

## AIMA4e

__function__ SIMULATED-ANNEALING(_problem_,_schedule_) __returns__ a solution state

 _current_ ← _problem_.INITIAL\-STATE
 __for__ _t_ = 1 __to__ ∞ __do__
   _T_ ← _schedule(t)_
   __if__ _T_ = 0 __then return__ _current_
   _next_ ← a randomly selected successor of _current_
   _ΔE_ ← VALUE(_next_) - VALUE(_current_)
   __if__ _ΔE_ > 0 __then__ _current_ ← _next_
&emsp;&emsp;&emsp;__else__ _current_ &larr; _next_ only with probability e<sup>_&Delta;E_/_T_</sup>

---
__Figure 4.6__ The simulated annealing algorithm, a version of stochastic hill climbing where
some downhill moves are allowed. The schedule input determines the value of the “temper-
ature” T as a function of time; higher temperatures early in the schedule mean that downhill
moves are accepted more readily; late in the schedule with low temperatures, downhill moves
are mostly rejected.


## AIMA3e
__function__ SIMULATED-ANNEALING(_problem_,_schedule_) __returns__ a solution state
&emsp;__inputs__: _problem_, a problem
Expand Down
14 changes: 14 additions & 0 deletions md/Successors.md
@@ -0,0 +1,14 @@
# Successors

## AIMA4e


__function__ SUCCESSORS(_problem_, _parent_) __returns__ an action
&emsp;_s_ &larr; _parent_.state
&emsp;_nodes_ &larr; an empty list
&emsp;__for__ _action_ in _problem_.actions(_s_) __do__
&emsp;&emsp;&emsp;_s'_ &larr; _problem_.result(s,_action_)
&emsp;&emsp;&emsp;_cost_ &larr; _parent_.pathCost + _problem_.stepCost(_s, action, s′_ )
&emsp;&emsp;&emsp;_node_ &larr; Node(state = _s'_, parent = _parent_, action = _action_, pathCost = _cost_)
&emsp;&emsp;&emsp;add _node_ to _nodes_
&emsp;__return__ _nodes_
23 changes: 23 additions & 0 deletions md/Uniform-Cost-Search.md
@@ -1,5 +1,28 @@
# UNIFORM-COST-SEARCH

## AIMA4e

__function__ UNIFORM-COST-SEARCH(_problem_) __returns__ a solution, or failure
&emsp;__if__ problem's initial state is a goal __then return__ empty path to initial state
&emsp;_frontier_ &larr; a priority queue ordered by pathCost, with a node for the initial state
&emsp;_reached_ &larr; a table of {_state_: the best path that reached _state_}; initially empty
&emsp;_solution_ &larr; failure
&emsp;__while__ _frontier_ is not empty __and__ top(_frontier_) is cheaper than _solution_ __do__
&emsp;&emsp;&emsp;_parent_ &larr; pop(_frontier_)
&emsp;&emsp;&emsp;__for__ _child_ __in__ successors(_parent_) __do__
&emsp;&emsp;&emsp;&emsp;&emsp;_s_ &larr; _child_.state
&emsp;&emsp;&emsp;&emsp;&emsp;__if__ _s_ is not in _reached_ __or__ _child_ is a cheaper path than _reached_[_s_] __then__
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;_reached_[_s_] &larr; _child_
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;add _child_ to the _frontier_
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;__if__ _child_ is a goal and is cheaper than _solution_ __then__
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;_solution_ = _child_
&emsp;__return__ _solution_

---
__Figure 3.11__ Uniform-cost search on a graph. Finds optimal paths for problems with vary-
ing step costs.


## AIMA3e
__function__ UNIFORM-COST-SEARCH(_problem_) __returns__ a solution, or failure
&emsp;_node_ &larr; a node with STATE = _problem_.INITIAL\-STATE, PATH\-COST = 0
Expand Down

0 comments on commit 72206d6

Please sign in to comment.