Chapter Three

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 46

CHAPTER THREE

INTRODUCTION TO PROBLEM
SOLVING
MAN VS MACHINE
 When we compare Humans to Machines, it is important to note that a
Machine can be a car, a Smart Phone, a Digital Television, etc.
 Generally, machine is better than human in:
 Speed and Power
 Sensor Detection out side
 Human Range
 Routine work
 Alertness
 Computation
 Short term Memory
 Storage
 Simultaneous Activities
Humans are Better than machines in:

 Sensory Functions

 Perceptual Abilities

 Flexiblity/Ability to Improvise

 Judgment

 Selective Recall

 Inductive Reasoning
Problem Definition
A problem can be defined by five main components:
1.Initial state: where we are at the beginning

2.Action: description of possible actions

3.Transition model: Description of what each action does


State space-the set of all states reachable from the initial state by any sequence of
actions

Initial state, actions, transition models, implicitly define the state space of the
problem

4. Goal Test: determines whether the given state is a goal state

5. Path cost functions: assigns numeric cost to each path


Problem Solving
 Problem solving is a process of generating solutions from observed data.

 A problem is characterized by a set of: goals, objects, and operations.

 To build a system to solve a problem:


1. Define the problem precisely

2. Analyze the problem

3. Isolate and represent the task knowledge that is necessary to solve the problem

4. Choose the best problem-solving techniques and apply it to the particular


problem.
Problem Solving
Defining the problem as State Space Search: The state space representation
forms the basis of most of the AI methods.
Formulate a problem as a state space search by showing the legal problem
states, the legal operators, and the initial and goal states.
A state is defined by the specification of the values of all attributes of
interest in the world
An operator changes one state into the other; it has a precondition which is
the value of certain attributes prior to the application of the operator, and a
set of effects, which are the attributes altered by the operator
The initial state is where you start
The goal state is the partial description of the solution
Problem solving

 A solution to a problem is an action sequence that leads from


the initial state to goal state
 Solution quality is measured by the path cost function.
 An optimal solution has the lowest path cost among all
solutions
Problem Solving
Formal Description of the problem:
1.Define a state space that contains all the possible configurations of
the relevant objects.

2.Specify one or more states within that space that describe possible
situations from which the problem solving process may start ( initial
state)

3.Specify one or more states that would be acceptable as solutions to


the problem. ( goal states) Specify a set of rules that describe the
actions (operations) available
Problem Solving
A problem is defined by four items:
1.initial state e.g., "at shambu―
2.actions or successor function : S(x) = set of action–state pairs
e.g., S(shambu) = {, … }
3. goal test (or set of goal states) e.g., x = "at Bucharest‖, Checkmate
(x)
4.path cost (additive) e.g., sum of distances, number of actions
executed, etc. c(x,a,y) is the step cost, assumed to be ≥ 0
A solution is a sequence of actions leading from the initial state
to a goal state
Properties of Search Algorithms
There are four important factors to consider:

1.Completeness: Is a solution guaranteed to be found if at least one


solution exists?

2.Optimality: Is the solution found guaranteed to be the best (or


lowest cost) solution if there exists more than one solution?

3.Time Complexity: The upper bound on the time required to find a


solution, as a function of the complexity of the problem.

4.Space Complexity: The upper bound on the storage space


(memory) required at any point during the search, as a function of the
complexity of the problem.
Problem-solving agents
Problem solving agents are goal-directed agents:

1. Goal Formulation: Set of one or more (desirable) world


states.

2.Problem formulation: What actions and states to


consider given a goal and an initial state.

3.Search for solution: Given the problem, search for a


solution --- a sequence of actions to achieve the goal
starting from the initial state.
4. Execution of the solution
Building Goal-Based Agents
 We have a goal to reach

 Driving from City A to City B


 We have information about the initial state; where we are now at
the beginning
 We have a set of operators; a series of actions that can be taken to
move around (change state)
 Objective: find a sequence of actions which will enable the agent
to achieve its goal optimally
Searching Defined
 Examine different possible sequences of actions & states, and come
up with specific optimal sequence of actions that will take you from
the initial state to the goal state
 Given a state space with initial state and goal state, find optimal
