0% found this document useful (0 votes)
33 views33 pages

Ai Unit 3

Adversarial search involves planning in competitive environments where agents have conflicting goals, often modeled through games like chess, which are deterministic, turn-taking, and zero-sum. The Minimax algorithm is a key method used to determine optimal moves by simulating all possible actions and their outcomes, while Alpha-Beta pruning optimizes this process by eliminating unnecessary evaluations. Evaluation functions and techniques like quiescence search help refine decision-making in real-time scenarios where complete search is impractical.

Uploaded by

satwik.ug23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views33 pages

Ai Unit 3

Adversarial search involves planning in competitive environments where agents have conflicting goals, often modeled through games like chess, which are deterministic, turn-taking, and zero-sum. The Minimax algorithm is a key method used to determine optimal moves by simulating all possible actions and their outcomes, while Alpha-Beta pruning optimizes this process by eliminating unnecessary evaluations. Evaluation functions and techniques like quiescence search help refine decision-making in real-time scenarios where complete search is impractical.

Uploaded by

satwik.ug23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

UNIT 3

Adversarial Search and Games


 In adversarial search, an agent must plan ahead in an environment where
other agents are actively planning against it.
 The unpredictability of these other agents can introduce contingencies into
the agent’s problem-solving process
 This creates a competitive scenario, different from single-agent search (like
A*), because outcomes depend on the actions of both agents.
 When agents are in conflict, we get adversarial search problems (a.k.a.
games)

Games in AI
 Games are a type of multiagent environment, specifically when the agents
have conflicting goals.
 In AI, the most common games are of a rather specialized kind—what game
theorists call deterministic, turn-taking, two-player, zero-sum games of
perfect information (such as chess)

Commonly studied games in AI are :


➤ Deterministic
➤ Two-player
➤ Turn-taking
➤ Perfect-information - Both players have complete visibility into the game
state (unlike poker or bridge).
➤ Zero-sum - The sum of utilities for both players is always constant (commonly
zero). A win for one is an equal loss for the other. Example: Chess outcomes —
(+1, 0), (0, +1), or (½, ½)

These characteristics make analysis and modeling tractable for AI research


Why Games Are Interesting for AI
 Games are too hard to solve completely, but:
o Easy to represent
o Have a limited set of actions
o Have strict and precise rules
 Example:
o Chess: Average branching factor ≈ 35
o Depth: ~50 moves per player
o Possible positions: ≈ 10^154
o Distinct nodes: ≈ 10^40
 Unlike toy problems (e.g., 8-puzzle), games mimic real-world complexity
 Games, like the real world, require the ability to make some decision even
when calculating the optimal decision is infeasible therefore we must come
up with the best possible decision within time and computational limits
 Inefficient algorithms are severely punished:
o An A* search algorithm that’s half as efficient just runs slower.
o A chess engine that’s half as efficient loses the game.

Hence, game-playing research focuses on real-time performance optimization.

A game can be formally defined as a kind of search problem with the following
elements:

S0: The initial state, which specifies how the game is set up at the start.

PLAYER(s): Defines which player has the move in a state.

ACTIONS(s): Returns the set of legal moves in a state.

RESULT(s, a): The transition model, which defines the result of a move

TERMINAL-TEST(s): A terminal test, which is true when the game is over and false
otherwise. States here the game has ended are called terminal state

UTILITY(s, p): A utility function (also called an objective function or payoff


function), defines the final numeric value for a game that ends in terminal state s
for a player p. In chess, the outcome is a win, loss, or draw, with values +1, 0, or ½
MAX and MIN Players
 AI agents in games are typically assigned two roles:
o MAX: Tries to maximize the utility (score).
o MIN: Tries to minimize the utility (hurt MAX).

These roles define a competitive relationship, key to adversarial search logic.

Game Tree vs. Search Tree

➤ Game Tree

 A full tree of all possible states and actions in the game.


 Theoretically complete but too large to traverse for complex games like
chess.

➤ Search Tree

 The subset of the game tree that the AI actually explores to decide on the
next move.
 Includes only enough nodes to find a good decision within time constraints.

Importance of Pruning & Evaluation


 Pruning: Allows us to ignore parts of the tree that don't affect the decision.
 Heuristic Evaluation Functions:
