You are on page 1of 20

Chapter 3

Solving Problems by Searching and


Constraint Satisfaction Problem

1
Problem Solving by Searching
• A problem-solving refers to a state where we
wish to reach to a definite goal from a present
state or condition.
• According to computer science, a problem-
solving is a part of artificial intelligence which
encompasses a number of techniques such as
algorithms, heuristics to solve a problem.

2
Problem Solving Agents
• A problem-solving agent is a goal-based agent and focuses on satisfying the
goal.
Steps performed by Problem-solving agent
• Goal Formulation: It is the first and simplest step in problem-solving. It
organizes the steps/sequence required to formulate one goal out of multiple
goals as well as actions to achieve that goal. Goal formulation is based on the
current situation and the agent's performance measure .
• Problem Formulation: It is the most important step of problem-solving which
decides what actions should be taken to achieve the formulated goal. There
are following five components involved in problem formulation:
• Initial State: It is the starting state or initial step of the agent towards its goal.
• Actions: It is the description of the possible actions available to the agent.
• Transition Model: It describes what each action does.
• Goal Test: It determines if the given state is a goal state. 3
Problem Solving Agents
• Path cost: It assigns a numeric cost to each path that
follows the goal. The problem-solving agent selects a
cost function, which reflects its performance measure.
Remember, an optimal solution has the lowest path
cost among all the solutions.
Note: Initial state, actions, and transition model together
define the state-space of the problem implicitly.
State-space of a problem is a set of all states which can be
reached from the initial state followed by any sequence of
actions. The state-space forms a directed map or graph
where nodes are the states, links between the nodes are
actions, and the path is a sequence of states connected by4
the sequence of actions.
Problem Solving Agents
• Search: It identifies all the best possible sequence of actions
to reach the goal state from the current state. It takes a
problem as an input and returns solution as its output.
• Solution: It finds the best algorithm out of various algorithms,
which may be proven as the best optimal solution.
• Execution: It executes the best optimal solution from the
searching algorithms to reach the goal state from the current
state.
For solving different kinds of problem, an agent makes use of
different strategies to reach the goal by searching the best
possible algorithms. This process of searching is known
as search strategy.
5
Problem Solving Agents
Example: Toy Problem - 8 Puzzle Problem:
Problem Solving Agents
•  Here, we have a 3x3 matrix with movable tiles
numbered from 1 to 8 with a blank space.
• The tile adjacent to the blank space can slide into that
space.
• The objective is to reach a specified goal state similar to
the goal state, as shown in the below figure.
• In the figure, our task is to convert the current state into
goal state by sliding digits into the blank space.
• In the above figure, our task is to convert the
current(Start) state into goal state by sliding digits into
the blank space.
7
Problem Solving Agents
The problem formulation is as follows:
• States: It describes the location of each numbered tiles and
the blank tile.
• Initial State: We can start from any state as the initial state.
• Actions: Here, actions of the blank space is defined, i.e.,
either left, right, up or down
• Transition Model: It returns the resulting state as per the
given state and actions.
• Goal test: It identifies whether we have reached the correct
goal-state.
• Path cost: The path cost is the number of steps in the path
where the cost of each step is 1. 8
Problem Solving Agents

Measuring problem-solving performance


• Before discussing different search strategies, the performance measure of an
algorithm should be measured.
• Consequently, There are four ways to measure the performance of an algorithm:

 Completeness: It measures if the algorithm guarantees to find a solution (if any


solution exist).
 Optimality: It measures if the strategy searches for an optimal solution.
 Time Complexity: The time taken by the algorithm to find a solution.
 Space Complexity: Amount of memory required to perform a search.

The complexity of an algorithm depends on branching factor or maximum number