sequence of actions leading through a sequence of states to the
final goal state
 Searching in State Space

 select optimal (min-cost/max-profit) node/state in the state space

 test whether the state selected is the goal state or not

 if not, expand the node further to identify its successor.


Search Tree
 The searching process is like building the search tree that

is super imposed over the state space

 A search tree is a representation in which nodes denote paths and

branches connect paths.

 The node with no parent is the root node.

 The nodes with no children are called leaf nodes.


Search algorithm
 Two functions needed for conducting search
 Generator (or successors) function: Given a state and action, produces its
successor states (in a state space)
 Tester (or IsGoal) function: Tells whether given state S is a goal state.
IsGoal(S)  True/False
 IsGoal and Successors functions depend on problem domain.
 Two lists maintained during searching
 OPEN list: stores the nodes expanded but not explored
 CLOSED list: the nodes expanded and explored
 Generally search proceeds by examining each node on the OPEN list;
performing some expansion operation that adds its children to the OPEN list,
& moving the node to the CLOSED list
Search algorithm
 Merge function: Given successor nodes, it either append, prepend
to open list or rearrange based on evaluation cost
 Path cost: function assigning a numeric cost to each path; either
from initial node to current node and/or from current node to goal
node
 Input: a given problem (Initial State + Goal state + transit states
and operators)
 Output: returns optimal sequence of actions to reach the goal.
Algorithm Evaluation
Completeness
 Is the algorithm guarantees in finding a solution
whenever one exists
 Think about the density of solutions in space and
evaluate whether the searching technique guaranteed to
find all solutions or not.
Optimality
 is the algorithm finding an optimal solution; i.e. the one
with minimize cost or maximize profit
 how good is our solution?
Algorithm Evaluation
With many computing projects, we worry about:
 Speed versus memory
 Time complexity: how long does it take to find a
solution
 Space complexity: how much space is used by the
algorithm
Fast programs
 use up too much memory
Memory efficient programs
 But they are slow
We consider various search strategies
 In terms of their memory/speed tradeoffs
Searching Strategies
Search strategy gives the order in which the search space is examined

Uninformed (= blind) search


 They do not need domain knowledge that guide them towards the goal

 Have no information about the number of steps or the path cost from the current

state to the goal


 It is important for problems for which there is no additional information to

consider

Informed (= heuristic) search


 have problem-specific knowledge (knowledge that is true from experience)

 Have knowledge about how far are the various state from the goal

 Can find solutions more efficiently than uninformed search


Search Methods:
 Informed search
 Uninformed search  Greedy search

 A*-search
 Breadth first
 Iterative improvement

 Depth first  Constraint satisfaction

 etc.

 Uniform cost

 Depth limited search

 Iterative deepening

etc
Breadth first search
• Expand shallowest unexpanded node,
–i.e. expand all nodes on a given level of the
search tree before moving to the next level
• Implementation: use queue data structure to
store the list:
–Expansion: put successors at the end of
queue
–Pop nodes from the front of the queue
• Properties:
–Takes space: keeps every node in memory
–Optimal and complete: guarantees to find
solution
Exercise
• Apply BFS to find an optimal path from start
node to Goal node.
Uniform cost Search
•The goal of this technique is to find the shortest path to the goal
in terms of cost.
–It modifies the BFS by always expanding least-cost unexpanded
node
•Implementation: nodes in list keep track of total path length
from start to that node
–List kept in priority queue ordered by path cost
A
S S S
1 10 S
5 B 5
S G 0 A B C A B C A B C
1 5 15 5 15 15
G G G
15 5
11 11 10
C

•Properties:
–This strategy finds the cheapest solution provided the cost of a path
must never decrease as we go along the path
g(successor(n)) ≥ g(n), for every node n
Depth-first search
Expand one of the node at the
deepest level of the tree.
–Only when the search hits a non-goal
dead end does the search go back and
expand nodes at shallower levels
Implementation: treat the list as
stack
–Expansion: push successors at the top of
stack
–Pop nodes from the top of the stack
•Properties
–Incomplete and not optimal: fails in
infinite-depth spaces, spaces with loops.
–Takes less space (Linear): Only needs to
remember up to the depth expanded
Iterative Deepening Search (IDS)
• IDS solves the issue of choosing the best depth limit by
trying all possible depth limit:
–Perform depth-first search to a bounded depth d, starting at d = 1
and increasing it by 1 at each iteration.
• This search combines the benefits of DFS and BFS
–DFS is efficient in space, but has no path-length guarantee
–BFS finds min-step path towards the goal, but requires memory space
–IDS performs a sequence of DFS searches with increasing depth-
cutoff until goal is found