o Allows us to estimate utility of a state without performing a full-depth
search.
o Necessary for complex games where full traversal is infeasible

Stochastic & Imperfect-Information Games


 Some games (e.g., backgammon) include an element of chance — modeled
using probabilities.
 Others (e.g., bridge) include imperfect information — not all state details
are visible to all players.
Optimal Decisions in Games –
 In normal search problems, the optimal solution is a sequence of actions
leading to a goal state (win).

 In adversarial search, MAX must account for MIN’s potential responses.

 Hence, MAX requires a contingent strategy, not a fixed action sequence:

 MAX’s move in the initial state


 MAX’s moves in the states resulting from every possible response by MIN
 then MAX’s moves in the states resulting from every possible response by
MIN to those moves
 and so on….

This is exactly analogous to the AND–OR search algorithm with MAX playing the
role of OR and MIN equivalent to AND

Analogy with AND–OR Trees:

 MAX = OR nodes → Chooses best action


 MIN = AND nodes → Considers all possible responses

Minimax Value
The minimax value of a node is the utility (for MAX) of being in the corresponding
state, assuming that both players play optimally from there to the end of the
game, the minimax value of a terminal state is just its utility

given a choice, MAX prefers to move to a state of maximum value, whereas MIN
prefers a state of minimum value
Minimax value is determined by assuming that both players play optimally from
that point onwards, if Min does not play optimally then Max will do even better

Minimax Algorithm –
The Minimax Algorithm is used by a player (usually MAX) to decide the best
possible move assuming the opponent (MIN) plays optimally to minimize MAX’s
advantage.

How it works (in steps):

1. Start at the root node (the current game state).


2. Recursively simulate every possible move for both MAX and MIN until
terminal states (leaf nodes) are reached.
3. At leaf nodes, return the utility value — how good or bad the outcome is
for MAX.
4. Back up values:
o At MIN nodes, choose the minimum utility (worst-case for MAX).
o At MAX nodes, choose the maximum utility (best for MAX).
5. The move with the highest backed-up value at the root is selected.

Complexity:

 Time Complexity: O(b^m)


o b = branching factor (avg. number of moves per state)
o m = depth of game tree
o Why? Because every possible state is explored.
 Space Complexity:
o O(bm) if all actions are generated and stored
o O(m) if actions are generated one by one (typical in depth-first
search)

For real games, of course, the time cost is totally impractical, but this algorithm
serves as the basis for the mathematical analysis of games and for more practical
algorithms
Optimal decisions in multiplayer games
When there are more than two players (e.g., Players A, B, C), the minimax idea
must be extended to handle multiple utility perspectives.

Key Changes from Two-Player Games:

1. Utility is now a vector, not a single number.


Example: A state has utilities (v_A, v_B, v_C) = (1, 2, 6).
2. The UTILITY function now returns a vector for each terminal state.
3. At each node, the current player chooses the action that maximizes their
own value in the vector.

Two available actions:

 Action 1 → terminal state: (1, 2, 6)


 Action 2 → terminal state: (4, 2, 3)

Player C chooses the action that gives them the highest value → 6 > 3, so Player C
chooses Action 1.

Generalized Backup Rule:

 At each node, the current player selects the child node with the highest
value for themselves.
 The backed-up value of the node is the entire vector from the chosen child.

Strategic Implications:

 In multiplayer games, alliances can form strategically:


o Example: A & B might collaborate to weaken a strong Player C.
o Once C is weakened, A and B may break the alliance and turn on
each other.
o players might have to balance the immediate advantage of breaking
an alliance against the long-term disadvantage of being perceived as
untrustworthy
o This is a natural result of each player following selfish optimal
strategies.
Non-Zero-Sum Games:

 Players don’t always have to compete.


 If a terminal state offers maximum benefit to both players, they will
naturally cooperate.
o Example: State = (1000, 1000) → both A & B aim to reach this state
together.

Heuristic Alpha--Beta Tree Search


Minimax checks every node in the game tree to find the best move, which means:

 Time complexity: O(b^m)


o b = branching factor (number of legal moves per state)
o m = maximum depth of the tree

That’s very expensive for deep games like chess

Alpha–Beta Pruning is a search optimization technique that allows Minimax to


skip evaluating parts of the tree that won’t affect the final decision.

It gives the same result as Minimax, But skips useless computations

How does it work?

Alpha–Beta keeps track of two values during the recursive search:

 α = the value of the best (i.e., highest-value) choice we have found so far at
any choice point along the path for MAX
 β = the value of the best (i.e., lowest-value) choice we have found so far at
any choice point along the path for MIN.These values help in cutting off
branches:

Alpha–beta search updates the values of α and β as it goes along and prunes the
remaining branches at a node (i.e., terminates the recursive call) as soon as the
value of the current node is known to be worse than the current α or β value for
MAX or MIN, respectively
Move Ordering Matters!
Effectiveness of alpha-beta pruning is highly dependent on the order in which
states are examined, we will not be able to prune any successors if the worst
successors are generated first, if the best successor is generated first then we will
be able to prune the others

This suggests that it might be worthwhile to try to examine first the successors
that are likely to be best. If this can be done, then it turns out that alpha–beta
needs to examine only O(b^m/2) nodes to pick the best move, instead of O(b^m)
for minimax. This means that the effective branching factor becomes √ b instead
of b—for chess, about 6 instead of 35

If successors are examined in random order rather than best-first, the total
number of nodes examined will be roughly O(b3m/4) for moderate b. For chess, a
fairly simple ordering function (such as trying captures first, then threats, then
forward moves, and then backward moves) gets you to within about a factor of 2
of the best-case O(bm/2) result

 Best-case scenario: Prune as much as possible → time complexity becomes


O(b^(m/2)).
o This effectively doubles the depth you can explore compared to
Minimax!
 Worst-case: No pruning → still behaves like normal Minimax

Iterative Deepening + Move Ordering:

 Search depth 1 → find a good move


 Use that move to prioritize choices in depth 2
 Continue this process

This technique:

 Helps with better move ordering


 Often leads to hitting the best-case pruning scenario
Such best moves from earlier searches are called killer moves and to try them
first is called the killer move heuristic.

Repeated states in the search tree can cause an exponential increase in search
cost. In many games, repeated states occur frequently because of
transpositions—different permutations of the move sequence that end up in the
same position

It is worthwhile to store the evaluation of the resulting position in a hash table


the first time it is encountered so that we don’t have to recompute it on
subsequent occurrences .The hash table of previously seen positions is
traditionally called a transposition table; it is essentially identical to the explored
list in GRAPH-SEARCH

Using a transposition table can have a dramatic effect, sometimes as much as


doubling the reachable search depth in chess. On the other hand, if we are
evaluating a million nodes per second, at some point it is not practical to keep all
of them in the transposition table

Imperfect Real-Time Decisions


 Minimax and Alpha–Beta are complete search algorithms that go all the
way to terminal states.
 But in real-time games (like chess), it’s not feasible to search entire game
trees due to time constraints (e.g., 3 minutes per move).
 Claude Shannon’s paper Programming a Computer for Playing Chess (1950)
proposed instead that programs should cut off the search earlier and apply
a heuristic evaluation function to estimate utility.

Alter minimax or alpha–beta in two ways: replace the utility function by a


heuristic evaluation function EVAL, which estimates the non- terminal nodes
utility, and replace the terminal test by a cutoff test that decides when to apply
EVAL
Evaluation functions
An evaluation function returns an estimate of the expected utility of the game
from a given position

1. The evaluation function should order the terminal states in the same way
as the true utility function: states that are wins must evaluate better than
draws, which in turn must be better than losses
2. The computation must not take too long
3. For nonterminal states, the evaluation function should be strongly
correlated with the actual chances of winning

Even though deterministic, cutoff introduces uncertainty, as we cannot compute


all possible outcomes, Evaluation functions estimate expected outcomes of
positions

Example:

In a category like "2 pawns vs 1 pawn":

 72% lead to win → Utility = +1


 20% lead to loss → Utility = 0
 8% lead to draw → Utility = 0.5
 Expected value = 0.72×1 + 0.2×0 + 0.08×0.5 = 0.76

Feature-Based Evaluation
Common in chess:

 Material value: Pawn = 1, Knight/Bishop = 3, Rook = 5, Queen = 9.


 Add other features: pawn structure, king safety, etc.

Mathematical Form:

EVAL(s) = w1·f1(s) + w2·f2(s) + ... + wn·fn(s)

 fi(s) = feature, wi = corresponding weight


