To Build A System To Solve A Problem
To Build A System To Solve A Problem
3 liters 4 liters
2
Water Jugs cont.
• Rules :
– <x,y> x<4 <4,y> ( Fill 4 liters )
– <x,y> y<3 <x,3> ( Fill 3 liters )
– <x,y> x>0 <x-d,y> (pour d ltr water out of the 4 ltr jug)
– <x,y> y>0 <x,y-d> (pour d ltr water out of the 3 ltr jug)
– <x,y> <o,y> ( Dump 4 liters )
– <x,y> <x,0> ( Dump 3 liters )
– <x,y> | x+y >= 4 <4,y-(4-x)>
– <x,y> | x+y >= 3 <x-(3-y),y>
– <x,y> | x+y <= 4 <x+y,0>
– <x,y> | x+y <= 3 <0,x+y>
3
Defining the problem as a state space
search
• Basic Search Problem
• Given [S,s,O,G)
• S- is the implicitly specify set of states
• s – is the start state
• O – is the set of state transition operators
• G – is the set of goal states
Defining the problem as a state space
search
• State Space - Define a state space that contains
all the possible configuration of the relevant
objects.
• Start Space - Specify one or more states within
that space describe possible situation from which
the problem-solving process may start.
• Goal State - Specify one or more states would be
acceptable as solutions to the problem.
• Operators – Specify a set of rules that describe
the actions available.
Examples of Problems
• “Toy” Problems :
– Water jug.
– Missionaries and Cannibals.
– 8 – Queens.
– 8 Puzzle.
• “Real” Problems :
• Schedules.
• Traveling Salesman.
• Robot navigation.
• Language Analysis (Parsers, Grammars).
• VLSI design
6
Production System
• Since search forms the core of many
intelligent processes, it is useful to structure
AI programs in a way that facilitates describing
and performing the search process.
• Production systems provide such structures
Production
1. DATA initial database.
2. Until DATA satisfies termination condition
do:
3. begin:
Select some rule, R, in the set of rules that can
be applied to DATA.
DATA result of applying R to DATA.
4. end.
8
A Production system
• A set of rules, each consisting of a left side (a pattern) that
determines the applicability of the rule and a right side that
describes the operation to be performed.
• One or more knowledge/database that contain whatever
information is appropriate for the particular task. Some
part of the database may be permanent, while other parts
of it may pertain only to the solution of the current
problem.
• A control strategy that specifies the order in which the
rules will be compared to the database and a way of
resolving the conflicts that arise when several rules match
at once.
• A rule applier.
Search Through State-Space
Goal state
Initial state
10
Control strategies
• How to decide which rule to apply next during
the process of searching for a solution to a
problem.
• As it is going to affect that how quickly
problem is solved or even whether problem is
finally solved.
• Good control strategy
– The first requirement is that it cause motion
– The second requirement is that it be systematic
• Good Control strategy Cause Motion –
– Water jug problem. Suppose we implemented the simple
control strategy of starting each time at the top of the list
of rules and choosing the first applicable one. If we did
that we, we would never solve the problem. We would
continue indefinitely filling the 4- gallon jug with water.
• Good strategy is that it be systematic.
– The requirement that a control strategy be be systematic
corresponds to the need for global motion (over the
course of several steps) as well as local motion (over the
course of a single step)
Control via Search Techniques
• “Uninformed” :
– Breadth – First.
– Depth – First.
– Backtracking.
• “Informed” – Heuristic :
– Hill Climbing.
– Best First, A*.
15
Breadth First
b = branching factor d=depth
2 d
1+b+b +…+b
d
Time Complexity – O(b )
d
Space Complexity – O(b )
16
Depth First Search
• If the initial state is a goal state, quit and return
success.
• Otherwise, do the following until success or
failure is signaled
– Generate a successor, E, of the initial state. If there
are no more successors, signal failure.
– Call Depth-First Search with as the initial state
– If success is returned, signal success. Otherwise
continue in this loop.
• Which data structure should it use ?
Depth First cont.
18
Combinatorial Explosion
• To solve a problem there can be too many
combination for a small set of possibilities,
• Eg – Travelling Sales Problem even for 10
cities !10 possibilities. 3628800.
• Branch and bound strategies
• For real world problems, it is often hard to measure
precisely the value of a particular solution.
• Rarely do we actually need the optimum solution; a
good approximation usually serve very well.
• In fact, there is some evidence that people, when they
solve problems, are not optimizers but rather are
satisfiers.
• They seek solution that satisfies some set of
requirements and as soon as they find one they quit.
Eg. – finding the parking space.
Heuristic Search
B (3) C (5) D
B (3) C (5) D (1)
A
E (4) F (6)
A
B C D
B C D
G (6) E F
H(5)
G H E F
I(2) J(1)
• g – a measure of the cost of getting from initial state to the
current node. G is not an estimate of anything but it is exact
sum of the costs of applying each of the rules that were
applied along the best path to the node.
• The function h’ is an estimate of the additional cost of getting
from the current node to a goal state. This is the place where
knowledge of problem domain exploited
• f’, represent an estimate of the cost of getting from the initial
state to a goal state along the path that generated the
current node.
A* Algorithm
• Start with OPEN containing only the initial node. Set that
node’s g value to 0, its h’ value to whatever it is, and its f’
value to h’+ g. Set Closed to the empty list.
• Until a goal node is found repeat
– If there are no nodes on open, report failure
– Otherwise, pick the node on OPEN with the lowest f’ value. Call it
BESTNODE. Remove it from OPEN. Place it on CLOSED.
– Check if best node is goal state, if so then report and exit.
– Otherwise generate the successor of BESTNODE (but do not set
BESTNODE to point to them yet).
• For Each successor
– Set successor to point back to BESTNODE.
– Computer g(Successor) = g(BESTNODE) + the cost of getting from
BESTNODE to successor.
– Check if successor is the as any node on open (i.e. already generated
but not processed) then call that node OLD.
– Check whether it is cheaper to get to OLD via its current parent or to
SUCCESSOR via BESTNODE by comparing their g values.
– If OLD is cheaper, then we need do nothing. If SUCCESSOR is cheaper,
then reset OLD’s parent link to point to BESTNODE, record the new
cheaper path in g(OLD), and update f’(OLD).
• If SUCCESSOR was not on OPEN, See If It is on
CLOSED. If so, call the node on CLOSED as OLD and
add OLD to the list of BESTNODE’ succesor.
• Check to se if the new path or the old path is better
as previous and set the parent link and g & f’ values
appropriately.
• If we have just found a better path to OLD, we must
propagate the improvement to OLD’s Successors.
• If successor was not already on either OPEN or
CLOSED, then put it on open and add it to the
list of BESTNODE’s successors.
• Compute f’(successor)=g(successor)
+h’(successor)
• Function g lets us choose which node to expand next on the
basis not only of how good the node itself look, but also on
the basis of how good the path to the node was.
• If we case about the path consideration of g is important.
• If we only care about getting to a solution somehow, we can
define g always to be 0.
• If we want to find a path involving the fewest number of
steps, then we set the cost of going from a node to its
successor as a constant, usually 1.
• If we want to find the cheapest path and some operator cost
more than others, then we set the cost of going from a node
to another to reflect those costs, then we set the cost of
going from one node to another to relect those costs.
• If h’ is a perfect estimator of h, then A* will converge
immediately to the goal with no search.
• If value of h’ is always 0, then search will be
controlled by g.
– If value of g is 0 then search is random
– If the value of g is always 1, the search will Breadth first
search.
• If we can maintain that h’ never overestimates h,
then A* algorithm is guaranteed to find that h’ an
optimal path to a goal, if one exists.
• This implementation is for graph.
• If can be simplified to apply to trees by not
bothering to check whether a new node is
already on OPEN or CLOSEd. This makes it
faster to generate node.
Problem Reduction
• AND-OR Graphs
– It is useful for representing the solution of
problems that can be solved by decomposing
them into a set of smaller problem, all of which
must then be solved.
– This decomposition, or reduction, generates arc
that we call AND arcs.
– One AND arc may point to any number of
successor nodes, all of which must be solved in
order for the arc to point to a solution.
Goal : Acquire TV Set
Goal: Steal TV Set Goal : Earn Some Money Goal : Buy TV Set
• Initialize the graph to the starting node.
• Loop until the starting node is labeled SOLVED or
until its cost goes above FUTILITY
– Traverse the graph, starting at the initial and following the
current best path, and accumulate the set of nodes that
on that path and have not yet been expanded or labeled
as solved.
– Pick one of these unexpended nodes and expand it.
– If there are no successors, assign FUTILITY as the value of
this node.
– Otherwise, add its successors to the graph and for each of
them compute f’(only h1’ and ignoring g).
– If f’ of any node is 0, mark that node as solved.
• Change the f’ estimate of the newly expanded node
to reflect the new information provided by its
successors.
• Propagate this change backward through the graph.
• If any node contains a successor arc whose
descendants are all solved, label the node itself as
SOLVED.
• At each node that is visited while going up the graph,
decide which of its successor arcs is the most
promising and mark it as part of the current best
path. This may cause the current best path to
change.
A A
B C D
A A
B C D B C D
G H E F
E F
Points to Consider when Representing
Problems
• Decomposable ?
A
C B
A B C
• Predictable ?
59
Points to Consider when Representing
Problems cont.
• Is “good” solution easily recognizable ?
Traveling Salesman
• Is Knowledge Base consistent ?
Big Data Base and limitations of logic
• How much Knowledge is needed ?
Chess, Newspaper-Understanding
60