Assignment - 3 Solution
Assignment - 3 Solution
ANS: 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 structure as well as its complexity.
Constraint satisfaction depends on three components:
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.
A finite set of variables which stores the solution (V = {V1, V2, V3,....., Vn})
A set of discrete values known as domain from which the solution is picked (D = {D1, D2,
D3,.....,Dn})
In maths or other the elements in the domain can be both continuous and discrete but in AI,
we generally only deal with discrete values.
Here all these sets should be finite except for the domain set. Each variable in the variable set
can have different domains.
2. n-Queen (In an n-queen problem, n queens should be placed in an nXn matrix such that no
queen shares the same row, column or diagonal.)
3. Map Colouring (colouring different regions of map, ensuring no adjacent regions have the
same color)
Step 3: Create a constraint set with variables and domains (if possible) after considering the
constraints.
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…}.
1. Consistent or Legal Assignment: An assignment which does not violate any constraint
or rule is called Consistent or legal assignment.
2. 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.
3. Partial Assignment: An assignment which assigns values to some of the variables
only. Such type of assignments is called Partial assignments.
There are following two types of domains which are used by the variables:
1. 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.
2. 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.
1. Unary Constraints: It is the simplest type of constraints that restricts the value of a
single variable.
2. Binary Constraints: It is the constraint type which relates two variables. A value x2
will contain a value which lies between x1 and x3.
3. Global Constraints: It is the constraint type which involves an arbitrary number of
variables.
# Some special types of solution algorithms are used to solve the following types of
constraints:
#CSP Problems:
Constraint satisfaction includes those problems which contains some constraints while
solving the problem. CSP includes the following problems:
1) Graph Colouring: The problem where the constraint is that no adjacent sides can have
the same color.
2) Sudoku Playing: The gameplay where the constraint is that no number from 0-9 can
be repeated in the same row or column.
3) Crossword: In crossword problem, the constraint is that there should be the correct
formation of the words, and it should be meaningful.
A Hill Climbing algorithm example can be a traveling salesman’s problem where we may
need to minimize or maximize the distance travelled by the salesman.
This algorithm has a node that comprises two parts: state and value. It begins with a non-
optimal state (the hill’s base) and upgrades this state until a certain precondition is met.
The heuristic function is used as the basis for this precondition. The process of continuous
improvement of the current state of iteration can be termed as climbing. This explains why
the algorithm is termed as a hill-climbing algorithm.
1. It employs a greedy approach: This means that it moves in a direction in which the
cost function is optimized. The greedy approach enables the algorithm to establish
local maxima or minima.
2. No Backtracking: A hill-climbing algorithm only works on the current state and
succeeding states (future). It does not look at the previous states.
3. Feedback mechanism: The algorithm has a feedback mechanism that helps it decide
on the direction of movement (whether up or down the hill). The feedback mechanism
is enhanced through the generate-and-test technique.
4. Incremental change: The algorithm improves the current solution by incremental
changes.
This is a simple form of hill climbing that evaluates the neighboring solutions. If the next
neighbor state has a higher value than the current state, the algorithm will move. The
neighboring state will then be set as the current one.
Algorithm
Conduct an assessment of the current state. Stop the process and indicate success if it
is a goal state.
Perform looping on the current state if the assessment in step 1 did not establish a goal
state.
Continue looping to attain a new solution.
Assess the new solution. If the new state has a higher value than the current state in
steps 1 and 2, then mark it as a current state.
Continue steps 1 to 4 until a goal state is attained. If this is the case, then exit the
process.
Applications
Marketing
A hill-climbing algorithm can help a marketing manager to develop the best marketing plans.
This algorithm is widely used in solving Traveling-Salesman problems. It can help by
optimizing the distance covered and improving the travel time of sales team members. The
algorithm helps establish the local minima efficiently.
Robotics
Hill climbing is useful in the effective operation of robotics. It enhances the coordination of
different systems and components in robots.
Job Scheduling
The hill climbing algorithm has also been applied in job scheduling. This is a process in
which system resources are allocated to different tasks within a computer system. Job
scheduling is achieved through the migration of jobs from one node to a neighbouring node.
A hill-climbing technique helps establish the right migration route.
Advantages:
1. Can switch between BFS and DFS, thus gaining the advantages of both.
2. More efficient when compared to DFS.
Disadvantages:
1. Chances of getting stuck in a loop are higher.
Here C is the initial or source node and L and Z are goal nodes.
Open: C
Closed: —
Open: T, O, E, B, P
Closed: C
Open: O, E, B, P
Closed: C, T
As T does not have any successors, the next node from open that is O is removed
from Open and added to closed.
Open: E, B, P
Closed: C, T, O
Open: I, E, B, P, N
Closed: C, T, O
Now, node I is removed from Open and added to closed.
Open: E, B, P, N
Closed: C, T, O, I
Open: Z, E, B, P, N
Closed: C, T, O, I
Now, node Z is removed from Open and added to closed.
Open: E, B, P, N
Closed: C, T, O, I, Z
4) Explain A* searching technique in detail with example. Discuss conditions for the
optimality of this technique.
Ans: A* Algorithm-
A* Algorithm is one of the best and popular techniques used for path finding and graph
traversals.
A lot of games and web-based maps use this algorithm for finding the shortest path
efficiently.
It is essentially a best first search algorithm.
Working-
Algorithm-
Step-01:
Step-03:
Remove node n with the smallest value of f(n) from OPEN and move it to list
CLOSED.
If node n is a goal state, return success and exit.
Step-04:
Expand node n.
Step-05:
If any successor to n is the goal node, return success and the solution by tracing the
path from goal node to S.
Otherwise, go to Step-06.
Step-06:
Step-07:
Go back to Step-02.
Example-01:
Solution-
Solution-
Step-01:
Step-02:
Path- A → F → G
Step-03:
Path- A → F → G → I
Step-04:
Path- A → F → G → I → J
This is the required shortest path from node A to node J.
5) Will Breadth First Search always find Optimal Solution. Why? Elaborate with a good
example.
Ans: Breadth First Search always find Optimal Solution because, BFS is a traversing
algorithm where you should start traversing from a selected node (source or starting node) and
traverse the graph layer wise thus exploring the neighbour nodes (nodes which are directly
connected to source node). You must then move towards the next-level neighbour nodes.
As the name BFS suggests, you are required to traverse the graph breadthwise as follows:
1. First move horizontally and visit all the nodes of the current layer
2. Move to the next layer
Breadth-first search algorithm likes to stay as close as possible to the starting point.
Some of the situations that I can think of are:
1. Social networking websites can use it for finding the people in the specified distance.
2. It can be useful in tormenting/peer-to-peer network to look for neighbouring computers.
3. GPS navigation systems can use it to find nearby locations.
Consider the following diagram.
The distance between the nodes in layer 1 is comparitively lesser than the distance between the
nodes in layer 2. Therefore, in BFS, you must traverse all the nodes in layer 1 before you move
to the nodes in layer 2.
Step 1: In the graph, every vertex or node is known. First, initialize a queue.
Step 2: In the graph, start from source node A and mark it as visited.
Step 3: Then you can observe B and E, which are unvisited nearby nodes from A.
You have two nodes in this example, but here choose B, mark it as visited, and
enqueue it alphabetically.
Step 4: Node E is the next unvisited neighboring node from A. You enqueue it after
marking it as visited.
Step 5: A now has no unvisited nodes in its immediate vicinity. As a result, you
dequeue and locate A.
Step 6: Node C is an unvisited neighboring node from B. You enqueue it after
marking it as visited.
Step 7: Node D is an unvisited neighboring node from C. You enqueue it after
marking it as visited.
Step 8: If all of D's adjacent nodes have already been visited, remove D from the
queue.
Step 9: Similarly, all nodes near E, B, and C nodes have already been visited;
therefore, you must remove them from the queue.
Step 10: Because the queue is now empty, the bfs traversal has ended.
6) Consider the following graph.
Starting from state A, execute DFS. The goal node is G. Show the order in which the
nodes are expanded? Assume that the alphabetically smaller node is expanded first to
break ties.
a) Blind Search
1) Depth first search
2) Breadth first search
3) Iterative deepening search
4) Bidirectional search
b) Informed Search.
MCQ Questions:
d) Average of Path cost from start node to current node and Heuristic cost
7) Which of the following graphs are useful for solving decomposable problems.