Notes:

 Assumes independence between features (often false).


 Better programs use nonlinear combinations or learn weights using ML

Cutting Off Search


Simple Cutoff:

 Set a fixed depth d (e.g., 4 plies).


 If d is reached → return EVAL(s) instead of continuing further.
 This works like a time budget — deeper searches are more accurate but
slower.

Iterative Deepening:

 Start with depth 1, then 2, then 3… until time runs out.


 At each depth, store the best move found so far to help with move
ordering.
 This gives you a move to play even if time is short

These simple approaches can lead to errors due to the approximate nature of the
evaluation function, example: A position might look good (ahead in material) but
actually leads to a loss one ply deeper

Quiescence Search
Some positions are “noisy” — they're unstable because of:

 Threats (e.g., checks, captures)


 Immediate tactical possibilities

Evaluating such positions without resolving the volatility leads to wildly


inaccurate scores. The evaluation function should be applied only to positions
that are quiescent—that is, unlikely to exhibit wild swings in value in the near
future
Nonquiescent positions can be expanded further until quiescent positions are
reached. This extra search is called a quiescence search

Solution: Extend the Search Selectively

 If a position is non-quiescent, don’t evaluate it yet.


 Extend the search only for tactical moves, typically:
o Captures
o Checks
o Threats
 Stop once a quiet position is reached → then apply EVAL(s)

This helps stabilize the evaluation and avoid silly mistakes caused by shallow
cutoff

Horizon effect

The horizon effect is more difficult to eliminate. It arises when the program is
facing an opponent’s move that causes serious damage and is ultimately
unavoidable, but can be temporarily avoided by delaying tactics

The agent mistakenly thinks it "escaped" because the bad outcome happens
beyond the cut off depth that is just over the horizon

One strategy to mitigate the horizon effect is the singular extension, a move that
is “clearly better” than all other moves in a given position. Once discovered
anywhere in the tree in the course of a search, this singular move is remembered

When the search reaches the normal depth limit, the algorithm checks to see if
the singular extension is a legal move; if it is, the algorithm allows the move to be
considered. This makes the tree deeper, but because there will be few singular
extensions, it does not add many total nodes to the tree.
Forward pruning

Instead of evaluating all legal moves at every node (which is expensive), ignore
the ones that are likely to be bad early on.

Forward pruning, meaning that some moves at a given node are pruned
immediately without further consideration. Clearly, most humans playing chess
consider only a few moves from each position (at least consciously)

Techniques:

1. Beam Search

 At each level, only consider the best n moves (e.g., based on a shallow
eval) instead of considering all moves.
 Similar to a spotlight: you “beam” focus onto the most promising options.
 Fast, but unfortunately, this approach is rather dangerous because there is
no guarantee that the best move will not be pruned away.

2. PROBCUT (Probabilistic Cut)

 The PROBCUT, or probabilistic cut, algorithm (Buro, 1995) is a forward-


pruning version of alpha–beta search that uses statistics gained from prior
experience to estimate whether a node will fall outside the (α, β)
window.
 If it's probably irrelevant → skip it entirely.
 Helps reduce unnecessary computation.

Search versus lookup

In many games (like chess), there are points in the game where we already know
the best moves, thanks to either human knowledge or complete computation.
Instead of wasting time searching, the AI can just look them up.
It is not surprising, therefore, that many game-playing programs use table lookup
rather than search for the opening and ending of games.

Opening Phase: Opening Books

An opening book is a precompiled database of strong opening moves, built from:

 Grandmaster-level games
 Engine simulations (e.g., Stockfish, AlphaZero)

It tells the AI:

 “In this position, the best next move is X”


 Without doing any evaluation or search

Endgame Phase: Retrograde Analysis

When the board is simplified (only a few pieces left), it's possible to compute all
possible outcomes perfectly. That’s where retrograde analysis comes in, Instead
of starting from the current position and searching forward, retrograde analysis
works backwards:

1. Start with known end states (e.g., checkmate positions).


2. From each, move backwards to earlier positions.
3. Figure out what player can force a win/loss/draw, and how many moves it
takes.

All this info is stored in a lookup table. So when the AI reaches one of these
positions, it doesn’t search — it just looks up the outcome and best move.

Why It Matters

 Lookup is instant and perfect — ideal for well-known or fully solved parts
of the game.
 Search is flexible but costly — needed when the game is too complex to
