AI unit 2 sem 5_watermark
AI unit 2 sem 5_watermark
UNIT 2
Problem Solving
Approaches
Topics
● Problem Solving
methods
● Search Strategies
● CSP
● Backtracking
● Game playing
● Some Examples of
Game
● Alpha beta pruning
● Stochastic
Problems Solving Approaches
1- Heuristics
2- Searching Algorithms
Heuristic Techniques
Heuristic techniques are problem-solving strategies or approaches that use
practical methods to find solutions when traditional algorithms might be
impractical or too time-consuming
Heuristic techniques are not guaranteed to find the best solution but are
designed to find solutions that are "good enough" for practical purposes.
Hill Climbing
Hill climbing is a popular heuristic optimization technique used to solve
optimization problems. It is based on the concept of repeatedly making incremental
changes to a solution in the direction that leads to a higher value of the objective
function (i.e., "climbing the hill" toward a peak). The basic idea is to start with an
initial solution and iteratively make small modifications to it, choosing the
modification that improves the objective function the most at each step.
State Space Diagram
● Local Maximum: Local maximum is a state which is better than its neighbor
states, but there is also another state which is higher than it.
● Global Maximum: Global maximum is the best possible state of state space
landscape. It has the highest value of objective function.
● Current state: It is a state in a landscape diagram where an agent is currently
present.
● Flat local maximum: It is a flat space in the landscape where all the neighbor
states of current states have the same value.
● Shoulder: It is a plateau region which has an uphill edge.
Constraint Satisfaction Problems
Finding a solution that meets a set of constraints is the goal of constraint satisfaction problems
(CSPs), a type of AI issue. Finding values for a group of variables that fulfill a set of restrictions
or rules is the aim of constraint satisfaction problems
Three basic components in the constraint satisfaction problem
Variables: The things that need to be determined are variables. Variables in a CSP are the objects
that must have values assigned to them in order to satisfy a particular set of constraints.
For Example In Sudoku we have to fill numbers only.
Domains: The range of potential values that a variable can have is represented by domains.
Depending on the issue, a domain may be finite or limitless
For Example In Sudoku the set of numbers from 1 to 9 can serve as the domain of a variable
Constraints: The guidelines that control how variables relate to one another are known as
constraints. Constraints in a CSP define the ranges of possible values for variables.
For Example In Sudoku the restrictions might be that each row, column, and 3×3 box can only
have one instance of each number from 1 to 9.
Best First Search
This algorithm always chooses the path which appears best at that moment. It is
the combination of depth-first search and breadth-first search algorithms. It lets
us to take the benefit of both algorithms. It uses the heuristic function and
search. With the help of the best-first search, at each step, we can choose the
most promising node.
Uninformed/Blind Search:
The uninformed search does not contain any domain knowledge such as
closeness, the location of the goal. It operates in a brute-force way as it only
includes information about how to traverse the tree and how to identify leaf and
goal nodes.
It can be divided into five main types:
○ Breadth-first search
○ Uniform cost search
○ Depth-first search
○ Iterative deepening depth-first
search
○ Bidirectional Search
1. Breadth-first Search
○ Breadth-first search is the most common search strategy for traversing a tree or graph. This algorithm
searches breadthwise in a tree or graph, so it is called breadth-first search.
○ BFS algorithm starts searching from the root node of the tree and expands all successor node at the
current level before moving to nodes of next level.
○ The breadth-first search algorithm is an example of a general-graph search algorithm.
○ Breadth-first search implemented using FIFO queue data structure.
2. Depth-first Search
○ Depth-first search isa recursive algorithm for traversing a tree or graph data structure.
○ It is called the depth-first search because it starts from the root node and follows each path to its greatest depth
node before moving to the next path.
○ DFS uses a stack data structure for its implementation.
○ The process of the DFS algorithm is similar to the BFS algorithm.
3- Uniform-cost search
Uniform-cost search is a searching algorithm used for traversing a weighted tree or graph. This algorithm
comes into play when a different cost is available for each edge. The primary goal of the uniform-cost search is
to find a path to the goal node which has the lowest cumulative cost. Uniform-cost search expands nodes
according to their path costs form the root node. It can be used to solve any graph/tree where the optimal cost
is in demand. A uniform-cost search algorithm is implemented by the priority queue. It gives maximum priority
to the lowest cumulative cost. Uniform cost search is equivalent to BFS algorithm if the path cost of all edges
is the same.
Informed Search
Informed search algorithms use domain knowledge. In an informed search, problem
information is available which can guide the search. Informed search strategies can
find a solution more efficiently than an uninformed search strategy. Informed search
is also called a Heuristic search.
1. Greedy Search
2. A* Search
Greedy Search (Best First Search)
Greedy algorithms are commonly used in decision tree learning. They are
also used in:
In A* search algorithm, we use search heuristic as well as the cost to reach the node. Hence we
can combine both costs as following, and this sum is called as a fitness number.
It uses heuristic function h(n), and cost to reach the node n from the start state g(n). It
has combined features of UCS and greedy best-first search, by which it solve the
problem efficiently.
Game Playing
Game Playing is an important domain of artificial intelligence. Games don’t require much
knowledge; the only knowledge we need to provide is the rules, legal moves and the
conditions of winning or losing the game. Both players try to win the game.
Game tree:
A game tree is a tree where nodes of the tree are the game states and Edges of the
tree are the moves by players. Game tree involves initial state, actions function, and
result Function.
8 Puzzle Problem
Initial Final
Rules:
1 6 2 1 2 3 1-Empty Space can move
Upward
4 3 4 5 6 Downward
Left
7 5 8 7 8 Right
(if possible)
The 8 Puzzle, also known as the sliding puzzle, is a classic problem in the field
of artificial intelligence. It consists of a 3x3 grid with eight numbered tiles and
one empty space. The goal is to rearrange the tiles from a given initial state to
a desired goal state using the minimum number of moves
Solution
1 2 1 2 1 2 3
4 6 3 4 6 3 4 6
7 5 8 7 5 8 7 5 8
1 2 3 1 2 3 1 2 3
4 6 4 5 6 4 5 6
7 5 8 7 8 7 8
Final
Tic Tac Toe
○ From the initial state, MAX has 9 possible moves as he starts first. MAX place x and MIN place o, and
both player plays alternatively until we reach a leaf node where one player has three in a row or all
squares are filled.
○ Both players will compute each node, minimax, the minimax value which is the best achievable utility
against an optimal adversary.
○ Suppose both the players are well aware of the tic-tac-toe and playing the best play. Each player is
doing his best to prevent another one from winning. MIN is acting against Max in the game.
○ So in the game tree, we have a layer of Max, a layer of MIN, and each layer is called as Ply. Max place
x, then MIN puts o to prevent Max from winning, and this game continues until the terminal node.
○ In this either MIN wins, MAX wins, or it's a draw. This game-tree is the whole search space of
possibilities that MIN and MAX are playing tic-tac-toe and taking turns alternately.
Mini-max algorithm
In a stochastic game, the players choose actions from a set of available actions.
The state of the game changes based on the players' actions. The players'
payoff functions evolve from stage to stage. The payoff functions depend on a
state variable that is affected by the players' actions. The actions are revealed at
the end of each stage.