Oup Assignment
Oup Assignment
INDIVIDUAL ASSIGNMENT
Id: 0l0472/14
1. What is an informed searching algorithm and discuss some informed searching algorithms in artificial
intelligence?
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should be less
than or equal to the estimated cost.
In the informed search we will discuss two main algorithms which are given below:
1. f(n)= g(n).
Advantages:
o Best first search can switch between BFS and DFS by gaining the advantages of both the
algorithms.
o This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
Example:
Consider the below search problem, and we will traverse it using greedy best-first search. At each
iteration, each node is expanded using evaluation function f(n)=h(n) , which is given in the below
table.
In this search example, we are using two lists which are OPEN and CLOSED Lists. Following are the
iteration for traversing the above example.
Time Complexity: The worst case time complexity of Greedy best first search is O(bm).
Space Complexity: The worst case space complexity of Greedy best first search is O(bm). Where, m
is the maximum depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is finite
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.
At each point in the search space, only those node is expanded which have the lowest value of
f(n), and the algorithm terminates when the goal node is found.
Algorithm of A* search:
Step1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation function
(g+h), if node n is goal node then return success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each
successor n', check whether n' is already in the OPEN or CLOSED list, if not then compute
evaluation function for n' and place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to the back
pointer which reflects the lowest g(n') value.
Advantages:
Disadvantages:
o It does not always produce the shortest path as it mostly based on heuristics and
approximation.
o A* search algorithm has some complexity issues.
o The main drawback of A* is memory requirement as it keeps all generated nodes in the
memory, so it is not practical for various large-scale problems.
Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic value of all
states is given in the below table so we will calculate the f(n) of each state using the formula f(n)=
g(n) + h(n), where g(n) is the cost to reach any node from start state.
Here we will use OPEN and CLOSED list.
Solution:
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path with cost 6.
Points to remember:
o A* algorithm returns the path which occurred first, and it does not search for all remaining
paths.
o The efficiency of A* algorithm depends on the quality of heuristic.
o A* algorithm expands all nodes which satisfy the condition f(n)<="" li="">
o Admissible: the first condition requires for optimality is that h(n) should be an admissible
heuristic for A* tree search. An admissible heuristic is optimistic in nature.
o Consistency: Second required condition is consistency for only A* graph-search.
If the heuristic function is admissible, then A* tree search will always find the least cost path.
Time Complexity: The time complexity of A* search algorithm depends on heuristic function, and
the number of nodes expanded is exponential to the depth of solution d. So the time complexity is
O(b^d), where b is the branching factor.
They may not provide a solution but their computational time is reasonably
reduced. They cannot be applied to find all solutions or to prove that no
solution exists. Let us look an algorithm to solve a constraint satisfaction
problem.
Algorithm:
1) Open all objects that must be assigned values in a complete solution.
2) Repeat until all objects assigned valid values.
3) Select an object and strengthen as much as possible. The set of constraints
that apply to object.
4) If set of constraints is different from previous set then open all objects that
share any of these constraints. Remove selected objects.
5) If union of constraints discovered above defines a solution, return solution.
6) If union of constraints discovered above defines a contradiction, return failure
7) Make a guess in order to proceed. Repeat until a solution is found.
8) Select an object with a number assigned value and try strengthen its
constraints.
Algorithm that can Avoid Repeated States (Algorithms that forget their
history are sure to repeate the states.)
If an algorithm remembers every state that it has visited, then it can be viewed
as exploring state space graph directly.
We can device a new algorithm called as graph-search algorithm which is more
efficient than earlier tree-search algorithm. A graph-search algorithm maintains
two data structures closed list and open list to avoid exporation of those node
which are already explored (i.e. trying to avoid repeated states).
Close list: A closed list is a data structure maintained by algorithm which
stores every expanded node. Algorithm discards the current node if it matches
with node on the closed list.
Open list: A open list is a data structure maintained by algorithm which stores
fringe of unexpanded node.
Graph-Search Algorithm
[Data structure required]:
- Node n
-State description
- Parent (may be backpointer) (if needed)
-Operator used to generate n (optional)
- Depth of n(optional)
- Path cost from s to n (if available)
- Open list
• initialization: {s}
• node insertion removal depends on specific search strategy
- Closed list
• initialization: { }
• organized by backpointers to construct a solution path
[Algorithm]:
open : ={s};
closed : = {};
repeat
{
n : = select (open); /* select one node from open for expansion */
if n is a goal
then exit with success; /* delayed goal testing */
expand (n)
/* generate all children of n put these newly generated nodes in open (check
duplicates)
put n in closed (check duplicates) */
until open = {};
}
exit with failure
For the above algorithm worst case time and space requirements are
proportional to the size of the state space. This may be much smaller than O
(bd).
A repeated state is detected when algorithm has found two paths to same
state. if the newly discovered path is shorter than the original one then it will be
discarded by algorithm. Then there is a chance that graph-search could miss
an optimal solution as it can discard one of the paths that can lead to optimal
state.
Adversarial Search
Adversarial search is a search, where we examine the problem which arises when we try to plan
ahead of the world and other agents are planning against us.
o In previous topics, we have studied the search strategies which are only associated with a single
agent that aims to find the solution which often expressed in the form of a sequence of actions.
o But, there might be some situations where more than one agent is searching for the solution in the
same search space, and this situation usually occurs in game playing.
o The environment with more than one agent is termed as multi-agent environment, in which each
agent is an opponent of other agent and playing against each other. Each agent needs to consider
the action of other agent and effect of that action on their performance.
o So, Searches in which two or more players with conflicting goals are trying to explore the same
search space for the solution, are called adversarial searches, often known as Games.
o Games are modeled as a Search problem and heuristic evaluation function, and these are the two
main factors which help to model and solve games in AI.
Imperfect information Battleships, blind, tic-tac-toe Bridge, poker, scrabble, nuclear war
o Perfect information: A game with the perfect information is that in which agents can look into the
complete board. Agents have all the information about the game, and they can see each other moves
also. Examples are Chess, Checkers, Go, etc.
o Imperfect information: If in a game agents do not have all information about the game and not
aware with what's going on, such type of games are called the game with imperfect information,
such as tic-tac-toe, Battleship, blind, Bridge, etc.
o Deterministic games: Deterministic games are those games which follow a strict pattern and set of
rules for the games, and there is no randomness associated with them. Examples are chess,
Checkers, Go, tic-tac-toe, etc.
o Non-deterministic games: Non-deterministic are those games which have various unpredictable
events and has a factor of chance or luck. This factor of chance or luck is introduced by either dice or
cards. These are random, and each action response is not fixed. Such games are also called as
stochastic games.
Example: Backgammon, Monopoly, Poker, etc.
Note: In this topic, we will discuss deterministic games, fully observable environment, zero-sum, and
where each agent acts alternatively.
Zero-Sum Game
o Zero-sum games are adversarial search which involves pure competition.
o In Zero-sum game each agent's gain or loss of utility is exactly balanced by the losses or gains of
utility of another agent.
o One player of the game try to maximize one single value, while other player tries to minimize it.
o Each move by one player in the game is called as ply.
o Chess and tic-tac-toe are examples of a Zero-sum game.
o What to do.
o How to decide the move
o Needs to think about his opponent as well
o The opponent also thinks what to do
Each of the players is trying to find out the response of his opponent to their actions. This requires
embedded thinking or backward reasoning to solve the game problems in AI.
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.
The following figure is showing part of the game-tree for tic-tac-toe game. Following are some key
points of the game:
o 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.
o Both players will compute each node, minimax, the minimax value which is the best achievable utility
against an optimal adversary.
o 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.
o 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.
o 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.
o It aims to find the optimal strategy for MAX to win the game.
o It follows the approach of Depth-first search.
o In the game tree, optimal leaf node could appear at any depth of the tree.
o Propagate the minimax values up to the tree until the terminal node discovered.
In a given game tree, the optimal strategy can be determined from the minimax value of each node,
which can be written as MINIMAX(n). MAX prefer to move to a state of maximum value and MIN
prefer to move to a state of minimum value then: