- 8-Puzzle
- State space
S
- a set of all unique-sequenced
array[0..8] of 0..8
indicating the digit on each position in the frame, with0
representing the missing tile
- a set of all unique-sequenced
- Initial state
s_0 ∈ S
- Set of goal states
S_G ⊆ S
S_G
={[1,2,3,4,5,6,7,8,0]}
-
``` A(s) = { <s, s'> | s' = s.swap(s.indexof(0), s.indexof(0)-1) /\ s,s' ∈ S } ∪ { <s, s'> | s' = s.swap(s.indexof(0), s.indexof(0)+1) /\ s,s' ∈ S } ∪ { <s, s'> | s' = s.swap(s.indexof(0), s.indexof(0)-3) /\ s,s' ∈ S } ∪ { <s, s'> | s' = s.swap(s.indexof(0), s.indexof(0)+3) /\ s,s' ∈ S } ```
- Transition function
f(s, a)
fors ∈ S
anda ∈ A(s)
f(s, <s, s'>) = s'
- Cost of each action
c(a, s)
fors ∈ S
anda ∈ A(s)
c(a, s) = 1
fors ∈ S
anda ∈ A(s)
- State space
- Travelling Salesman Problem
- Consider a set of cities
V
to visit in any order, a starting city locationv_start
, and a set of edgesE
specifying if there’s an edge from two cities<v, v'>
- State space
S
S = { <v_current, V_current> | v_current ∈ V, V_current ⊆ V }
- Initial state
s_0 ∈ S
- if needing to return to the first city
s_0 = <v_start, V>
- or
s_0 = <v_start, {}>
- if not needing to return to the first city
s_0 = <v_start, V - {v_start}>
- or
s_0 = <v_start, {v_start}>
- if needing to return to the first city
- Set of goal states
S_G ⊆ S
{ <v, {}> | v ∈ V }
- or
{ <v, V> | v ∈ V }
- Applicable actions function
A(s)
for each states ∈ S
A(s) = { <v, v'> | <v, v'> ∈ E }
- Transition function
f(s, a)
fors ∈ S
anda ∈ A(s)
f(<v_current, V_current>, <v_current, v'>) = <v', V_current - {v'}>
- or
f(<v_current, V_current>, <v_current, v'>) = <v', V_current ∪ {v'}>
- Cost of each action
c(a, s)
fors ∈ S
anda ∈ A(s)
- State space
- Consider a set of cities
- Is
h
admissible?- yes
h (s_1)
= 4 <h* (s_1)
= 6h (s_2)
= 3 <h* (s_2)
= 5h (s_3)
= 5 <h* (s_3)
= 10h (s_4)
= 3 <h* (s_4)
= 5h (s_5)
= 2 <h* (s_5)
= 3h (s_6)
= 2 <h* (s_6)
= 4h (s_7)
= 0 <=h* (s_7)
= 0
- yes
- Is
h
consistent?- yes
h(s_1) - h(s_2)
= 1 < 2h(s_1) - h(s_3)
= -1 < 2h(s_1) - h(s_4)
= 1 <= 1h(s_2) - h(s_5)
= 1 < 2h(s_3) - h(s_7)
= 5 < 10h(s_4) - h(s_6)
= 1 <= 1h(s_5) - h(s_7)
= 2 < 3h(s_6) - h(s_7)
= 2 < 4
- yes
- iterations
- iteration 1
- OPEN
n_1 = <s_1, 4, 0, nil>
- OPEN
- iteration 2
- OPEN
n_2 = <s_2, 5, 2, s_1>
n_3 = <s_3, 7, 2, s_1>
n_4 = <s_4, 4, 1, s_1>
- CLOSED
n_1 = <s_1, 4, 0, nil>
- OPEN
- iteration 3
- OPEN
n_2 = <s_2, 5, 2, s_1>
n_3 = <s_3, 7, 2, s_1>
n_5 = <s_6, 4, 2, s_4>
- CLOSED
n_1 = <s_1, 4, 0, nil>
n_4 = <s_4, 4, 1, s_1>
- OPEN
- iteration 4
- OPEN
n_2 = <s_2, 5, 2, s_1>
n_3 = <s_3, 7, 2, s_1>
n_6 = <s_7, 6, 6, s_6>
- CLOSED
n_1 = <s_1, 4, 0, nil>
n_4 = <s_4, 4, 1, s_1>
n_5 = <s_6, 4, 2, s_4>
- OPEN
- iteration 5
- OPEN
n_3 = <s_3, 7, 2, s_1>
n_6 = <s_7, 6, 6, s_6>
n_7 = <s_5, 6, 4, s_2>
- CLOSED
n_1 = <s_1, 4, 0, nil>
n_4 = <s_4, 4, 1, s_1>
n_5 = <s_6, 4, 2, s_4>
n_2 = <s_2, 5, 2, s_1>
- OPEN
- iteration 6
- OPEN
n_3 = <s_3, 7, 2, s_1>
n_7 = <s_5, 6, 4, s_2>
- CLOSED
n_1 = <s_1, 4, 0, nil>
n_4 = <s_4, 4, 1, s_1>
n_5 = <s_6, 4, 2, s_4>
n_2 = <s_2, 5, 2, s_1>
n_6 = <s_7, 6, 6, s_6>
- OPEN
- iteration 1
- path
s_1
->s_4
->s_6
->s_7
- Is this the optimal plan? Has the algorithm proved this?
- yes, as
h
is admissible. If there is a cheapest path then it should have already been expanded due to its smallerf
value
- yes, as