Skip to content

Commit 72206d6

Browse files
authored
Merge pull request aimacode#86 from samagra14/4e_search
Adds 4e algorithms.
2 parents 7d06ab9 + c111831 commit 72206d6

File tree

7 files changed

+116
-1
lines changed

7 files changed

+116
-1
lines changed

md/Breadth-First-Search.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# BREADTH-FIRST-SEARCH
22

3+
## AIMA4e
4+
5+
__function__ BREADTH-FIRST-SEARCH(_problem_) __returns__ a solution, or failure
6+
 __if__ problem's initial state is a goal __then return__ empty path to initial state
7+
 _frontier_ ← a FIFO queue initially containing one path, for the _problem_'s initial state
8+
 _reached_ ← a set of states; initially empty
9+
 _solution_ ← failure
10+
 __while__ _frontier_ is not empty __do__
11+
   _parent_ ← the first node in _frontier_
12+
   __for__ _child_ __in__ successors(_parent_) __do__
13+
     _s_ ← _child_.state
14+
     __if__ _s_ is a goal __then__
15+
       __return__ _child_
16+
     __if__ _s_ is not in _reached_ __then__
17+
       add _s_ to _reached_
18+
       add _child_ to the end of _frontier_
19+
 __return__ _solution_
20+
21+
---
22+
__Figure 3.9__ Breadth-first search algorithm.
23+
24+
325
## AIMA3e
426
__function__ BREADTH-FIRST-SEARCH(_problem_) __returns__ a solution, or failure
527
 _node_ ← a node with STATE = _problem_.INITIAL\-STATE, PATH\-COST = 0

md/Depth-Limited-Search.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# DEPTH-LIMITED-SEARCH
22

3+
## AIMA4e
4+
5+
__function__ DEPTH-LIMITED-SEARCH(_problem_, _l_) __returns__ a solution, or failure, or cutoff
6+
 _frontier_ ← a FIFO queue initially containing one path, for the _problem_'s initial state
7+
 _solution_ ← failure
8+
 __while__ _frontier_ is not empty __do__
9+
   _parent_ ← pop(_frontier_)
10+
   __if__ depth(_parent_) > l __then__
11+
     _solution_ ← cutoff
12+
     __else__
13+
       __for__ _child_ __in__ successors(_parent_) __do__
14+
         __if__ _child_ is a goal __then__
15+
           __return__ _child_
16+
         add _child_ to __frontier__
17+
 __return__ _solution_
18+
19+
---
20+
__Figure 3.14__ An implementation of depth-limited tree search. The algorithm has two dif-
21+
ferent ways to signal failure to find a solution: it returns failure when it has exhausted all
22+
paths and proved there is no solution at any depth, and returns cutoff to mean there might be
23+
a solution at a deeper depth than l. Note that this algorithm does not keep track of reached
24+
states, and thus might visit the same state multiple times on different paths.
25+
326
## AIMA3e
427
__function__ DEPTH-LIMITED-SEARCH(_problem_,_limit_) __returns__ a solution, or failure/cutoff
528
 __return__ RECURSIVE\-DLS(MAKE\-NODE(_problem_.INITIAL\-STATE),_problem_,_limit_)

md/Hill-Climbing.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# HILL-CLIMBING
22

3+
## AIMA4e
4+
5+
__function__ HILL-CLIMBING(_problem_) __returns__ a state that is a local maximum
6+
 _current_ ← _problem_.INITIAL\-STATE
7+
 __loop do__
8+
   _neighbor_ ← a highest\-valued successor of _current_
9+
   _if_ VALUE(_neighbour_) ≤ VALUE(_current_) __then return__ _current_
10+
   _current_ ← _neighbor_
11+
12+
---
13+
__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.
14+
315
## AIMA3e
416
__function__ HILL-CLIMBING(_problem_) __returns__ a state that is a local maximum
517
 _current_ ← MAKE\-NODE(_problem_.INITIAL\-STATE)

md/Iterative-Deepening-Search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ITERATIVE-DEEPENING-SEARCH
22

3-
## AIMA3e
3+
## AIMA3e / AIMA4e
44
__function__ ITERATIVE-DEEPENING-SEARCH(_problem_) __returns__ a solution, or failure
55
 __for__ _depth_ = 0 to ∞ __do__