fully precompute.
 Strong AIs combine both,Lookup in the opening and endgame, Search in
the unpredictable middle game
Limitations of Game Search Algorithms
1. Computational Complexity

 Exponential Growth: The game tree grows exponentially with depth


(branching factor^depth), making it infeasible to search the entire tree for
complex games like chess or Go.
 Time Constraints: Real-time games require quick decisions, but deep search
takes time.

2. Limited Evaluation Function Accuracy

 In games where it's impractical to search until terminal states (e.g., chess),
the algorithm relies on a heuristic evaluation function.
 If the heuristic is poor or too simple, it might lead to suboptimal decisions.

3. Incomplete Information & Stochastic Elements

 Many classic search algorithms assume perfect information (e.g., chess,


checkers), but this doesn’t apply to games like poker or real-time strategy
games.
 Algorithms like Minimax don’t naturally handle randomness (e.g., dice rolls
in backgammon).

4. Memory Usage

 Some algorithms (like Minimax with large trees or storing transposition


tables) consume a lot of memory, especially when optimizing with
memoization or keeping large trees in memory.
5. Branching Factor Bottlenecks

 In games with a high number of possible moves per state (e.g., Go), the
sheer number of options makes even shallow searches overwhelming.

6. Not Generalizable

 Algorithms are often tailored to specific games and don't generalize well
across different game types or domains.
Constraint Satisfaction Problems
A Constraint Satisfaction Problem (CSP) consists of three main components:

1. Variables (X):
A finite set of variables
X = {X1, X2, ..., Xn}
2. Domains (D):
Each variable Xi has a domain Di of possible values
D = {D1, D2, ..., Dn}
Example: Di = {red, green, blue}
3. Constraints (C):
Rules that define allowable combinations of values
C = {C1, C2, ..., Cm}

Each constraint Ci has a:

 Scope: The variables involved.


 Relation (rel): Allowed combinations of values (can be explicitly listed or
abstract)

To solve a CSP, we need to define a state space and the notion of a solution. Each
state in a CSP is defined by an assignment of values to some or all of the
variables, {Xi = vi , Xj = vj ,...}.

CSP Definitions
 Assignment: A mapping of some variables to values.
o Example: {X1 = v1, X2 = v2}
 Consistent Assignment: No constraints are violated.
 Complete Assignment: All variables are assigned.
 Solution: A consistent and complete assignment.
 Partial Assignment: Assignment to only some variables.
Why formulate a problem as a CSP?

 It provides a Natural representation for many problems, it is often easier


to use a CSP-solving sytem rather than designing a custom solution to a
problem
 CSP solvers can be faster than state-space searchers because the CSP solver
can quickly eliminate large areas of the search space through constraint
propagation, As a result, many problems that are intractable for regular
state-space search can be solved quickly when formulated as a CSP
 Helps identify why an assignment is invalid—we see which variables violate
a constraint

Variations on the CSP Formalism


CSPs can vary based on the type of domains and constraints they use.

1. Finite Discrete Domains

 Each variable has a limited and countable set of values.


 These are the most common types used in classic CSPs.
 Example Problems:
o Map Coloring: Choose a color for each region from a finite set.
o 8-Queens: Place 8 queens on an 8×8 board so that no two attack
each other.
 Domain of each queen (row position): {1,...,8}

2. Infinite Discrete Domains

 Variables can take on an unlimited countable number of values.


 Useful in logic or rule-based systems.
 Example:
o Variables range over natural numbers: {0, 1, 2, ...}

Note: Solving becomes trickier because you can't simply enumerate all values.
3. Continuous Domains

 Variables range over real numbers (ℝ).


 Common in engineering and scientific applications.
 Example:
o Satellite Scheduling: Task start times can be any real number.

Solving Techniques:

 Linear Programming (LP):


o Used when constraints are linear.
o Solvable in polynomial time.
 Nonlinear Constraints:
o Constraints involve non-linear relationships.
o No general algorithm exists; usually needs approximation or
heuristic methods.

Many real-world CSPs also include preference constraints indicating which


solutions are preferred

Every finite-domain constraint can be reduced to a set of binary constraints if