Limit=0 Limit=1 Limit=2


Bidirectional Search(Reading ass)
• Simultaneously search both forward from the initial state to the goal
and backward from the goal to the initial state, and stop when the two
searches meet somewhere in the middle
– Requires an explicit goal state and invertible operators (or
backward chaining).
– Decide what kind of search is going to take place in each half using
BFS, DFS, uniform cost search, etc.

Goal
Start
Bidirectional Search
• Advantages:
– Only need to go to half depth
– It can enormously reduce time complexity, but is not
always applicable
• Difficulties
– Do you really know solution? Unique?
– Cannot reverse operators
– Memory requirements may be important: Record all
paths to check they meet
• Memory intensive

• Note that if a heuristic function is inaccurate,


the two searches might miss one another .
Comparing Uninformed Search
Strategies Complete Optimal Time Space
complexity complexity

Breadth first search yes yes O(bd) O(bd)


Depth first search no no O(bm) O(bm)
Uniform cost search yes yes O(bd) O(bd)
Depth limited search if l >= d no O(bl) O(bl)
Iterative deepening yes yes O(bd) O(bd)
search
bi-directional search yes yes O(bd/2) O(bd/2)
• b is branching factor,
• d is depth of the shallowest solution,
• m is the maximum depth of the search tree,
• l is the depth limit
Example for illustrating uninformed search
strategies

S
3 1 8

A B C
3 15
7 20 5
D E G
How they perform
• Breadth-First Search: S
– Expanded nodes: S A B C D E G
3 1 8
– Solution found: S A G (cost 18)

• Depth-First Search:
– Expanded nodes: S A D E G
A B C
– Solution found: S A G (cost 18)
3 15
7 20 5
• Uniform-Cost Search:
– Expanded nodes: S A D B C E G D E G
– Solution found: S C G (cost 13)
This is the only uninformed search that worries about costs.
• Iterative-Deepening Search:
– nodes expanded: S S A B C S A D E G
– Solution found: S A G (cost 18)
Exercise: Uninformed Search Strategies

Assume that node 1 is the initial state and node 7


is the goal state
Exercise: Apply Uninformed Search
Strategies to identify optimal path

S
1 5 8

A B C
3 9
7 4 5
D E G
Informed search
 Search efficiency would improve greatly if there is
a way to order the choices so that the most
promising nodes are explored first.
 This requires domain knowledge of the problem (i.e.

heuristic) to undertake focused search


 informed search strategy—uses problem-specific knowledge
 can find solutions more efficiently

 the knowledge to make this determination is provided by an


evaluation function
 that returns a number describing the desirability of expanding the
node
Best First Search
 When the nodes are ordered so that the one with the
best evaluation is expanded first, the resulting strategy
is called best-first search.
 choose the node that appears to be best according to the
evaluation function
 Because they aim to find low-cost solutions, these algorithms
typically use some estimated measure of the cost of the
solution and try to minimize it
 Two basic approaches to Best First search
1. Greedy search
 tries to expand the node closest to the goal.
2. A* search
 tries to expand the node on the least-cost solution path.
Greedy search
 One of the simplest best-first search strategies is to
minimize the estimated cost to reach the goal.
 That is, the node whose state is judged to be closest to the
goal state is always expanded first
 the cost of reaching the goal from a particular state can
be estimated but cannot be determined exactly.
 A function that calculates such cost estimates is called
a heuristic function, and is usually denoted by the letter
h:
 h(n) = estimated cost of the cheapest path from the state at
node n to a goal state
 Greedy search uses h(n) to select the next node to
expand is
 Note that h(n) = 0 if n is a goal.
 heuristic functions are problem-specific(Domain
specific)
 A good heuristic function for route-finding problems is