of successors, depth of the shallowest goal node (i.e., number of steps from root
to the path) and the maximum length of any path in a state space. 9
Search Strategies
There are two types of strategies that describe a solution for a given problem:
• Uninformed Search (Blind Search)
This type of search strategy does not have any additional information about
the states except the information provided in the problem definition. They
can only generate the successors and distinguish a goal state from a non-goal
state. These type of search does not maintain any internal state, that’s why it
is also known as Blind search.
There are following types of uninformed searches:
• Breadth-first search
• Uniform cost search
• Depth-first search
• Depth-limited search
• Iterative deepening search
• Bidirectional search 10
Search Strategies
Informed Search (Heuristic Search)
This type of search strategy contains some additional
information about the states beyond the problem
definition. This search uses problem-specific knowledge to
find more efficient solutions. This search maintains some
sort of internal states via heuristic functions (which
provides hints), so it is also called heuristic search.
There are following types of informed searches:
• Best first search (Greedy search)
• A* search
11
Search Strategies
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. 12
Search Strategies
Advantages:
• BFS will provide a solution if any solution exists.
• If there are more than one solutions for a given problem,
then BFS will provide the minimal solution which
requires the least number of steps.
Disadvantages:
• It requires lots of memory since each level of the tree
must be saved into memory to expand the next level.
• BFS needs lots of time if the solution is far away from the
root node.
13
Search Strategies
Example: In the below tree structure, we have shown the traversing of the tree using BFS
algorithm from the root node S to goal node K. BFS search algorithm traverse in layers, so it
will follow the path which is shown by the dotted arrow, and the traversed path will be:
• S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K  

14
Search Strategies
• Time Complexity: Time Complexity of BFS algorithm can
be obtained by the number of nodes traversed in BFS
until the shallowest Node. Where the d= depth of
shallowest solution and b is a node at every state.
T (b) = 1+b2+b3+.......+ bd= O (bd)
• Space Complexity: Space complexity of BFS algorithm is
given by the Memory size of frontier which is O(b d).
• Completeness: BFS is complete, which means if the
shallowest goal node is at some finite depth, then BFS
will find a solution.
• Optimality: BFS is optimal if path cost is a non-decreasing
function of the depth of the node. 15
Constraint Satisfaction Problems
• Constraint satisfaction is a technique where a problem is solved when its
values satisfy certain constraints or rules of the problem. 
• Such type of technique leads to a deeper understanding of the problem s
• Constraint satisfaction depends on three components, namely:
X: It is a set of variables.
D: It is a set of domains where the variables reside. There is a specific
domain for each variable.
C: It is a set of constraints which are followed by the set of variables.
• In constraint satisfaction, domains are the spaces where the variables
reside, following the problem specific constraints. These are the three
main elements of a constraint satisfaction technique.
• The constraint value consists of a pair of {scope, rel}. The scope is a tuple
of variables which participate in the constraint and rel is a relation which
includes a list of values which the variables can take to satisfy the
16
constraints of the problem.
Constraint Satisfaction Problems
Solving Constraint Satisfaction Problems
The requirements to solve a constraint satisfaction problem (CSP) is:
• A state-space
• The notion of the solution.
A state in state-space is defined by assigning values to some or all variables
such as
{X1=v1, X2=v2, and so on…}.
An assignment of values to a variable can be done in three ways:
• Consistent or Legal Assignment: An assignment which does not violate any
constraint or rule is called Consistent or legal assignment.
• Complete Assignment: An assignment where every variable is assigned
with a value, and the solution to the CSP remains consistent. Such
assignment is known as Complete assignment.
• Partial Assignment: An assignment which assigns values to some of the
variables only. Such type of assignments are called Partial assignments. 17
Constraint Satisfaction Problems
Types of Domains in CSP
There are following two types of domains which are used by the variables :
• Discrete Domain: It is an infinite domain which can have one state for multiple
variables. For example, a start state can be allocated infinite times for each
variable.
• Finite Domain: It is a finite domain which can have continuous states describing
one domain for one specific variable. It is also called a continuous domain.
Constraint Types in CSP
With respect to the variables, basically there are following types of constraints:
• Unary Constraints: It is the simplest type of constraints that restricts the value
of a single variable.
• Binary Constraints: It is the constraint type which relates two variables. A
value x2 will contain a value which lies between x1 and x3.
• Global Constraints: It is the constraint type which involves an arbitrary number
of variables.
18
Constraint Satisfaction Problems
Constraint propagation is a special type of inference which helps in reducing
the legal number of values for the variables. The idea behind constraint
propagation is local consistency.
There are following local consistencies which are discussed below:
• Node Consistency: A single variable is said to be node consistent if all the
values in the variable’s domain satisfy the unary constraints on the
variables.
• Arc Consistency: A variable is arc consistent if every value in its domain
satisfies the binary constraints of the variables.
• Path Consistency: When the evaluation of a set of two variable with
respect to a third variable can be extended over another variable,
satisfying all the binary constraints. It is similar to arc consistency.
• k-consistency: This type of consistency is used to define the notion of
stronger forms of propagation. Here, we examine the k-consistency of the
variables. 19
Constraint Satisfaction Problems

20

You might also like