enough auxiliary variables are introduced, so we could transform any CSP into one
with only binary constraints; this makes the algorithms simpler. There are
however two reasons why we might prefer a global constraint rather than a set of
binary constraints.
First, it is easier and less error-prone to write the problem description using global
constraints. Second, it is possible to design special-purpose inference algorithms
for global constraints that are not available for a set of more primitive constraints.

Constraint Propagation: Inference in CSPs


In regular state-space search, an algorithm can do only one thing: search. In CSPs
there is a choice: an algorithm can search (choose a new variable assignment
from several possibilities) or do a specific type of inference called constraint
propagation

Constraint Propagation involves reducing the search space by:

 Using the constraints to reduce the number of legal values for a variable,
which in turn can reduce the legal values for another variable, and so on
 This is called enforcing local consistency, we eliminate inconsistent values
to simplify the problem before or during search

This leads to early detection of failure and faster solutions.

Local Consistency
Local consistency defines how much constraint propagation has occurred. Types:

Node Consistency (NC)

 A variable is node consistent if:


o All values in its domain satisfy the varaiables unary constraints
(constraints involving a single variable).
 Apply by removing values that violate unary constraints.
 It is always possible to eliminate all the unary constraints in a CSP by
running node consistency
Arc Consistency (AC)

 A variable in a CSP is arc-consistent if every value in its domain satisfies the


variable’s binary constraints
 More formally, Xi is arc-consistent with respect to another variable Xj if for
every value in the current domain Di there is some value in the domain Dj
that satisfies the binary constraint on the arc (Xi, Xj )
 The most popular algorithm for arc consistency is called AC-3: Iteratively
remove values from domains that are not arc consistent .
 It is possible to extend the notion of arc consistency to handle n-ary rather
than just binary constraints; this is called generalized arc consistency or
sometimes hyperarc consistency
 A variable Xi is generalized arc consistent with respect to an n-ary
constraint if for every value v in the domain of Xi there exists a tuple that
has all its values taken from the domains of the corresponding variables
and this tuple is a member of the constraint

Path Consistency (PC)

 Arc consistency can go a long way toward reducing the domains of


variables, sometimes finding a solution (by reducing every domain to size 1)
and sometimes finding that the CSP cannot be solved (by reducing some
domain to size 0), But for other networks, arc consistency fails to make
enough inferences
 Path consistency tightens the binary constraints by using implicit
constraints that are inferred by looking at triples of variables.
 A two-variable set {Xi, Xj} is path-consistent with respect to a third variable
Xm if, for every assignment {Xi = a, Xj = b} consistent with the constraints
on {Xi, Xj}, there is an assignment to Xm that satisfies the constraints on {Xi,
Xm} and {Xm, Xj}. This is called path consistency because one can think of it
as looking at a path from Xi to Xj with Xm in the middle.
 It helps prune the solution space more than arc consistency but is more
computationally expensive.
k-Consistency

 A CSP is k-consistent if:


o For any set of (k-1) variables and consistent assignment to them, a
consistent value can always be assigned to any kth variable.
 Special Cases:
o 1-consistency = node consistency
o 2-consistency = arc consistency
o 3-consistency = path consistency
 Strong k-consistency: A CSP is strongly k-consistent if it is k-consistent and
is also (k − 1)-consistent, (k − 2)-consistent, ... all the way down to 1-
consistent
 Any algorithm for establishing n-consistency must take time exponential in
n in the worst case. Worse, n-consistency also requires space that is
exponential in n

Global constraints
Global constraints occur frequently in real problems and can be handled by
special-purpose algorithms that are more efficient than the general-purpose
methods described so far

1. Alldiff Constraint

 Requires that all involved variables must take distinct values.


 Appears in problems like:
o Cryptarithmetic puzzles
o Sudoku
o Map coloring (regions with shared borders)

 If m variables involved in Alldiff have only n possible distinct values left, and
m>n, then the constraint cannot be satisfied (a pigeonhole problem).

Inconsistency Detection Algorithm:

1. Remove singleton variables (variables with only one possible value).


2. Delete those values from the domains of remaining variables.
3. Repeat until no singleton remains.
4. If:
o Any variable ends up with an empty domain, or
o There are more variables than available domain values left,
o An inconsistency has been detected.

2. Atmost Constraint (Resource Constraint)

 Ensures that the sum of values assigned to variables does not exceed a
certain threshold.

