0% found this document useful (0 votes)
6 views40 pages

02 Statespace

Uploaded by

pdreadxlsx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views40 pages

02 Statespace

Uploaded by

pdreadxlsx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

STATE-SPACE MODEL

Gregorics Tibor Artificial intelligence


Modeling & Search

modeling search
path-finding
task solution
problem
graph-representation

State-space model Local searches


Problem reduction model Backtracking search
Problem decomposition model Graph-searches
Constraint-programming model Evolutionary algorithm
Logical models Resolution
Rule-based reasoning
Gregorics Tibor Artificial intelligence
What does the modeling focus on?

❑ Problem space: contains the possible answers.


❑ Goal: finding correct answers (solutions).
❑ Ideas that help the search:
- Restricting the problem space: feasible answers
- Selecting an initial item of the problem space.
- Defining neighborhood relationships between the items
of the problem space:
• It helps to go through the problem space systematically.
- Ranking the currently available items of the problem
space during its traversal
Gregorics Tibor Artificial intelligence
Travelling salesman problem
The traveling salesman must visit every city in his territory
exactly once and then return home covering the optimal total
cost. (n cities and cost of each pair of cities are known)
A n (n-1)!
4 2
E 1 B 5 24
11
3 1 9 50 6⸱1062
1
D 5 C possible solutions:
ABCDEA
ACBDEA ABDCEA ABCEDA
ABDECA
problem space
ADBECA …

Gregorics Tibor Artificial intelligence


Travelling salesman problem
The traveling salesman must visit every city in his territory
exactly once and then return home covering the optimal total
cost. (n cities and cost of each pair of cities are known)
A
start: ABCDEA
4 2 2+9+5+3+4=23
E 1 B
11
3 1 9
1 ACBDEA ABDCEA ABCEDA
D 5 C
1+9+1+3+4=18 2+1+5+1+4=13 2+9+1+3+1=16
AEDCBA
AEDBCA ABDECA
ACEDBA 2+1+3+1+1=8
ACEBDA ADBECA …
unnecessary 1+1+1+1+1=5
Gregorics Tibor Mesterséges intelligencia
Path-finding problems

❑ Using an appropriate model, the problem space of a path-


finding problem can be treated as an arc-weighted, directed
graph, where the items of the problem space are
represented by either nodes or paths. This graph might be
infinite but the number of the outgoing arcs of each node is
always finite, and there is a positive constant lower bound
(δ) on the cost of the edges (δ-graph).
❑ In order to solve these problems either a special goal node
or a path driving from a start node to any goal node must
be found. (Sometimes the optimal path is needed.)

Gregorics Tibor Artificial intelligence


Graph notations 1.

▪ nodes, arcs N, ANN (infinite)


▪ arc from n to m (n,m)A (n,mN)
▪ children of n (n) = {mN(n,m)A}
▪ parents of n (n)  (n) = {mN(m,n)A}
▪ directed graph R=(N,A)
▪ finite outgoing arcs  (n) <  (nN)
▪ cost of arc c:A→ℝ
▪ -property (ℝ+) c(n,m)   > 0 (n,m)A
▪ -graph directed, arc-weighted, -property,
finite outgoing arcs from a node
Gregorics Tibor Artificial intelligence
Graph notations 2.
▪ directed path  = (n,n1),(n1,n2),...,(nk-1,m)
= <n,n1,n2,...,nk-1,m>
It is correct in spite of n⟶ m, n⟶ m, n⟶M (MN)
infinite number of paths
since we have -graphs. {n⟶m}, {n⟶M } (MN)
If no path, it is infinite.
▪ length of a path 
▪ cost of a path c(n,m):=i c(ni-1,ni)
▪ optimal cost c*(n,m):= min{n⟶m} c(n,m)
c*(n,M):= min{n⟶M} c(n,m)
▪ optimal path n⟶* m := minc {   {n⟶m} }
n⟶* M := minc {   {n⟶M} }
Gregorics Tibor Artificial intelligence
Definition of graph-representation

❑ All path-finding problems can be described with a


graph-representation. It is a triple (R, s, T) where
– R=(N, A, c) is a -graph (representation graph)
– sN is the start node
– TN is the set of goal nodes.
❑ Solution of the problem:
− finding a goal node: tT
− finding a path s ⟶ T or an optimal path s ⟶* T
directed path from s to the cheapest directed path from s
one of the nodes of T to one of the nodes of T
Gregorics Tibor Artificial intelligence
Search

