02 search problems
-
Upload
nour-zeineddine -
Category
Entertainment & Humor
-
view
190 -
download
0
description
Transcript of 02 search problems
11
Search ProblemsSearch Problems
Explorating AlternativesExplorating Alternatives
R&N: Chap. 3, Sect. 3.1–2 + 3.6R&N: Chap. 3, Sect. 3.1–2 + 3.6
22
Example: 8-PuzzleExample: 8-Puzzle
1
2
3 4
5 6
7
8 1 2 3
4 5 6
7 8
Initial state Goal state
Search is about the exploration of alternatives
33
Exploratory search is an old idea: Exploratory search is an old idea: The Labyrinth and the Ariadne ThreadThe Labyrinth and the Ariadne Thread
According to Greek mythology, Theseus came to Crete to slay the Minotaur, a monster who lived in a Labyrinth. Ariadne gave Theseus a ball of yarn which he unwound as he entered the Labyrinth. After killing the Minotaur, Theseus traced the thread back to the entrance of the Labyrinth, rejoined Ariadne, and successfully escaped Crete
44
Since the dawn of civilization, puzzles and Since the dawn of civilization, puzzles and games that require the exploration of games that require the exploration of alternative paths have fascinated mankind alternative paths have fascinated mankind and have been considered a challenge for and have been considered a challenge for human intelligencehuman intelligence
ChessChess originated in Persia and India originated in Persia and India about 4000 years ago about 4000 years ago
CheckersCheckers appeared as early as 1600 B.C appeared as early as 1600 B.C in Egyptian paintingsin Egyptian paintings
GoGo originated in China over 3000 years originated in China over 3000 years agoago
55
66
15-Puzzle15-PuzzleIntroduced in 1878 by Sam Loyd, who dubbed Introduced in 1878 by Sam Loyd, who dubbed himself “America’s greatest puzzle-expert”himself “America’s greatest puzzle-expert”
12
15
11
14
10
13
9
5 6 7 8
4321
77
88
15-Puzzle15-PuzzleSam Loyd offered Sam Loyd offered $1,000$1,000 of his own money to of his own money to the first person who would solve the following the first person who would solve the following problem:problem:
12
14
11
15
10
13
9
5 6 7 8
4321
12
15
11
14
10
13
9
5 6 7 8
4321
?
99
But no one ever won the prize !!But no one ever won the prize !!
1010
8-Puzzle: State Space8-Puzzle: State Space
1
2
3 4
5 6
7
8
1
2
3 4
5 6
7
8
1
2
3 4
5 6
7
8
1
2
3 4
5 6
78
...
1111
8-Puzzle: Successor Function8-Puzzle: Successor Function
1
2
3 4
5 6
7
8
1
2
3 4
5
6
78
1
2
3 4
5 6
78
1
2
3 4
5 6
78
1212
Stating a Problem as Stating a Problem as a Search Problema Search Problem
State space S Successor function: x ∈ S → SUCCESSORS(x) ∈ 2S
Arc cost Initial state s0
Goal test: x∈S → GOAL?(x) =T or F
S1
3 2
1313
State GraphState Graph It is defined as follows:It is defined as follows:
• Each state is represented by a distinct Each state is represented by a distinct nodenode
• An arc connects a node s to a node s’ if An arc connects a node s to a node s’ if s’ s’ ∈∈ SUCCESSORSSUCCESSORS(s) (s)
The state graph may contain more than The state graph may contain more than one connected componentone connected component
1414
1515
Solution to the Search ProblemSolution to the Search Problem A A solutionsolution is a path connecting the initial is a path connecting the initial
node to a goal node (any one)node to a goal node (any one)
1616
1717
Solution to the Search ProblemSolution to the Search Problem A A solutionsolution is a path connecting the initial is a path connecting the initial
to a goal node (any one)to a goal node (any one) The The costcost of a path is the sum of the of a path is the sum of the
edge costs along this pathedge costs along this path An An optimaloptimal solution is a solution path of solution is a solution path of
minimum costminimum cost There might be no solution !There might be no solution !
1818
1919
How big is the state space of How big is the state space of the (nthe (n22-1)-puzzle?-1)-puzzle?
8-puzzle 8-puzzle 9! = 362,880 states 9! = 362,880 states 15-puzzle 15-puzzle 16! ~ 1.3 x 10 16! ~ 1.3 x 101212 states states 24-puzzle 24-puzzle 25! ~ 10 25! ~ 102525 states states
But But only halfonly half of these states are of these states are reachable from any given statereachable from any given state
2020
Let the goal be:Let the goal be:
Let nLet nii be the number of tiles j < i that appear after tile i be the number of tiles j < i that appear after tile i(from left to right and top to bottom)(from left to right and top to bottom)
N = nN = n22 + n + n33 + + …… + n + n15 15 + row number of empty tile+ row number of empty tile
Permutation InversionsPermutation Inversions
121511
1410
1395 6 7 8
4321
121511
146
1395 10 7 8
4321 n2 = 0 n3 = 0 n4 = 0n5 = 0 n6 = 0 n7 = 1n8 = 1 n9 = 1 n10 = 4n11 = 0 n12 = 0 n13 = 0n14 = 0 n15 = 0
N = 7 + 4
2121
Proposition: (N mod 2) is invariant under Proposition: (N mod 2) is invariant under any legal move of the empty tileany legal move of the empty tile
Proof:Proof:• Any horizontal move of the empty tile Any horizontal move of the empty tile
leaves N unchangedleaves N unchanged• A vertical move of the empty tile changes A vertical move of the empty tile changes
N by an even incrementN by an even increment
121511
1410
1395 6 7
8
4321
s =
1215
11
1410
1395 6 7
8
4321
s’ = N(s’) = N(s) + 3 + 1
2222
Proposition: (N mod 2) is invariant under Proposition: (N mod 2) is invariant under any legal move of the empty tileany legal move of the empty tile
For a goal state g to be reachable For a goal state g to be reachable from a state s, a necessary condition is from a state s, a necessary condition is that N(g) and N(s) have the same paritythat N(g) and N(s) have the same parity
It can be shown that this is also a It can be shown that this is also a sufficient conditionsufficient condition
The state graph consists of two The state graph consists of two connected components of equal sizeconnected components of equal size
2323
So, the second state is So, the second state is not reachable from the not reachable from the first, and Sam Loyd took first, and Sam Loyd took no risk with his money ...no risk with his money ...
15-PuzzleSam Loyd offered $1,000 of his own money to the first person who would solve the following problem:
12
14
11
15
10
13
9
5 6 7 8
4321
12
14
11
15
10
13
9
5 6 7 8
4321
12
15
11
14
10
13
9
5 6 7 8
4321
?12
15
11
14
10
13
9
5 6 7 8
4321
12
15
11
14
10
13
9
5 6 7 8
4321
?
N = 4 N = 5
2424
What is the Actual State Space?What is the Actual State Space?• The set of all states? The set of all states?
[e.g., a set of 16! states for the 15-puzzle][e.g., a set of 16! states for the 15-puzzle]• The set of all states from which a given goal The set of all states from which a given goal
state is reachable? state is reachable? [e.g., a set of 16!/2 states for the 15-puzzle][e.g., a set of 16!/2 states for the 15-puzzle]
• The set of all states reachable from a given The set of all states reachable from a given initial state?initial state?
In general, the answer is In general, the answer is a)a)
2525
What is the Actual State Space?What is the Actual State Space?• The set of all states? The set of all states?
[e.g., a set of 16! states for the 15-puzzle][e.g., a set of 16! states for the 15-puzzle]• The set of all states from which a given goal The set of all states from which a given goal
state is reachable? state is reachable? [e.g., a set of 16!/2 states for the 15-puzzle][e.g., a set of 16!/2 states for the 15-puzzle]
• The set of all states reachable from a given The set of all states reachable from a given initial state?initial state?
In general, the answer is a)In general, the answer is a)But a fast test determining whether a state is reachable from another is very useful, as search-based problem solvers are often very inefficient when a problem has no solution
2626
Stating a Problem as Stating a Problem as a Search Problema Search Problem
State space S Successor function: x ∈ S → SUCCESSORS(x) ∈ 2S
Arc cost Initial state s0
Goal test: x∈S → GOAL?(x) =T or F A solution is a path joining the initial to a goal node
S1
3 2
2727
Searching the State SpaceSearching the State Space Often it is not Often it is not
feasible to build feasible to build a complete a complete representation representation of the state of the state graphgraph
2828
8-puzzle 362,880 states
15-puzzle 1.3 x 1012 states
24-puzzle 1025 states
100 millions states/sec
0.036 sec
< 4 hours
> 109 years
8-, 15-, 24-Puzzles8-, 15-, 24-Puzzles
2929
Searching the State SpaceSearching the State Space Often it is not Often it is not
feasible to build feasible to build a complete a complete representation representation of the state of the state graphgraph
A problem solver A problem solver must construct a must construct a solution by solution by exploring a small exploring a small portion of the portion of the graph graph
3030
Searching the State SpaceSearching the State Space
3131
Searching the State SpaceSearching the State Space
Search tree
3232
Searching the State SpaceSearching the State Space
Search tree
3333
Searching the State SpaceSearching the State Space
Search tree
3434
Searching the State SpaceSearching the State Space
Search tree
3535
Searching the State SpaceSearching the State Space
Search tree
3636
Simple Problem-Solving-Agent Simple Problem-Solving-Agent AlgorithmAlgorithm
ss00 sense/read initial state sense/read initial state GOAL? GOAL? select/read goal test select/read goal test Succ Succ select/read successor function select/read successor function solution solution searchsearch(s(s00, GOAL?, Succ) , GOAL?, Succ) perform(solution)perform(solution)
3737
State SpaceState Space Each state is an Each state is an abstractabstract representation representation
of a collection of possible worlds sharing of a collection of possible worlds sharing some crucial properties and differing on some crucial properties and differing on non-important details onlynon-important details onlyE.g.: In assembly planning, a state does not E.g.: In assembly planning, a state does not define exactly the absolute position of each partdefine exactly the absolute position of each part
The state space is The state space is discretediscrete. It may be . It may be finite, or infinitefinite, or infinite
3838
Successor FunctionSuccessor Function It implicitly represents all the actions It implicitly represents all the actions
that are feasible in each statethat are feasible in each state
3939
Successor FunctionSuccessor Function It implicitly represents all the actions It implicitly represents all the actions
that are feasible in each statethat are feasible in each state Only the results of the actions (the Only the results of the actions (the
successor states) and their costs are successor states) and their costs are returned by the functionreturned by the function
The successor function is a “black box”: The successor function is a “black box”: its content is unknownits content is unknownE.g., inE.g., in assembly planning, the function does assembly planning, the function does not say if it only allows two sub-assemblies to not say if it only allows two sub-assemblies to be merged or if it makes assumptions about be merged or if it makes assumptions about subassembly stabilitysubassembly stability
4040
Path CostPath Cost An arc cost is a positive number An arc cost is a positive number
measuring the “cost” of performing the measuring the “cost” of performing the action corresponding to the arc, e.g.:action corresponding to the arc, e.g.:• 1 in the 8-puzzle example1 in the 8-puzzle example• expected time to merge two sub-assembliesexpected time to merge two sub-assemblies
We will assume that for any given We will assume that for any given problem the cost c of an arc always problem the cost c of an arc always verifies: verifies: c c ≥ ≥ εε >> 0 0, where , where εε is a constant is a constant
4141
Path CostPath Cost An arc cost is a positive number An arc cost is a positive number
measuring the “cost” of performing the measuring the “cost” of performing the action corresponding to the arc, e.g.:action corresponding to the arc, e.g.:• 1 in the 8-puzzle example1 in the 8-puzzle example• expected time to merge two sub-assembliesexpected time to merge two sub-assemblies
We will assume that for any given We will assume that for any given problem the cost c of an arc always problem the cost c of an arc always verifies: verifies: c c ≥ ≥ εε >> 0 0, where , where εε is a constant is a constant[This condition guarantees that, if path becomes [This condition guarantees that, if path becomes arbitrarily long, its cost also becomes arbitrarily large]arbitrarily long, its cost also becomes arbitrarily large]
Why is this needed?
4242
It may be explicitly described:It may be explicitly described:
or partially described:or partially described:
or defined by a condition, or defined by a condition, e.g., the sum of every row, of every column, e.g., the sum of every row, of every column, and of every diagonals equals 30and of every diagonals equals 30
Goal StateGoal State1 2 34 5 67 8
11145
136
384 10 9 7
122115
158
a aa a
aa (“a” stands for “any”)
4343
Other examplesOther examples
4444
8-Queens Problem8-Queens ProblemPlace 8 queens in a chessboard so that no two queens are in the same row, column, or diagonal.
A solution Not a solution
4545
Formulation #1Formulation #1 States:States: all arrangements of 0, all arrangements of 0,
1, 2, ..., or 8 queens on the 1, 2, ..., or 8 queens on the boardboard
Initial state:Initial state: 0 queen on the 0 queen on the boardboard
Successor function:Successor function: each of each of the successors is obtained by the successors is obtained by adding one queen in an empty adding one queen in an empty squaresquare
Arc cost:Arc cost: irrelevantirrelevant Goal test:Goal test: 8 queens are on the 8 queens are on the
board, with no two of them board, with no two of them attacking each otherattacking each other
64x63x...x53 ~ 3x1014 states
4646
Formulation #2Formulation #2 States:States: all arrangements of k = all arrangements of k =
0, 1, 2, ..., or 8 queens in the k 0, 1, 2, ..., or 8 queens in the k leftmost columns with no two leftmost columns with no two queens attacking each otherqueens attacking each other
Initial state:Initial state: 0 queen on the 0 queen on the boardboard
Successor function:Successor function: each each successor is obtained by adding successor is obtained by adding one queen in any square that is one queen in any square that is not attacked by any queen not attacked by any queen already in the board, in the already in the board, in the leftmost empty column leftmost empty column
Arc cost:Arc cost: irrelevantirrelevant Goal test:Goal test: 8 queens are on the 8 queens are on the
boardboard 2,057 states
4747
n-Queens Problemn-Queens Problem A solution is a A solution is a goal nodegoal node, not a path to this , not a path to this
node (typical of design problem)node (typical of design problem) Number of states in state space:Number of states in state space:
• 8-queens 8-queens 2,057 2,057• 100-queens 100-queens 10 105252
But techniques exist to solve n-queens But techniques exist to solve n-queens problems efficiently for large values of nproblems efficiently for large values of nThey exploit the fact that there are many They exploit the fact that there are many solutions well distributed in the state spacesolutions well distributed in the state space
4848
Path PlanningPath Planning
What is the state space?
4949
Formulation #1Formulation #1
Cost of one horizontal/vertical step = 1Cost of one diagonal step = √2
5050
Optimal SolutionOptimal Solution
This path is the shortest in the discretized state space, but not in the original continuous space
5151
Formulation #2Formulation #2sweep-line
5252
Formulation #2Formulation #2
5353
StatesStates
5454
Successor FunctionSuccessor Function
5555
Solution PathSolution Path
A path-smoothing post-processing step is usually needed to shorten the path further
5656
Formulation #3Formulation #3
Cost of one step: length of segment
5757
Formulation #3Formulation #3
Cost of one step: length of segment
Visibility graph
5858
Solution PathSolution Path
The shortest path in this state space is also the shortest in the original continuous space
5959
Assembly (Sequence) PlanningAssembly (Sequence) Planning
6060
Possible FormulationPossible Formulation States:States: All decompositions of the assembly All decompositions of the assembly
into subassemblies (subsets of parts in their into subassemblies (subsets of parts in their relative placements in the assembly)relative placements in the assembly)
Initial state:Initial state: All subassemblies are made of a All subassemblies are made of a single partsingle part
Goal state:Goal state: Un-decomposed assembly Un-decomposed assembly Successor function:Successor function: Each successor of a state Each successor of a state
is obtained by merging two subassemblies (the is obtained by merging two subassemblies (the successor function must check if the merging successor function must check if the merging is feasible: collision, stability, grasping, ...)is feasible: collision, stability, grasping, ...)
Arc cost:Arc cost: 1 or time to carry the merging 1 or time to carry the merging
6161
A Portion of State SpaceA Portion of State Space
6262
But the formulation rules out But the formulation rules out “non-monotonic” assemblies“non-monotonic” assemblies
6363
But the formulation rules out But the formulation rules out “non-monotonic” assemblies“non-monotonic” assemblies
6464
But the formulation rules out But the formulation rules out “non-monotonic” assemblies“non-monotonic” assemblies
6565
But the formulation rules out But the formulation rules out “non-monotonic” assemblies“non-monotonic” assemblies
6666
But the formulation rules out But the formulation rules out “non-monotonic” assemblies“non-monotonic” assemblies
6767
But the formulation rules out But the formulation rules out “non-monotonic” assemblies“non-monotonic” assemblies
XThis “subassembly” is not allowed in the definition ofthe state space: the 2 partsare not in their relative placements in the assembly
Allowing any grouping of parts as a valid subassembly would make the state space much bigger and more difficult to search
6868
Assumptions in Basic SearchAssumptions in Basic Search
The world is The world is staticstatic The world is The world is discretizablediscretizable The world is The world is observableobservable The actions are The actions are deterministicdeterministic
But many of these assumptions can be removed, and search still remains an important problem-solving tool
6969
Vacuum Cleaner ProblemVacuum Cleaner Problem A vacuum robot lives in a two-room environmentA vacuum robot lives in a two-room environment
States:States: The robot is in one of the two rooms, The robot is in one of the two rooms, and each room may or may not contain dirt and each room may or may not contain dirt 8 states 8 states
Successor function:Successor function: the successors of a state the successors of a state correspond to trying 3 actions: Right, Left, correspond to trying 3 actions: Right, Left, Suck. Suck.
Initial state:Initial state: UnknownUnknown (not observable) (not observable) Goal state:Goal state: No dust in the rooms No dust in the rooms
7070
Re-Formulation with “Belief States”Re-Formulation with “Belief States” Belief states:Belief states: sets of states sets of states 2 288 =256 =256
belief statesbelief states Initial belief state:Initial belief state: set of 8 states set of 8 states Successor function:Successor function: the successors of a the successors of a
belief state correspond to trying Right, belief state correspond to trying Right, Left, Suck on all states in the belief Left, Suck on all states in the belief state. state.
Goal belief state:Goal belief state: any set of states with any set of states with none having dust in any of the roomsnone having dust in any of the rooms
7171
Left RightSuck
7272
Search and AISearch and AI Search methods are Search methods are ubiquitousubiquitous in AI systems. in AI systems.
They often are the backbones of both core They often are the backbones of both core and peripheral modules and peripheral modules
An An autonomous robotautonomous robot uses search methods: uses search methods:• to decide which actions to take and which sensing to decide which actions to take and which sensing
operations to perform, operations to perform, • to quickly anticipate and prevent collision, to quickly anticipate and prevent collision, • to plan trajectories,to plan trajectories,• to interpret large numerical datasets provided by to interpret large numerical datasets provided by
sensors into compact symbolic representations, sensors into compact symbolic representations, • to diagnose why something did not happen as to diagnose why something did not happen as
expected, expected, • etc...etc...
7373
ApplicationsApplicationsSearch plays a key role in many applications, e.g.:Search plays a key role in many applications, e.g.:
Route finding: airline travel, networksRoute finding: airline travel, networks Package/mail distributionPackage/mail distribution Pipe routingPipe routing Comparison and classification of protein foldsComparison and classification of protein folds Pharmaceutical drug designPharmaceutical drug design Design of protein-like moleculesDesign of protein-like molecules Video gamesVideo games