66
   _result_ ← DEPTH\-LIMITED\-SEARCH(_problem_,_depth_)

md/Simulated-Annealing.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# SIMULATED-ANNEALING
22

3+
## AIMA4e
4+
5+
__function__ SIMULATED-ANNEALING(_problem_,_schedule_) __returns__ a solution state
6+
7+
 _current_ ← _problem_.INITIAL\-STATE
8+
 __for__ _t_ = 1 __to__ ∞ __do__
9+
   _T_ ← _schedule(t)_
10+
   __if__ _T_ = 0 __then return__ _current_
11+
   _next_ ← a randomly selected successor of _current_
12+
   _ΔE_ ← VALUE(_next_) - VALUE(_current_)
13+
   __if__ _ΔE_ > 0 __then__ _current_ ← _next_
14+
&emsp;&emsp;&emsp;__else__ _current_ &larr; _next_ only with probability e<sup>_&Delta;E_/_T_</sup>
15+
16+
---
17+
__Figure 4.6__ The simulated annealing algorithm, a version of stochastic hill climbing where
18+
some downhill moves are allowed. The schedule input determines the value of the “temper-
19+
ature” T as a function of time; higher temperatures early in the schedule mean that downhill
20+
moves are accepted more readily; late in the schedule with low temperatures, downhill moves
21+
are mostly rejected.
22+
23+
324
## AIMA3e
425
__function__ SIMULATED-ANNEALING(_problem_,_schedule_) __returns__ a solution state
526
&emsp;__inputs__: _problem_, a problem

md/Successors.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Successors
2+
3+
## AIMA4e
4+
5+
6+
__function__ SUCCESSORS(_problem_, _parent_) __returns__ an action
7+
&emsp;_s_ &larr; _parent_.state
8+
&emsp;_nodes_ &larr; an empty list
9+
&emsp;__for__ _action_ in _problem_.actions(_s_) __do__
10+
&emsp;&emsp;&emsp;_s'_ &larr; _problem_.result(s,_action_)
11+
&emsp;&emsp;&emsp;_cost_ &larr; _parent_.pathCost + _problem_.stepCost(_s, action, s′_ )
12+
&emsp;&emsp;&emsp;_node_ &larr; Node(state = _s'_, parent = _parent_, action = _action_, pathCost = _cost_)
13+
&emsp;&emsp;&emsp;add _node_ to _nodes_
14+
&emsp;__return__ _nodes_

md/Uniform-Cost-Search.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# UNIFORM-COST-SEARCH
22

3+
## AIMA4e
4+
5+
__function__ UNIFORM-COST-SEARCH(_problem_) __returns__ a solution, or failure
6+
&emsp;__if__ problem's initial state is a goal __then return__ empty path to initial state
7+
&emsp;_frontier_ &larr; a priority queue ordered by pathCost, with a node for the initial state
8+
&emsp;_reached_ &larr; a table of {_state_: the best path that reached _state_}; initially empty
9+
&emsp;_solution_ &larr; failure
10+
&emsp;__while__ _frontier_ is not empty __and__ top(_frontier_) is cheaper than _solution_ __do__
11+
&emsp;&emsp;&emsp;_parent_ &larr; pop(_frontier_)
12+
&emsp;&emsp;&emsp;__for__ _child_ __in__ successors(_parent_) __do__
13+
&emsp;&emsp;&emsp;&emsp;&emsp;_s_ &larr; _child_.state
14+
&emsp;&emsp;&emsp;&emsp;&emsp;__if__ _s_ is not in _reached_ __or__ _child_ is a cheaper path than _reached_[_s_] __then__
15+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;_reached_[_s_] &larr; _child_
16+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;add _child_ to the _frontier_
17+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;__if__ _child_ is a goal and is cheaper than _solution_ __then__
18+
&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;_solution_ = _child_
19+
&emsp;__return__ _solution_
20+
21+
---
22+
__Figure 3.11__ Uniform-cost search on a graph. Finds optimal paths for problems with vary-
23+
ing step costs.
24+
25+
326
## AIMA3e
427
__function__ UNIFORM-COST-SEARCH(_problem_) __returns__ a solution, or failure
528
&emsp;_node_ &larr; a node with STATE = _problem_.INITIAL\-STATE, PATH\-COST = 0

0 commit comments

Comments
 (0)