❑ Only special path-finding algorithms can find solution


paths in a huge graph.
− It starts from the start node that is the first current
node.
− In each step it selects a new current node among the
children of the previous current node(s) in non-
deterministic way.
− It can store the subpart of the discovered part of the
representation graph.
− It stops when it detects the goal node.

Gregorics Tibor Artificial intelligence


Search-system

Procedure Search-system
1. DATA := initial value
2. while termination condition(DATA) loop
3. SELECT R FROM rules that can be applied
4. DATA := R(DATA)
5. endloop
end

Gregorics Tibor Artificial intelligence


Search-system

global workspace
stores the part of knowledge acquired
Procedure Search-system that is useful to preserve
(initial value, termination condition)
1. DATA := initial value
2. while termination condition(DATA) loop
3. SELECT R FROM rules that can be applied
4. DATA := R(DATA) searching rules
5. endloop can change the content
of the workspace
end control strategy (precondition, effect)
selects an appropriate rule
(general principle + heuristics)

Gregorics Tibor Artificial intelligence


Examination of search-system
❑ soundness
• the answer is correct if the search terminates
❑ completeness
• the search guarantees the solution if there exists a solution
❑ optimality
• the search gives optimal solution
❑ time complexity
• number of the iterations and running time of one iteration
❑ space complexity
• size of the workspace
Gregorics Tibor Artificial intelligence
Concept of state-space model

❑ State-space: set of states, where one state is a collection


of values belonging to the data (objects) that are needed
to describe the problem
− the state-space can be defined as a subset of a base-set by
a so-called invariant statement.
❑ Operators: map from the state-space to the state-space
− step from a state to another state
− defined with its precondition and effect
❑ Initial state(s) or its description (initial condition)
❑ Final state(s) or its description (goal condition)
Gregorics Tibor Artificial intelligence
Graph-representation
of state-space model
❑ State-space model State-graph
▪ state node
▪ effect of an operator on a state directed arc
▪ cost of an operator cost of arc
▪ initial state start node
▪ final state goal node
❑ Graph-representation:
state-graph, start node, goal nodes
▪ sequence of operators directed path
▪ solution representation graph, directed path
δ-graph from start to goal
Gregorics Tibor Artificial intelligence
Hanoi tower problem
1 2 3 initial state final state 1 2 3
[3,3,3] [1,1,1]
1 1
2 2
3 3
set of all possible n length sequences (arrays)
State-space: ST = {1,2,3}n where the elements may be 1, 2 or 3.
Operator: Move(from, to): ST → ST from, to{1,2,3}
IF ‘from’ and ‘to’ are valid and different pegs
and there is a disc on ‘from’
and ‘to’ is either empty or its upper disc is greater than the
disc we want to move (this is the upper disc on ‘from’)
THEN this[the upper disc on ‘from’]:= to
Gregorics Tibor this is the current state Artificial intelligence
start
[3,3,3]
State-graph
[2,3,3] [1,3,3] Possible solutions are the
paths driving from start
[2,1,3] [1,2,3]

[1,1,3] [2,2,3]
[3,1,3] [3,2,3]
[1,1,2] [2,2,1]

[3,1,2] [2,1,2] [1,2,1] [3,2,1]

[3,2,2] [2,3,2] [1,3,1] [3,1,1]

[2,2,2] [1,1,1]
goal
[1,2,2] [1,3,2] [3,3,2] [3,3,1] [2,3,1] [2,1,1]
State-space vs. problem space

❑ The elements of the problem space can be symbolized with


the paths driving from the start node in the state-graph.
❑ There is a very close relationship between the state-space
and the problem space, but the state-space is not identical to
the problem space.
• In many cases (just in the Hanoi tower problem) the elements of the
problem space are not the states (nodes) but the sequences of
operators (paths driving from the start node) and some of them are
the solutions.
• Sometimes the solution might be only one state but a sequence of the
operators (path) is needed to achieve it.

Gregorics Tibor Artificial intelligence


Complexity of state-graph

complexity size of computational


of state-graph problem space cost of search

