2021 Lecture03 P1 ProblemSolvingBySearching
2021 Lecture03 P1 ProblemSolvingBySearching
2021 Lecture03 P1 ProblemSolvingBySearching
SOLVING PROBLEMS
BY SEARCHING
2
Problem-solving
Agents
• Well-defined problems
and solutions
• Formulating problems
3
A touring holiday in Romania
What makes a good trip at Arad?
• take in the sights, enjoy the foods, etc.
• avoid hangovers
• …
However, there will be your friend’s wedding
tomorrow at Bucharest!!!
4
Goal-based agents
• Intelligent agents maximize their performance measure.
• Performance measure includes different factors.
• Making decisions involves many tradeoffs.
• Goals help organize behavior by limiting the objectives that
the agent is trying to achieve and the actions it considers.
5
Problem formulation
• Consider a goal to be a set of world states in which the
objective is satisfied.
• Problem formulation is the process of deciding what
actions and states to consider, given a goal.
• E.g., state: being in a particular town, actions: driving from one town
to another → goal state: being in Bucharest
6
Traveling from Arad to Bucharest
7
Goal-based agents in Romania
• The agent initially does not know which road to follow
→ unknown environment, try an action randomly
• Suppose the agent has a map of Romania.
• The agent discovers many hypothetical
journey and finds a journey that
eventually gets to Bucharest.
• Observable
• Each city has a sign indicating its presence for arriving drivers.
• The agent always knows the current state.
• Discrete
• Each city is connected to a small number of other cities.
• There are only finitely many actions to choose from any given state.
• Known
• The agent knows which states are reached by each action.
• Deterministic
• Each action has exactly one outcome.
9
Solving problem by searching
• Search: the process of looking for a sequence of actions
that reaches the goal
• A search algorithm takes a problem as input and returns a
solution in the form of an action sequence.
• Execution phase: once a solution is found, the
recommended actions are carried out.
• While executing the solution, the agent ignores its percepts when
choosing an action → open-loop system
10
Solving problem by searching
11
Well-define problems and solutions
12
The state space
• The set of states that are reachable from the initial state by
any sequence
• It is implicitly defined by the initial state, actions, and transition model
• Directed graph – nodes are states and the links between
nodes are actions.
13
Well-define problems and solutions
14
Formulating problems by abstraction
16
Example
problems
• Toy problems
• Real-world problems
17
Toy problems vs. Real-world problems
Toy problems Real-world problems
Exercise problem-solving methods Bring solutions to practical issues
Compare performance of methods
Concise, exact description No single, agreed-upon description
E.g., 8-puzzle, 8-queens problem, E.g., route finding, touring and
cryptarithmetic, vacuum world, traveling salesperson problems,
missionaries and cannibals, simple VLSI layout, robot navigation,
route finding assembly sequencing
18
The Vacuum-cleaner world
• States: determined by the agent location and the dirt locations
• 2 × 22 = 8 possible world states (𝑛 × 2𝑛 in general)
• Initial state: Any state can be designated as the initial state.
• Actions: Left, Right, and Suck
• Larger model may include Up and Down, etc.
• Transition model: The actions have their expected effects.
• Except that moving Left in the leftmost square, moving Right in the
rightmost square, and Sucking in a clean square have no effect.
• Goal test: whether all the squares are clean
• Path cost: each step costs 1
19
The Vacuum-cleaner world
21
The 8-puzzle
23
The 8-queens: Incremental formulation
• States: any arrangement of 0 to 8 queens on the board
• Initial state: no queens on the board
• Actions: add a queen to any empty square
• Transition model: returns the board with a queen added to the
specified square
• Goal test: 8 queens are on the board, none attacked
• 64 ∙ 63 ⋯ 57 ≈ 1.8 × 1014 possible sequences to investigate
24
The 8-queens: Incremental formulation
25
Knuth’s 4 problem
• Devised by Donald Knuth (1964)
• Illustration of how infinite state spaces can arise
• Knuth’s conjecture: Starting with the number 4, a sequence of factorial,
square root, and floor operations will reach any desired positive integer.
26
The route-finding problem
• Consider the airline travel problems solved by a travel-planning Web site.
• States: a location (e.g., an airport) and the current time
• Extra information about “historical” aspects, e.g., previous segments, fare
bases, statuses as domestic or international, are needed.
• Initial state: specified by the user’s query
• Actions
• Take any flight from the current location, in any seat class, leaving after the
current time, leaving enough time for within-airport transfer if needed
• Transition model
• Current location: the flight’s destination, current time: the flight’s arrival time
• Goal test: whether the agent is at the destination specified by the user.
• Path cost: depend on different factors of the per performance measure
27
The touring problems
• Actions: correspond to trips between adjacent cities
• Each state must include not just the current location but also
the set of cities the agent has visited.
• For example, the touring holiday in Romania
• In(Bucharest), Visited({Bucharest}): initial state
• In(Vaslui), Visited({Bucharest, Urziceni, Vaslui}): intermediate state
• Goal test: whether in Bucharest and all 20 cities have been visited.
• Traveling salesperson problem (TSP): NP-hard
• Every city must be visited exactly once, and the tour is shortest.
• Plan movements of automatic circuit-board drills or stocking
machines on shop floors, etc.
28
Other real-world problems
• Actions: take the upper disk from one of the rods and sliding it
onto another rod, on top of the other disks that may already be
present on that rod, without violating the rule of disk sizes.
• Transition model: return a state given a state and an action
• Goal test:
31
Search tree
• Search algorithms consider many possible action sequences
to find the solution sequence.
• Search tree: the possible action sequences starting at the
initial state (root)
• Branches are actions and nodes are states in the state space
• Frontier: the set of all leaf nodes available for expansion at
any given point
34
Redundant paths
• Redundant paths are unavoidable.
• Following redundant paths may cause a tractable problem to
become intractable.
• This is true even for algorithms that know how to avoid infinite loops
35
GRAPH-SEARCH algorithms
function GRAPH-SEARCH(problem) returns a solution, or failure
initialize the frontier using the initial state of problem
initialize the explored set to be empty
loop do
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
add the node to the explored set
expand the chosen node, adding the resulting nodes to the frontier
only if not in the frontier or explored set
37
GRAPH-SEARCH separation property
38
Infrastructure for search algorithms
• Each node 𝑛 is structuralized by four components.
• 𝒏. 𝐒𝐓𝐀𝐓𝐄: the state in the state space to which the node corresponds
• 𝒏. 𝐏𝐀𝐑𝐄𝐍𝐓: the node in the search tree that generated the node 𝑛
• 𝒏. 𝐀𝐂𝐓𝐈𝐎𝐍: the action applied to the parent to generate 𝑛
• 𝒏. 𝐏𝐀𝐓𝐇 − 𝐂𝐎𝐒𝐓 : the cost, denoted by 𝒈(𝒏), of the path from the
initial state to the node, as indicated by the parent pointer
• Frontier can be implemented with a (priority) queue or stack.
• Explored set can be a hash table that allows for efficient
checking of repeated states
• Canonical form: logically equivalent states should map to the same
data structure
39
Infrastructure for search algorithms
42
THE END
43