Professional Documents
Culture Documents
Search:
It is the process of navigating from a start state to a
goal state by transitioning through intermediate states.
Solution:
A sequence of actions that will lead from the start state to the
goal state.
Example:
Open = {A} Closed = {}
Open = {B, E} Closed = {A}
Open = {C, D, E} Closed = {A, B}
Open = {D, E} Closed = {A, B, C}
Open = {E} Closed = {A, B, C, D}
Open = {F, G} Closed = {A, B, C, D, E}
Open = {G} Closed = {A, B, C, D, E, F}
Open = {} Closed = {A, B, C, D, E, F, G}
Types of CSPs:
• Finite domains i.e. where variables have finite domains
(discrete)
• Infinite domains i.e. variables have infinite domains
(continuous)
If a CSP has n variables, the size of the domain is d, then there
are 𝑑𝑛 complete assignments.
Example:
Variables: X, Y
Domain: {1,2,3}
Constraints:
X+Y=4
X*Y=3
Solution:
X=1, Y=3
Example 2:
Problem:
Map colouring problem is to paint a map (e.g. via three colours
red, green and blue) in such a way that none of adjacent
regions can have the same colour.
Variables:
WA, NT, Q, NSW, V, SA, T
Domain:
D = {red, green, blue}
Constraints:
Adjacent regions must have different
colours.
WA ≠ NT, WA ≠ SA, NT ≠ SA, NT ≠ Q, ...
Solutions:
e.g. {WA=red, NT=green, Q=red,
NSW=green, V=red, SA=blue, T=green}
Solving CSPs:
• Generate and Test
• Breadth First Search (BFS)
• Depth First Search (DFS)
o Backtracking
▪ Filtering
• Forward Checking
▪ Ordering
• Local Search Method
Forward Checking:
Example:
Variables:
A, B, and C
Domain:
{0, 1, 2}
Constraint: Assigning A the value 0 resulted in C
B>A>C having no legal values to be assigned to
therefore this assignment is illegal.
Ordering:
Variables:
A, B, and C
Domain:
{0, 1, 2} Assigning A the value of 0 constricts C from
Constraint: having three values to having two values and in
the next step we assign C the value 1 which then
A≤B<C
constricts B to only 0. The solution would be A =
0, B = 0, C = 1
Using Backtracking, Forward Checking, and Ordering results in
a very efficient search method.
Local Search:
It is a search method (generally used when a tree cannot be
generated fully) which randomly generates a complete
assignment met with no regard to constraints. Then a random
constraint-violating variable is chosen and assigned a value
which violates the least constraints
Optimization problem:
It is a search problem with preferences.
They consist of variables, domains, and objective functions
(instead of constraints).
Objectives in optimization problems can be either single-
objective or multi-objective optimization problems.
Constraints could be present in optimization problems.
Local Search methods are more effective than Tree Search
methods.
Game:
Game is an adversarial search where there is an opponent
trying to minimize your chances of winning.
Formalization:
▪ States: S (Start state 𝑆0 )
▪ Actions: 𝐴 (may depend on player/state)
▪ Transition function: 𝑆 × 𝐴 → 𝑆
▪ Terminal test: 𝑆 → (𝑡ru𝑒, 𝑓𝑎𝑙𝑠𝑒)
▪ Players: 𝑃 = (1, ..., 𝑁) (usually take turns)
▪ Utilities: 𝑆𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙 × 𝑃 → 𝑅 (values on outcomes)
A utility function assigns a value to the result of the game for a
player p at terminal state S.
Value of state: The best achievable outcome (utility) for a state
Agent x is maximizing while Agent O is minimizing the value of
state.(minimax)
MiniMax example:
Criteria of MiniMax:
Complete? Yes, it will find a solution in the finite search tree (if it
exists)
Optimal? Yes, if both players play optimally.
Time complexity? 𝑂(𝑏 𝑚 )
Space Complexity? 𝑂(𝑏𝑚)
Alpha-Beta Pruning Algorithm
▪ α is set to - ∞ and β is set to ∞ at the root node
▪ α only changes at MAX nodes
▪ β only changes at MIN nodes
▪ a node is pruned when α ≥ β.
Example:
Fin.