❑ number of paths driving from the start depends on

▪ number of nodes and arcs

▪ branching factor: average number of outgoing arcs

▪ frequency of the cycles and diversity of their length

Gregorics Tibor Artificial intelligence


♛ n-queens problem 1.

general state final state


♛ ♛

♛♛ ♛
♛ ♛
two dimensional array (n×n matrix)
State-pace: ST = {♛, _ }n×n where its elements may be ♛ or _
invariant: number of queens (♛) = n
Operator: Change(x,y,u,v): ST → ST x,y,u,v[1.. n] (this:ST)
IF 1≦ x,y,u,v ≦n and this[x,y]=♛ and this[u,v]=_
THEN this[x,y]  this[u,v]
swap
Gregorics Tibor Artificial intelligence
State-graph
♛♛




♛ ♛ ♛ ♛
♛ ♛ ♛ ♛
♛ ♛ ♛
♛ ♛ ♛

♛ ♛ ♛
♛ ♛ ♛
♛ ♛ ♛
♛ ♛ ♛
number of nodes: n 2 
 n 
 

branching factor: n*(n2−n) ♛



number of the outgoing paths from any node ♛

with k length : (n*(n2−n)) k
Gregorics Tibor Artificial intelligence
Reduce the problem space

❑ A problem may have several models:


the best model = the smallest problem space
o In the previous representation the size of the problem space is huge.
o Expand the state space with the states containing less queens than n,
and use a new operator: put a new queen on the board (the initial
state is the empty board).
o The state-graph can be further reduced with limiting the
precondition of the new operator (decreasing the branching factor):
- Put the queens on the board row by row.
- A new queen is never put on the board if it would be under
attack.

Gregorics Tibor Artificial intelligence


♛♛ n-queens problem 2.
initial state general state final state
♛ ♛
♛ ♛


State-space: ST = {♛, _ }n×n
invariant: number of queens (♛)  n and
only in the first few rows can be found one-one queen
Operator: Put(col): ST → ST col[1.. n] (this: ST)
IF 1≦ col ≦n and number of queens < n and there is no attack
THEN this[row,col] := ♛ where „row” is the next empty row

Gregorics Tibor Artificial intelligence


number of nodes < (nn+1−1)/(n−1)
State-graph start
branching factor: n
number of possible solutions < nn
♛ ♛

♛ ♛ ♛ ♛ ♛ ♛ ♛ ♛
♛ ♛ ♛ ♛ ♛ ♛ ♛ ♛

♛ ♛ ♛ ♛
♛ ♛ ♛ ♛ ♛
♛ ♛ ♛ ♛♛ ♛ ♛ ♛ ♛
♛ ♛ ♛ ♛
♛ ♛ ♛ ♛

goal
♛ ♛ ♛ ♛ ♛ ♛ ♛
♛ ♛ ♛ ♛ ♛ ♛ ♛
♛ ♛ ♛ ♛ ♛ ♛ ♛
♛ ♛ ♛ ♛ ♛ ♛ ♛
Gregorics Tibor Artificial intelligence
Computational cost of the operator
❑ The computational complexity of an operator can be reduced
if the states are completed with extra information that are
maintained by the operator itself.
❑ For example
o The position of the next empty row can be stored in a state. It
may be increased after placing a new queen instead of
computing it over and over.
o To avoid the attacks on the chessboard the empty squares that
are under attack (not free) might be annotated in order to check
easily whether a queen is allowed to place on that square. In
this way there will be three kinds of squares: free, under attack
and occupied by queen.

Gregorics Tibor Artificial intelligence


♛♛♛ n-queens problem 3.
initial state: general state: final state:
next_row = 1 next_row = 3 next_row = 5
♛    ♛ 
  ♛   ♛
    ♛  
     ♛
State-space: ST = rec( board: {♛,  , _ }n×n , next_row: ℕ)
invariant: only next_row−1 queens are on the board
in its first next_row−1 rows one by one,
next_row ≦ n+1,
no attacks,
notations:  denotes the empty square under attack
_ denotes the free square
Gregorics Tibor Artificial intelligence
♛♛♛ n-queens problem 3.
Operator:
Put(col): ST → ST col[1.. n] (this: ST)
IF 1≦ col ≦n and this. next_row ≦ n time complexity
and this.board[this. next_row,col]= _ of precondition
THEN this.board[this.next_row, col] := ♛ is constant
i[this. next_row+1..n]:
this.board[i,col]:=
this.board[i,i−this.next_row+col]:=
this.board[i, this.next_row+col−i]:=
this.next_row:= this.next_row+1 time complexity
Initial: this.board is empty, this.next_row:=1 of effect is linear
goal condition becomes very simple
Final: this.next_row=n+1

