0% found this document useful (0 votes)
9 views22 pages

FALLSEM2024-25 BEEE411L TH CH2024250101504 Reference Material I 02-09-2024 Module - 4 CSP

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)
9 views22 pages

FALLSEM2024-25 BEEE411L TH CH2024250101504 Reference Material I 02-09-2024 Module - 4 CSP

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/ 22

Constraint satisfaction

problems
Constraint satisfaction
• Discover some problem that satisfies a given set of constraints.
• Design must be created within fixed limits on time, cost and materials.
• It reduces substantial amount of search that is required as compared with methods that
finds partial solutions.
• For example: If you want to travel to a place ‘X’, with ‘n’ possible modes, you will have
varieties of solution without any constraints. If the travel is bounded to time, money,
distance and/or any other factors, then the solution can be arrived at lesser time.
• It is a search procedure that operates in a space of constraint sets.
– Initial state contains constraints that are originally given in the problem description.
– Goal state is any state that has been constrained “enough”, where “enough” must be defined for each
problem.
Constraint satisfaction
• It is a two-step process:
– Constraints are discovered and propagated as far as possible throughout the system. If the solution is not found, then
search begins.
– A guess about something is made and added as a new constraint. Propagation can then occur with this new constraint,
and so forth.
• Constraint propagation terminates for two reasons:
– A contradiction may be detected, if it happens, then there is no solution consistent with all the known constraints. If the
contradictions involves only those constraints that were given as a part of the problem specification, then no solution
exists.
– The propagation has run out of the steam and there are no further changes that can be made on the current knowledge.
If this happens and a solution has not yet been adequately specified, then the search is necessary to get the process
moving again.
Algorithm: Constraint satisfaction
• Propagate the available constraints. To perform this, OPEN to the set of all objects that
must have values assigned to them in a complete solution. Do until an inconsistency is
empty.
– Select an OB from OPEN. Strengthen as much as possible the set of constraints that apply to OB.
– If this set is different from the set that was assigned the last time OB was examined or if this is the first time OB has been examined,
then add OPEN to all objects that share any constraints with OB.
– Remove OB from OPEN.
• If the union of constraints discovered above defines a solution, then quit and report the solution,
• If the union of constraints discovered above defines a contradiction, then return failure.
• If neither of the above occurs, then it is necessary to make a guess at something in order to proceed. To do
this, loop until a solution is found or all possible solutions have been eliminated:
– Select an object whose value is not determined and select a way of strengthening the constraints on that object.
– Recursively invoke constraint satisfaction with the current set of constraints augmented by the strengthening constraint just selected.
Monte – Carlo Tree search
• It is a heuristic search algorithm used for decision-making in artificial intelligence,
particularly in games and scenarios that involve complex choices.
• It combines tree search methods with Monte Carlo simulations to explore the
consequences of actions and to identify the optimal strategies over time.
• MCTS has been used successfully in board games like Go, chess, and other decision-making
problems, as it handles large state spaces efficiently.
• It consists of four main steps:
– Selection
– Expansion
– Simulation
– Backpropagation
Monte – Carlo Tree search
• Selection:
– Start from the root node and select child nodes based on a selection policy, typically a balance between exploitation
(favoring nodes that have yielded good results) and exploration (favoring nodes that are less explored).
– A popular selection strategy is the Upper Confidence Bound for Trees (UCB1), which balances exploration and
exploitation.
• Expansion:
– Once a leaf node is reached, if the node is not a terminal node (i.e., the game or decision isn't over), new child nodes are
added.
– These represent possible future actions or moves.
• Simulation (Rollout):
– From the newly added node, a simulation is run by making random moves until a terminal state is reached (win, lose, or
draw, in the case of games). This gives an estimate of the outcome of that sequence of actions.
• Backpropagation:
– The result of the simulation is then backpropagated through the tree, updating the statistics (e.g., win/loss records) for
each node along the path from the selected node back to the root.
– These steps are repeated many times, gradually refining the tree and guiding the search toward better actions.
Monte – Carlo Tree search
Monte – Carlo Tree search is applied in the following scenarios:
• The state space is very large, making traditional search methods infeasible.
• It's difficult to evaluate the exact value of non-terminal states.
• Randomized simulations can provide reasonable estimates of state value.
Monte – Carlo Tree search - example
Problem Setup: We are designing an AI to play Tic-Tac-Toe using MCTS. Assume the AI plays
as "X," and it is the AI's turn to make a move
✓ Selection: The algorithm starts at the root node, representing the current board
configuration. The selection process begins, navigating the game tree to find a leaf node to
expand. Initially, all moves are equally likely since no simulations have been run. Example
current board state:

✓ Here, "X" can make a move in one of the four remaining empty spaces. The selection policy
(UCB1) will guide the choice. At the start, since no statistics are available, it randomly
selects one of the available moves.
Monte – Carlo Tree search - example
Problem Setup: We are designing an AI to play Tic-Tac-Toe using MCTS. Assume the AI plays
as "X," and it is the AI's turn to make a move
✓ Expansion:After selecting a node (for instance, placing "X" in the bottom middle), if the
node represents a non-terminal state (i.e., the game is not over), the child nodes are
expanded to explore possible future states. Board after "X" moves to the bottom middle:

✓ Here, "X" can make a move in one of the four remaining empty spaces. The selection policy
(UCB1) will guide the choice. At the start, since no statistics are available, it randomly
selects one of the available moves.
Monte – Carlo Tree search - example
Problem Setup: We are designing an AI to play Tic-Tac-Toe using MCTS. Assume the AI plays
as "X," and it is the AI's turn to make a move
✓ Simulation(Rollout): A simulation is run from the expanded node, randomly selecting
valid moves for both players until a terminal state (win/loss/draw) is reached.
✓ Simulated moves: "O" places its mark in the top right. "X" places its mark in the bottom left and wins.
✓ Simulated final state:
Monte – Carlo Tree search - example
Problem Setup: We are designing an AI to play Tic-Tac-Toe using MCTS. Assume the AI plays
as "X," and it is the AI's turn to make a move
✓ Backpropagation: The result of the simulation (a win for "X") is backpropagated through
the tree. Each node along the path from the expanded node to the root updates its
win/visit counts. For the node representing the bottom middle move, its win count is
incremented, and its visit count is updated.
Monte – Carlo Tree search - example
Problem Setup: We are designing an AI to play Tic-Tac-Toe using MCTS. Assume the AI plays
as "X," and it is the AI's turn to make a move
✓ Repeat: This process (selection, expansion, simulation, backpropagation) repeats thousands
of times. Over time, the algorithm will gather statistics for each possible move at the root
node (current state of the board). The move with the highest win rate is selected as the AI’s
next move.
✓ Decision Making: After sufficient simulations, the MCTS will select the move that maximizes its
winning probability. In this example, the AI might decide to place "X" in the bottom middle
position, as simulations suggest that this leads to victory more frequently.
Minimax search procedure
✓ Itis an algorithm used in decision-making and game theory to minimize the possible loss in
a worst-case scenario.
✓ It is typically applied to zero-sum games, where one player’s gain is another player’s loss.
✓ The algorithm assumes that both players play optimally. The key concepts of Minimax are
as follows:
✓ Maximizing Player: Tries to maximize their score.
✓ Minimizing Player: Tries to minimize the maximizing player’s score (i.e., maximize their own score in a two-player
game).
✓ Game Tree: Represents possible moves for both players. Each node is a game state, and branches are possible actions.
✓ Terminal Node: A game state where the game ends, and an outcome is assigned (win, loss, or draw).
✓ Evaluation Function: Assigns a score to each terminal state (e.g., win = +1, loss = -1, draw = 0).
Steps of Minimax search
✓ Generate the Game Tree: List all possible moves for both players from the current state.
✓ Apply Minimax:
✓ Recursively evaluate each move.
✓ For the maximizing player, choose the move with the highest score.
✓ For the minimizing player, choose the move with the lowest score.

✓ Backpropagate Values: The value of each node is the best possible outcome for the player
whose turn it is.
✓ Choose
the Optimal Move: The root of the game tree will show the best move based on the
Minimax evaluation.
Example: tic-tac-toe - game tree construction
1. Maximizing Player (X’s Turn): X has two possible moves:
1. Move 1: X plays at (2,1)
2. Move 2: X plays at (3,1)

2. After X’s move, O plays (Minimizing Player): O then places their mark, trying to minimize X's chances of
winning.
1. For each move, generate possible responses by O, and continue until the game reaches terminal states (win, loss, or draw).
• Evaluating Moves Using Minimax:
1. If X plays at (2,1), O may play at (3,1). This leads to one terminal state:
– X wins in this case, so the score is +1 for X.
2. If X plays at (3,1), O can block X by playing at (2,1). This leads to a draw, so the score is 0.

• Backpropagation:
• If X plays at (2,1), the outcome is a win for X (+1).
• If X plays at (3,1), the outcome is a draw (0).
• Final Decision:
– Since X (the maximizing player) wants to maximize their score, they will choose to play at (2,1), as it gives them the highest score (+1,
a guaranteed win).
Example: tic-tac-toe - game tree construction
Example: tic-tac-toe

• Advantages of Minimax:
• Guarantees an optimal solution if both players play perfectly.
• Simple and effective for small games like Tic-Tac-Toe.

• Limitations:
• For large games (e.g., chess), the number of possible states can become too large to
compute exhaustively. In such cases, algorithms like Alpha-Beta pruning are
used to reduce the number of nodes evaluated.
Alpha-beta pruning:
• It is an optimization technique for the Minimax algorithm used in decision-making, primarily in
game theory.
• It helps reduce the number of nodes that need to be evaluated in the game tree, making the
Minimax algorithm more efficient without affecting the outcome.
• Alpha-Beta pruning eliminates the need to explore subtrees that cannot possibly influence the
final decision. It "prunes" branches in the game tree, saving computational resources by ignoring
branches that are irrelevant for determining the best move.
• Terminology:
– Alpha (α): The best value (highest) that the maximizing player can guarantee up to that point.
– Beta (β): The best value (lowest) that the minimizing player can guarantee up to that point.
• Alpha and beta values are used to cut off branches of the game tree when a better option has
already been found.
Steps in Alpha-beta pruning:
• Maximizing Player (Alpha): The maximizing player tries to maximize the score.
Alpha is updated whenever a new best move is found for the maximizing player.
• Minimizing Player (Beta): The minimizing player tries to minimize the score.
Beta is updated whenever a new best move is found for the minimizing player.
• Pruning: If at any point during evaluation, the maximizing player finds a move
that is guaranteed to be better than any move the minimizing player has
evaluated so far, further evaluation of this branch is "pruned" or stopped.
• Pruning condition: Prune if β ≤ α: When the current move evaluation makes the
value of the node worse than what has already been found in previous moves, the
subtree below this node can be ignored because it cannot influence the final
decision.
Example: Tic-Tac-Toe
• Consider a simplified game tree for a Tic-Tac-Toe scenario, where
Player X (Maximizing) and Player O (Minimizing) alternate
moves.
• Evaluation without Alpha-Beta Pruning:
– The Minimax algorithm evaluates all nodes in the tree, leading to an exhaustive search of
all possible moves.
Example: Tic-Tac-Toe
• Evaluation with Alpha-Beta Pruning:
• Alpha-Beta pruning can cut off unnecessary
evaluations:

– Start at the root node (X’s turn), and explore the first child.
– Evaluate the first branch completely, computing alpha (for X) and beta (for O).
– As soon as you find a move that results in a worse outcome than the already evaluated
branches (for the minimizing player O), prune the remaining branches in that part of
the tree.
Alpha-beta pruning logic
• At the top, it's X's (Max) turn, and X wants to maximize the score.
• The first branch is evaluated fully, giving a score of 3.
• Then O (Min) is evaluated. On the left branch, O minimizes, and the score is 1.
This makes O’s best option beta = 1.
• If in subsequent evaluations, another branch gives X a score higher than 1, we
can stop evaluating other options for O, as O will never allow X to take this
branch (because O can block it earlier with a score of 1 or better).

You might also like