AI - Problem Solving - INCOMPLETE
AI - Problem Solving - INCOMPLETE
AI - Problem Solving - INCOMPLETE
Problem solving in AI
oDepth first
oBreadth first
oHill climbing
oBest first search
oA* Search
oAO* search
AI
Search Algorithms
• Informed search algorithms use heuristic functions that are specific to the
problem, apply them to guide the search through the search space to try to
reduce the amount of time spent in searching.
• games such as 3x3 eight-tile, 4x4 fifteen-tile, and 5x5 twenty four tile puzzles
are single-agent-path-finding challenges.
• consist of a matrix of tiles with a blank tile.
• player is required to arrange the tiles by sliding a tile either vertically or
horizontally into a blank space with the aim of accomplishing some objective.
Other examples,
• Travelling Salesman Problem, Rubik’s Cube, and Theorem Proving.
AI
Means-Ends Analysis (MEA)
• Problem-solving technique to achieve end-goals.
• Starts from predetermined goal, in which actions are chosen to lead to goal.
• With help of MEA, both forward and backward research can be done to
determine where stagnation is occurring.
• Requirements −
o Initial state
o State description
• Search programs either return only a solution value when a goal is found, or
record_and_return the solution path.
Basic algorithm
• These procedures take data P (for the particular instance of problem that is to be
solved) as parameter, and should do following:
• next (P, c): generate the next candidate for P after the current one c.
• If there are no candidates at all for instance P first procedure should return Λ
AI
Brute-Force Search Strategies__ Speed up
• Reduce search space, i.e. set of candidate solutions by using heuristics specific to
the problem class.
Example, find all integers between 1 & 1,000,000 that are evenly divisible by 417.
• Can be solved much more efficiently by starting with 417, and repeatedly
adding 417 until the number exceeds 1,000,000
AI
Brute-Force Search Strategies__ Speed up
place eight queens on a standard chessboard, so that no queen attacks any other.
AI
Brute-Force Search Strategies__ Speed up
• Since each queen can be placed in any of the 64 squares, in principle there are
64^8 = 281,474,976,710,656 possibilities to consider.
• But, queens are all alike, and no two queens can be placed on same square;
possible ways of choosing a set of 8 squares from set all 64 squares is
AI
Generate and test
• Plan generate‐test:
Algorithm:
(1) Generate a possible solution
(2) Test to see if it is a solution (compare end point of path to goal state)
(3) If solution is found, quit. Else return to (1)
Generate and test _ Example
• Level-4 for has 10 classrooms which are numbered from 401 to 410
respectively.
• How we can apply generate and test algorithm to find the classroom?
• What is the maximum number of classrooms you may try until the correct
one is found?
Generate and test _ Example
Generate and test _ Example
• Is it good to apply the generate and test algorithm if the level is not known,
and the building has 20 levels??
• What is the maximum number of classrooms you may try until the correct
one is found.
oIf some intermediate states are likely to appear often in the tree, it would
be better to modify that procedure to traverse a graph rather than a tree.
Generate and test
Weakness of planning:
AI
Pure Heuristic Search
• Creates two lists, a closed list for already expanded nodes, and open list for
created but unexpanded nodes.
• In each iteration, a node with minimum heuristic value is expanded, all its
child nodes are created and placed in closed list.
• Then, heuristic function is applied to child nodes and they are placed in the
open list according to their heuristic value.
AI
Heuristic Search
• Direct techniques (blind search) are not always possible (they require too
much time or resource).
AI
Heuristic Search - 8 Puzzle
• For now - establish some ordering to possible moves (values of heuristic does
not matter as long as it ranks the moves).
AI
Heuristic Search - 8 Puzzle
• Count how far away (how many tile movements) each tile is from it’s correct
position.
AI
Breadth-First Search
• Starts from root node explores neighbouring nodes first moves towards
next level neighbours.
• In each iteration, node at the head of the queue is removed and then expanded.
• Generated child nodes are then added to the tail of the queue.
Breadth-First Search
Breadth-First Search
• If branching factor (average number of child nodes for a given node) = b, and
depth = d, then number of nodes at level d = bd.
• total no of nodes created in worst case is b + b2 + b3 + … + bd.
AI
Breadth-First Search _ Algorithm
o Remove the first element, say E, from the NODE-LIST. If NODE-LIST was
empty then quit.
o For each way that each rule can match the state described in E do:
ii) If the new state is the goal state, quit and return this state.
AI
Breadth-First Search
Advantage
• Breadth first search will never get trapped exploring useless path forever.
• If there is more than one solution then BFS can find the minimal one that
requires less number of steps.
Disadvantage
• If solution is farther away from root, BFS will consume lot of time
AI
Depth-First Search
AI
Depth-First Search
Depth-First Search _ Algorithm
a) Generate a state, say E, and let it be the successor of the initial state. If
there is no successor, signal failure.
AI
Depth-First Search
o only needs to store stack of nodes on path from root to current node.
• Finds solution without exploring much in a path time taken also very less.
AI
Depth-First Search
Disadvantage − May not terminate, and go on infinitely on one path. The solution
to this issue is to choose a cut-off depth.
o If ideal cut-off is d, & cut-off is lesser than d, then this algorithm may fail.
AI
Depth-First ITERATIVE DEEPENING (DFID) Search
• First performs a DFS to depth 1, then starts over; executing a complete DFS to
depth 2, and continues to run DFS to successively greater depths, until a
solution is found.
AI
Best-First-Search
• Depth‐first search: not all competing branches having to be expanded.
⇒ Combining the two: follow a single path at a time, but switch paths whenever
some competing path look more promising than current one.
Best-First-Search
• Traverse the graph (from initial node) following best current path.
• Pick one/best unexpanded nodes on that path and expand it.
• Add its successors to graph and compute for each of them
• Change expanded node’s value to reflect its successors.
• Propagate the change up the graph.
• Reconsider current best solution and repeat until a solution is
found
Best-First-Search _ Algorithm
• OPEN: nodes that have been generated, but have not examined.
• Whenever a new node is generated, check whether it has been generated before
Greedy search:
• h(n) = estimated cost of the cheapest path from node nto a goal state
g(n) = cost of the cheapest path from the initial state to node n.
• Identical to Breadth First search if each transition has the same cost.
AI
Bidirectional Search
• forward from initial state and backward from goal state till both meet to
identify a common state.
• Search stops when searches from both directions meet in the middle.
• Requires an explicit goal state instead of simply a test for a goal condition.
• Path from initial state is concatenated with the inverse path from goal state.
AI
Bidirectional Search
Advantage
• Speed: Sum of the time taken by two searches (forward and backward).
Disadvantage
• Algorithm must be too efficient to find the intersection of the two search trees.
• discards all states that don’t look promising or seem unlikely to lead to goal state.
• Next node to expand, is the node with highest value of nodes generated from the
expansion of current node.
• To take such decisions, it uses heuristics (an evaluation function) which indicates
how close the current state is to goal state.
Hill-Climbing = generate-and-test + heuristics (direction to move)
• heuristic or evaluation function estimates how close a given state is to goal state
AI
Hill-Climbing Search
• In this technique, starting at base of hill walk upwards until reach top of hill.
o start with initial state and keep improving the solution until its optimal.
• Hill climbing is often used when a good heuristic function is available for
evaluating states and when no other useful
AI
knowledge is available.
Hill-Climbing Search
• Heuristic search used for mathematical optimization of problem solving.
• For given large set of inputs and a good heuristic function, it tries to find
sufficiently good solution to the problem.
• Iterative algorithm that starts with arbitrary solution to a problem and attempts
to find better solution by changing a single element of the solution incrementally.
1. Evaluate initial state; if it is goal state quit otherwise current state is initial
state.
2. Select a new operator for this state and generate a new state.
o if it is no better ignore
AI
State Space Diagram Hill-Climbing Search
• State space diagram is a graphical representation of the set of states our search
algorithm can reach vs value of objective function (function which we wish to
maximize).
• X-axis : denotes state space i.e. states or configuration our algorithm may reach.
• Best solution will be that state space where objective function has maximum
value (global maximum).
AI
State Space Diagram Hill-Climbing Search
AI
Hill-Climbing Search _ regions
• Local maximum: A state which is better than all neighbors, but there exists a
better state which is far from current state.
• Global maximum : It is the best possible state in the state space diagram. This
because at this state, objective function has highest value.
• Plateau//flat local maximum: All neighboring states have same heuristic values,
so it’s unclear to choose the next state by making local comparisons
• Ridge: An area which is higher than surrounding states, but it can not be reached
in single move; special kind of local maximum. (example; only four possible
directions to explore (N, E, W, S), and Ridge exists in NE direction)
AI
Hill-Climbing Search _ Disadvantages
• Plateau : All neighbours have same value; not possible to select best direction.
Solution: Make a big jump. Randomly select a state far away from current
state. Chances are that we will land at a non-plateau region
• Ridge : Any point on a ridge can look like peak; & movement in all possible
directions is downward. Algorithm stops when it reaches this state.
AI
Hill-Climbing Search _ Example
AI
Hill-Climbing Search _ Example
• h(x) = +1 for all blocks in the support structure of the block is correctly positioned
otherwise -1
• Call any block correctly positioned if it has same support structure as goal state.
AI
Hill-Climbing Search _ Example
AI
Hill-Climbing Search _ Example
AI
Hill-Climbing Search _ Example
AI
Hill-Climbing Search _ Example
• Show the steps of applying hill climbing algorithm on this
tree for initial state (a) to final state (h).