Inconsistency Detection:

 Compute the sum of the minimum values from each variable’s domain.
 If the total exceeds the limit ⇒ Inconsistency.

Domain Reduction Strategy:

 Remove max values from domains if they violate feasibility when combined
with min values of other variable domains.

3. Bounds Propagation

 In large integer-based problems, full domain enumeration is inefficient.


 Instead, represent domains as intervals: [lower bound, upper
bound].
 We say that a CSP is bounds consistent if for every variable X, the lower-
bound and upper-bound values of X, there exists some value for every
variable Y that satisfies the constraint between X and Y
Backtracking Search for CSPs
CSPs cannot be solved by inference alone; there comes a time when we must
search for a solution

The Naive Problem

Naively, you’d have n! * d^n possibilities — assigning d values to n variables in


any order. Our seemingly reasonable but naive formulation ignores crucial
property common to all CSPs: commutativity

Commutativity tells us the order of variable assignments doesn't matter for


CSPs. So, we reduce branching from n*d to just d at each level

Backtracking Search – Core Idea


Backtracking search is like recursive DFS over partial assignments:

 The term backtracking search is used for a depth-first search that chooses
values for one variable at a time and backtracks when a variable has no
legal values left to assign
 You assign values one variable at a time.
 If a value leads to inconsistency, you backtrack and try the next option.
 This avoids exploring entire assignments that will definitely fail

To improve performance of search algorithms we supply them with domain-


specific heuristic functions derived from our knowledge of the problem. We can
solve CSPs efficiently without such domain-specific knowledge by answering the
following questions:

1. Which variable should be assigned next (SELECT-UNASSIGNED-VARIABLE), and


in what order should its values be tried (ORDER-DOMAIN-VALUES)?

2. What inferences should be performed at each step in the search (INFERENCE)?

3. When the search arrives at an assignment that violates a constraint, can the
search avoid repeating this failure?
Variable and Value Ordering Heuristics
1. MRV (Minimum Remaining Values)

Choose the variable with the fewest legal values left.

 Aka the fail-first strategy, it picks a variable that is most likely to cause a
failure soon, thereby pruning the search tree.
 Helps detect dead-ends early.

2. Degree Heuristic

In cases where multiple variables have the fewest legal moves we use gegree
heuristic that breaks ties by picking the variable involved in the most constraints
on other unassigned variables.

 Reduces branching factor on future choices.

3. Least Constraining Value

Once a variable has been selected, the algorithm must decide on the order in
which to examine its values, The least constraining value heuristic prefers the
value that rules out the fewest choices for the neighboring variables in the
constraint graph

 Keeps the most flexibility.

Interleaving search and inference


Every time we make a choice of a value for a variable, we have a brand-new
opportunity to infer new domain reductions on the neighboring variables

Forward Checking
One of the simplest forms of inference is called forward checking. Whenever a
variable X is assigned, the forward-checking process establishes arc consistency
for it: for each unassigned variable Y that is connected to X by a constraint, delete
from Y ’s domain any value that is inconsistent with the value chosen for X.

Although forward checking detects many inconsistencies, it does not detect all of
them. The problem is that it makes the current variable arc-consistent, but
doesn’t look ahead and make all the other variables arc-consistent

MAC (Maintaining Arc Consistency)

When assigning a variable a value, MAC runs AC-3 on neighbors to propagate


domain reductions.

 More powerful than forward checking.


 Fails early when domains go empty through deeper inferences.

MAC is strictly more powerful than forward checking because forward checking
does the same thing as MAC on the initial arcs in MAC’s queue; but unlike MAC,
forward checking does not recursively propagate constraints when changes are
made to the domains of variables

Intelligent backtracking: Looking backward


Chronological Backtracking

Default method: when stuck, just go back to the previous variable and try a
different value for it even if it had nothing to do with the failure.

A more intelligent approach to backtracking is to backtrack to a variable that


might fix the problem—a variable that was responsible for the failure

Backjumping

When stuck, jump to the most recent variable responsible for the failure.

 We maintain a conflict set to track which assignments led to the problem.


 If no legal value is found and we get stuck, the algorithm should return the
most recent element of the conflict set along with the failure indicator
 Forward checking can help build this conflict set naturally.

When we reach a contradiction, backjumping can tell us how far to back up, so we
don’t waste time changing variables that won’t fix the problem