Gregorics Tibor Artificial intelligence


start
state-graph
♛   ♛   ♛   ♛
   
       
     

♛   ♛   ♛   ♛   ♛   ♛
 ♛   ♛   ♛ ♛   ♛   ♛ 
       
           

♛   ♛   ♛   ♛
  ♛   ♛ ♛   ♛  
♛  ♛     ♛  ♛
     

♛   ♛
  ♛ goal ♛  
♛     ♛
 ♛ ♛ 
Gregorics Tibor Artificial intelligence
8-puzzle

initial state: 2 8 3 1 2 3 final state:

1 6 4 8 4
7 5 7 6 5
State-space: ST =rec(table:{0..8}3×3, empty:{1..3}×{1..3})
invariant: the elements of the table is a permutation of 0 .. 8
empty gives the coordinates of the empty cell that is
denoted with 0 it is computed
coordinate
Operator: Move(dir): ST → ST (this: ST) by coordinate

IF dir∊{(0,-1),(-1,0),(0,1),(1,0)} and (1,1)≦this.empty+dir≦ (3,3)


THEN this.table[this.empty]  this.table[this.empty+dir]
this.empty := this.empty+dir
Gregorics Tibor Artificial intelligence
start 2 8 3
1 6 4
7 5
state-graph
2 8 3 2 8 3 2 8 3
1 6 4 1 4 1 6 4
7 5 7 6 5 7 5

2 8 3 2 8 3 2 3 2 8 3 2 8 3
6 4 1 4 1 8 4 1 4 1 6
1 7 5 7 6 5 7 6 5 7 6 5 7 5 4

8 3 2 8 3 8 3 2 8 3 2 3 2 3 2 8 2 8 3 2 8 3 2 8
2 6 4 6 4 2 1 4 7 1 4 1 8 4 1 8 4 1 4 3 1 4 5 1 6 1 6 3
1 7 5 1 7 5 7 6 5 6 5 7 6 5 7 6 5 7 6 5 7 6 7 5 4 7 5 4

8 3 2 8 3 1 2 3 2 3 4 2 8 3 2 8 3
2 1 4 7 1 4 8 4 1 8 1 4 5 1 5 6
7 6 5 6 5 7 6 5 7 6 5 7 6 7 4

goal
8 1 3 8 3 1 2 3 1 2 3 2 8 3 2 8 3 2 8 3
2 4 2 1 4 8 4 7 8 4 1 4 5 1 5 1 5 6
7 6 5 7 6 5 7 6 5 6 5 7 6 7 4 6 7 4

8 1 3 1 3 1 3 2 8 3
2 4 8 2 4 8 2 4 1 5
7 6 5 7 6 5 7 6 5 7 4 6
Black&White puzzle

There are n black and m white stones and one empty place in a linear frame
with n+m+1 length. A stone can slide to the adjacent empty place or it can
jump over one stone onto an empty place. Initially black stones precede the
white stones. Let’s reverse the order of black and white stones!
State-space: ST =rec(s : {B, W,_}n+m+1, pos : [1.. n+m+1])
invariant: pos is the index of the single empty place, the number of B is n,
and the number of W is m
Operators: MoveLeft, MoveRight, JumpLeft, JumpRight
e.g.: MoveLeft : ST → ST (empty space is moved)
IF this.pos1 (this : ST)
THEN this.s[this.pos-1]  this.s[this.pos] ; this.pos := this.pos-1
Initial: [B, … , B, W, … , W, _ ]
Final: i,j [1.. n+m+1], i<j : (this.s[i]=B  this.s[j]=W)
Gregorics Tibor Artificial intelligence
state-graph of Black&White puzzle
start

goal