the straight-line distance to the goal.
 That is, HsLD(n) = straight-line distance between n and
the goal location
 Example: greedy search to find a path from Arad to
Bucharest
 With the straight-line-distance heuristic, the first node
to be expanded from Arad will be Sibiu,
 because it is closer to Bucharest than either Zerind or
Timisoara.
 The next node to be expanded will be Fagaras, because
it is closest.
 Fagaras in turn generates Bucharest, which is the goal.
 For this particular problem, the heuristic leads to minimal
search cost:
 it finds a solution without ever expanding a node that is not on the
solution path.
 However, it is not perfectly optimal:
 b/c the path it found via Sibiu and Fagaras to Bucharest is 32
miles longer than the path through Rimnicu Vilcea and Pitesti.
 This path was not found because Fagaras is closer to
Bucharest in straight-line distance than Rimnicu Vilcea, so
it was expanded first
 The strategy prefers to take the biggest possible out of
the remaining cost to reach the goal,
 without worrying about whether this will be best in the long run—
hence the name "greedy search”
 Greedy search is susceptible to false starts.
 Consider the problem of getting from lasi to Fagaras.
 The heuristic suggests that Neamt be expanded first,
but it is a dead end.
 The solution is to go first to Vaslui—a step that is
actually farther from the goal according to the heuristic
—and then to continue to Urziceni, Bucharest, and
Fagaras.
 Hence, in this case, the heuristic causes unnecessary
nodes to be expanded.
 Furthermore, if we are not careful to detect repeated
states, the solution will never be found
—the search will oscillate between Neamt and lasi
Space and Time complexity of gready
 it is not optimal

 and it is incomplete because it can start down an infinite


path(deadend) and never return to try other possibilities.
 The worst-case time complexity for greedy search is O(bm)

 where m is the maximum depth of the search space.

 Because greedy search retains all nodes in memory, its space


complexity is the same as its time complexity.
 With a good heuristic function, the space and time complexity
can be reduced substantially.
A* search
• Greedy search minimizes the estimated cost to the goal, h(n), and
thereby cuts the search cost considerably.
– But it is neither optimal nor complete.

• Uniform-cost search, on the other hand, minimizes the cost of the


path so far, g(n);
– it is optimal and complete, but can be very inefficient.

• It would be nice if we could combine these two strategies to get


the advantages of both.
• we can do exactly that, combining the two evaluation functions
simply by summing them:
f(n) = g(n) + h(n).
 g(n): gives the path cost from the start node to node n,
 h(n): is the estimated cost of the cheapest path from n to the goal,
– Hence we have f(n) = estimated cost of the cheapest solution through n
 A* search find the cheapest solution, a reasonable thing to try first
is the node with the lowest value of f(n).
Admissible heuristics
– The restriction is to choose an h(n) function that never
overestimates the cost to reach the goal.
– Such an h is called an admissible heuristic.
– Admissible heuristics are by nature optimistic, because they
think the cost of solving the problem is less than it actually
is.
– If h is admissible, f(n) never overestimates the actual cost of
the best solution through n.
– Best-first search using f(n) as the evaluation function and an
admissible h function is known as A* search
 Check Admissibility of estimated cost h(n):
– make sure that h(n) is not overestimated as compared to g(n)

– g (n): Actual cost of shortest path from n to z (not known)


then
• h(n) :is said to be an admissible heuristic function if for all n, h(n) ≤ g(n)

– Using an admissible heuristics guarantees that the solution


found by searching algorithm is optimal
 Notice that the A* search prefers to expand from Rimnicu
Vilcea rather than from Fagaras.
 Even though Fagaras is closer to Bucharest, the path taken to
get to Fagaras is not as efficient in getting close to
Bucharest as the path taken to get to Rimnicu
Exercise: search space
• Given the search space below, find the optimal path using:
 Greedy search
 A* Search
 What do you observe in the process of applying the two
searching approaches
Initial state
S
• Note that: numbers with in 8
the nodes are h(n) & edges 1 5 8
are labeled with g(n)
A B C
8 4 3
3 9
4
7 5
D E G
  0
goal state

You might also like