LOCAL SEARCH FOR CSPS


 Local search starts with a complete assignment of values to all variables.
 Typically, the initial guess violates several constraints. The point of local
search is to eliminate the violated constraints, It modifies one variable at a
time to reduce the number of constraint violations.
 Often used in large-scale or real-time problems (e.g., scheduling, n-
queens).

The MIN-CONFLICTS Heuristic

In choosing a new value for a variable, the most obvious heuristic is to select the
value that results in the minimum number of conflicts with other variables

Enhancements to Local Search

These methods help escape plateaux (flat regions in the state space where no
move seems better):

a. Plateau Search - Allows "sideways" moves (equal number of conflicts).

b. Tabu Search - keeping a small list of recently visited states and forbidding the
algorithm to return to those states

c. Simulated Annealing - Occasionally allows worse moves to escape local optima.

d. Constraint Weighting
 Each constraint is given a numeric weight, Wi, initially all 1, increment the
weight of each constraint that is violated by the current assignment.
 Prioritizes fixing difficult constraints by increasing their weight if violated.
 Can help concentrate the search on the important constraints, Helps
escape plateaux by "tilting" the landscape.

Another advantage of local search is that it can be used in an online setting when
the problem changes, A backtracking search with the new set of constraints
usually requires much more time and might find a solution with many changes
while local search starting from current solution would be faster and would
produce lesser changes

The Structure of Problems


We can exploit the structure of constraint satisfaction problems (CSPs) to solve
them more efficiently

1. Independent Sub-problems

 Concept: If the constraint graph has disconnected components (like


Tasmania in the Australia map), each component can be solved separately.
 Benefit: Instead of solving one big problem with n variables, you solve
several small ones with c variables each.
 Complexity: From O(d^n) (exponential) to O(d^c * n/c) (linear in n, when c
is constant).
 Example: Breaking a CSP with 80 Boolean variables into four independent
subproblems can reduce computation time drastically.

2. Tree-Structured CSPs

 Definition: A tree structure means any two nodes are connected by only
one path, in such a CSP it is possible to create a topological ordering.
 Directed Arc Consistency (DAC) — for topologically ordered variables
X1...Xn, each variable Xi must be arc-consistent with every Xj where j > i.
 Once the graph is consistent, go from root to leaves, assigning values.
Since it's arc-consistent, each assignment will have a compatible value in its
children so no backtracking will be needed.
 Complexity: O(nd²) — linear in number of variables (with d domain size).

3. Cutset Conditioning

 Idea: If the graph isn't a tree, we can make it one by removing a small set of
nodes (cycle cutset).
 Steps:
1. Identify the cutset S such that the rest of the graph becomes a tree.
2. Try all valid assignments to variables in S.
3. For each valid assignment of S, reduce domains of remaining
variables and then solve the tree to find a valid solution to the CSP.
 Complexity: O(d^c * (n - c)d²) — efficient if c (size of cutset) is small.
 Note: Finding the smallest cutset is NP-hard, but good approximations
exist.

4. Tree Decomposition

 Concept: Decompose the graph into overlapping subproblems arranged in a


tree.
 Requirements:
1. Every variable in the original problem appears in at least one of the
subproblems.
2. If two variables are connected by a constraint in the original
problem, they must appear together (along with the constraint) in at
least one of the subproblems.
3. If a variable appears in two subproblems in the tree, it must appear
in every subproblem along the path connecting those subproblems.
 Procedure:
1. Solve each subproblem.
2. Treat each subproblem as a mega-variable.
3. Combine solutions using DAC between subproblem “nodes.”
 Tree Width: Defined as the size of the largest subproblem minus one.
o If tree width = w, total complexity = O(n * d^(w + 1)).
o Finding optimal tree width is NP-hard, but heuristics work well.

5. Value Symmetry and Symmetry-Breaking Constraints

 In CSPs like map coloring, some solutions are just reorderings of others,
That means the search space is unnecessarily inflated.
 This is called value symmetry. We would like to reduce the search space by
breaking the symmetry, We do this by introducing a symmetry-breaking
constraint
 Breaking all symmetry among intermediate search nodes (not just final
solutions) is NP-hard so we can’t always eliminate every form of
symmetry during the solving process.
 However simple symmetry-breaking rules (like ordering) go a long way.
They make the solver faster and more efficient.

You might also like