goal
goal goal
Gregorics Tibor Artificial intelligence
Travelling salesman problem
The traveling salesman must visit every city in his territory
exactly once and then return home covering the optimal total
cost. (n cities and cost of each pair of cities are known)
A n (n-1)!
4 2
E 1 B 5 24
11
3 1 9 50 6⸱1062
1
D 5 C possible solutions:
ABCDEA
ACBDEA ABDCEA ABCEDA
ABDECA
problem space
ADBECA …

Gregorics Tibor Artificial intelligence


Travelling salesman problem
The traveling salesman must visit every city in his territory exactly
once and then return home (n cities and cost of each pair of cities are
known) covering the optimal total cost.

*
State-space: ST = {cities} (set of finite sequences of cities
without home city)
Operator: Goto(city): ST → ST city∊{cities}
IF  this.contains(city) (this: ST )
THEN this.append(city)
Initial state: <> (empty sequence)
Final state:  this =n‒1 (length of this is n)

Gregorics Tibor Artificial intelligence


state-graph of travelling salesman
<> start

<B> <C> <D> <E>

<BC> <BD> <BE> <CB> <CD> <CE> <DB> <DC> <DE> <EB> <EC> <ED>

… <CBD> <CBE> … <DBC> <DBE> … <EBC> <EBD> …


<BCD> <BCE>

<BCDE> … <CBDE> … <DBCE> … …


<EBCD>

Gregorics Tibor Artificial intelligence


SAT – satisfiability problem
There is given a Boolean statement in CNF with n variables. Find a
vector of truth assignments for the variables so that the formula be
true.
E.g.: F(x1, …, x5) = (x1x2 x5)  (x1x3)  (x1 x4)  (x2 x5)
possible solution: x1 = true, x2 = any, x3 = any, x4 = true, x5 = true
State-space: ST = 𝕃n
Operator: Change(i): ST → ST i∊[1..n] (this : ST )
this[i] := this[i]
Initial state: arbitrary
Final state: F(this) is true

Gregorics Tibor Artificial intelligence


SAT – satisfiability problem 2.
There is given a Boolean statement in CNF with n variables. Find a
vector of truth assignments for the variables so that the formula be
true.
n
State-space: ST = rec(t : {true, false, ∅} , i : ℕ , count : ℕ)
invariant: 0  i  n, j{1…i}: t[j] ≠∅
count ( C) = the number of the clauses having true value
Operator:
True: ST → ST False: ST → ST (this : ST)
i := i+1: this.t[i] := true i := i+1: this.t[i] := false
update(this.count) update(this.count)
Initial state: ([∅, … , ∅] , 0, 0)
Final state: this.count=C
Gregorics Tibor Artificial intelligence
C Block world problem
A B
There are some blocks (A,B,C,…). A robot arm can move the blocks:
pickup, putdown, stack, unstack. Let’s build a given formation!
State-space: ST = set(ground literals)
ground literals={ontable(A), on(C,B), clear(C), … } where the following
predicates occur : ontable(x), on(x,y), clear(x), handempty, holding(x)

invariant: all states are consistent (e.g.: on(C,B) and clear(B) is impossible)

Initial: { ontable(A), clear(A), ontable(B), on(C,B), clear(C), handempty }


Final: { on(A,B), on(B,C) }

Gregorics Tibor Artificial intelligence


C Operators of block world problem
A B

Pickup(x): ST → ST x ∊ {A,B,C,…} (this : ST)


IF ontable(x),clear(x),handempty  this
THEN this := this −{ontable(x),clear(x),handempty }{holding(x)}
Putdown(x): ST → ST x ∊ {A,B,C,…} (this : ST)
IF holding(x) this
THEN this := this −{holding(x)}{ontable(x),clear(x),handempty}
Stack(x,y): ST → ST x, y ∊ {A,B,C,…} (this : ST)
IF holding(x), clear(y) this
THEN this := this −{holding(x), clear(y)}{on(x,y),clear(x),handempty}
Unstack(x,y): ST → ST x, y ∊ {A,B,C,…} (this : ST)
IF on(x,y),clear(x),handempty  this
THEN this := this −{on(x,y),clear(x),handempty}{holding(x), clear(y)}

Gregorics Tibor Artificial intelligence


state-graph

A A
C B
B B C A C

start
C B
C
A B A B A B C A C

A
A B
B B
goal C C A C

Gregorics Tibor Artificial intelligence

You might also like