























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























Problem Solving by Search-II and Propositional Logic Adversarial Search: Games, Optimal Decisions in Games, Alpha–Beta Pruning, Imperfect Real-Time Decisions. Constraint Satisfaction Problems: Defining Constraint Satisfaction Problems, Constraint Propagation, Backtracking Search for CSPs, Local Search for CSPs, The Structure of Problems. Propositional Logic: Knowledge-Based Agents, The Wumpus World, Logic, Propositional Logic, Propositional Theorem Proving: Inference and proofs, Proof by resolution, Horn clauses and definite clauses, Forward and backward chaining, Effective Propositional Model Checking, Agents Based on Propositional Logic. Adversarial Search in Artificial Intelligence AI Adversarial search: Adversarial search is a game-playing technique where the agents are surrounded by a competitive environment. A conflicting goal is given to the agents (multiagent). These agents compete with one another and try to defeat one another in order to win the game. Such conflicting goals give rise to the adversarial search. Here, game-playing means discussing those games where human intelligence and logic factor is used, excluding other factors such as luck factor. Tic-tac-toe, chess, checkers, etc., are such type of games where no luck factor works, only mind works. Mathematically, this search is based on the concept of ‘Game Theory. ’ According to game theory, a game is played between two players. To complete the game, one has to win the game and the other looses automatically.’ Techniques required to get the best optimal solution There is always a need to choose those algorithms which provide the best optimal solution in a limited time. So, we use the following techniques which could fulfill our requirements: ● Pruning: A technique which allows ignoring the unwanted portions of a search tree which make no difference in its final result. ● Heuristic Evaluation Function: It allows to approximate the cost value at each level of the search tree, before reaching the goal node. Elements of Game Playing search
To play a game, we use a game tree to know all the possible choices and to pick the best one out. There are following elements of a game-playing: ● S0: It is the initial state from where a game begins. ● PLAYER (s): It defines which player is having the current turn to make a move in the state. ● ACTIONS (s): It defines the set of legal moves to be used in a state. ● RESULT (s, a): It is a transition model which defines the result of a move. ● TERMINAL-TEST (s): It defines that the game has ended and returns true. ● UTILITY (s,p): It defines the final value with which the game has ended. This function is also known as Objective function or Payoff function. The price which the winner will get i.e. ● (-1): If the PLAYER loses. ● (+1): If the PLAYER wins. ● (0): If there is a draw between the PLAYERS. For example, in chess, tic-tac-toe, we have two or three possible outcomes. Either to win, to lose, or to draw the match with values +1,-1 or 0. Let’s understand the working of the elements with the help of a game tree designed for tic-tac-toe. Here, the node represents the game state and edges represent the moves taken by the players.
the best choice. MAX will choose that path which will increase its utility value and MIN will choose the opposite path which could help it to minimize MAX’s utility value. MINIMAX Algorithm MINIMAX algorithm is a backtracking algorithm where it backtracks to pick the best move out of several choices. MINIMAX strategy follows the DFS (Depth-first search) concept. Here, we have two players MIN and MAX, and the game is played alternatively between them, i.e., when MAX made a move, then the next turn is of MIN. It means the move made by MAX is fixed and, he cannot change it. The same concept is followed in DFS strategy, i.e., we follow the same path and cannot change in the middle. That’s why in MINIMAX algorithm, instead of BFS, we follow DFS. ● Keep on generating the game tree/ search tree till a limit d. ● Compute the move using a heuristic function. ● Propagate the values from the leaf node till the current position following the minimax strategy. ● Make the best move from the choices. For example, in the above figure, the two players MAX and MIN are there. MAX starts the game by choosing one path and propagating all the nodes of that path. Now, MAX will backtrack to the initial node and choose the best path where his utility value will be the maximum. After this, its MIN chance. MIN will also propagate through a path and again will backtrack, but MIN will choose the path which could minimize MAX winning chances or the utility value. So, if the level is minimizing, the node will accept the minimum value from the successor nodes. If the level is maximizing, the node will accept the maximum value from the successor. Note: The time complexity of MINIMAX algorithm is O(bd) where b is the branching factor and d is the depth of the search tree.
Alpha-beta Pruning | Artificial Intelligence Alpha-beta pruning is an advance version of MINIMAX algorithm. The drawback of minimax strategy is that it explores each node in the tree deeply to provide the best path among all the paths. This increases its time complexity. But as we know, the performance measure is the first consideration for any optimal algorithm. Therefore, alpha-beta pruning reduces this drawback of minimax strategy by less exploring the nodes of the search tree. The method used in alpha-beta pruning is that it cutoff the search by exploring less number of nodes. It makes the same moves as a minimax algorithm does, but it prunes the unwanted branches using the pruning technique (discussed in adversarial search). Alpha-beta pruning works on two threshold values, i.e.,? (alpha) and? (beta). ● ?: It is the best highest value, a MAX player can have. It is the lower bound, which represents negative infinity value. ● ?: It is the best lowest value, a MIN player can have. It is the upper bound which represents positive infinity. So, each MAX node has ?-value, which never decreases, and each MIN node has ?-value, which never increases. Note: Alpha-beta pruning technique can be applied to trees of any depth, and it is possible to prune the entire subtrees easily. Working of Alpha-beta Pruning Consider the below example of a game tree where P and Q are two players. The game will be played alternatively, i.e., chance by chance. Let, P be the player who will try to win the game by maximizing its winning chances. Q is the player who will try to minimize P’s winning chances. Here,? will represent the maximum value of the nodes, which will be the value for P as well.? will represent the minimum value of the nodes, which will be the value of Q.
● So, number of pruned nodes in the above example are four and MAX wins the game with the maximum UTILITY value, i.e., The rule which will be followed is: “Explore nodes if necessary otherwise prune the unnecessary nodes.” Note: It is obvious that the result will have the same UTILITY value that we may get from the MINIMAX strategy.
Because moves must be made in a reasonable amount of time, usually it is not feasible to consider the whole game tree (even with alpha-beta), so programs should cut the search off at some point earlier and apply a heuristic evaluation function to states in the search, effectively turning nonterminal nodes into terminal leaves. i.e. Alter minimax or alpha-beta in 2 ways:
Cutting off search To modify ALPHA-BETA-SEARCH:
Types of Domains in CSP There are following two types of domains which are used by the variables : ● 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. ● 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. Constraint Types in CSP With respect to the variables, basically there are following types of constraints: ● Unary Constraints: It is the simplest type of constraints that restricts the value of a single variable. ● Binary Constraints: It is the constraint type which relates two variables. A value x2 will contain a value which lies between x1 and x. ● 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: ● Linear Constraints: These types of constraints are commonly used in linear programming where each variable containing an integer value exists in linear form only. ● Non-linear Constraints: These types of constraints are used in nonlinear programming where each variable (an integer value) exists in a non-linear form. Note: A special constraint which works in the real-world is known as Preference constraint. Constraint Propagation In local state-spaces, the choice is only one, i.e., to search for a solution. But in CSP, we have two choices either: ● We can search for a solution or ● We can perform a special type of inference called constraint propagation. Constraint propagation is a special type of inference which helps in reducing the legal number of values for the variables. The idea behind constraint propagation is local consistency. In local consistency, variables are treated as nodes , and each binary constraint is treated as an arc in the given problem. There are following local consistencies which are discussed below: ● Node Consistency: A single variable is said to be node consistent if all the values in the variable’s domain satisfy the unary constraints on the variables. ● Arc Consistency: A variable is arc consistent if every value in its domain satisfies the binary constraints of the variables. ● Path Consistency: When the evaluation of a set of two variables with respect to a third variable can be extended over another variable, satisfying all the binary constraints. It is similar to arc consistency. ● k-consistency: This type of consistency is used to define the notion of stronger forms of propagation. Here, we examine the k-consistency of the variables. CSP Problems Constraint satisfaction includes those problems which contain some constraints while solving the problem. CSP includes the following problems: ● Graph Coloring: The problem where the constraint is that no adjacent sides can have the same color.
● Sudoku Playing: The gameplay where the constraint is that no number from 0-9 can be repeated in the same row or column. ● n-queen problem: In n-queen problem, the constraint is that no queen should be placed either diagonally, in the same row or column. Note: The n-queen problem is already discussed in Problem-solving in the AI section. ● Crossword: In crossword problems, the constraint is that there should be the correct formation of the words, and it should be meaningful. ● Latin square Problem: In this game, the task is to search the pattern which is occurring several times in the game. They may be shuffled but will contain the same digits.
1. Variable and value ordering SELECT-UNASSIGNED-VARIABLE Variable selection—fail-first Minimum-remaining-values (MRV) heuristic: The idea of choosing the variable with the fewest “legal” value. A.k.a. “most constrained variable” or “fail-first” heuristic, it picks a variable that is most likely to cause a failure soon thereby pruning the search tree. If some variable X has no legal values left, the MRV heuristic will select X and failure will be detected immediately—avoiding pointless searches through other variables. E.g. After the assignment for WA=red and NT=green, there is only one possible value for SA, so it makes sense to assign SA=blue next rather than assigning Q. [Powerful guide] Degree heuristic: The degree heuristic attempts to reduce the branching factor on future choices by selecting the variable that is involved in the largest number of constraints on other unassigned variables. [useful tie-breaker] e.g. SA is the variable with highest degree 5; the other variables have degree 2 or 3; T has degree 0. ORDER-DOMAIN-VALUES Value selection—fail-last If we are trying to find all the solutions to a problem (not just the first one), then the ordering does not matter. Least-constraining-value heuristic: prefers the value that rules out the fewest choice for the neighboring variables in the constraint graph. (Try to leave the maximum flexibility for subsequent variable assignments.) e.g. We have generated the partial assignment with WA=red and NT=green and that our next choice is for Q. Blue would be a bad choice because it eliminates the last legal value left for Q’s neighbor, SA, therefore prefers red to blue. The minimum-remaining-values and degree heuristic are domain-independent methods for deciding which variable to choose next in a backtracking search. The least-constraining-value heuristic helps in deciding which value to try first for a given variable. 2. Interleaving search and inference INFERENCE forward checking: [One of the simplest forms of inference.] 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. There is no reason to do forward checking if we have already done arc consistency as a preprocessing step.
Advantage: For many problems the search will be more effective if we combine the MRV heuristic with forward checking. Disadvantage: Forward checking only makes the current variable arc-consistent, but doesn’t look ahead and make all the other variables arc-consistent. MAC (Maintaining Arc Consistency) algorithm: [More powerful than forward checking, detect this inconsistency.] After a variable Xi is assigned a value, the INFERENCE procedure calls AC-3, but instead of a queue of all arcs in the CSP, we start with only the arcs(Xj, Xi) for all Xj that are unassigned variables that are neighbors of Xi. From there, AC-3 does constraint propagation in the usual way, and if any variable has its domain reduced to the empty set, the call to AC-3 fails and we know to backtrack immediately.
3. Intelligent backtracking chronological backtracking: The BACKTRACKING-SEARCH in Fig 6.5. When a branch of the search fails, back up to the preceding variable and try a different value for it. (The most recent decision point is revisited.) E.g. Suppose we have generated the partial assignment {Q=red, NSW=green, V=blue, T=red}. When we try the next variable SA, we see every value violates a constraint. We back up to T and try a new color, it cannot resolve the problem. Intelligent backtracking: Backtrack to a variable that was responsible for making one of the possible values of the next variable (e.g. SA) impossible. Conflict set for a variable: A set of assignments that are in conflict with some value for that variable. (e.g. The set {Q=red, NSW=green, V=blue} is the conflict set for SA.) backjumping method: Backtracks to the most recent assignment in the conflict set. (e.g. backjumping would jump over T and try a new value for V.) Forward checking can supply the conflict set with no extra work. Whenever forward checking based on an assignment X=x deletes a value from Y’s domain, add X=x to Y’s conflict set; If the last value is deleted from Y’s domain, the assignment in the conflict set of Y is added to the conflict set of X. In fact,every branch pruned by backjumping is also pruned by forward checking. Hence simple backjumping is redundant in a forward-checking search or in a search that uses stronger consistency checking (such as MAC). Conflict-directed backjumping: E.g. consider the partial assignment which is proved to be inconsistent: {WA=red, NSW=red}. We try T=red next and then assign NT, Q, V, SA, no assignment can work for these last 4 variables. Eventually we run out of value to try at NT, but simple backjumping cannot work because NT doesn’t have a complete conflict set of preceding variables that caused it to fail. The set {WA, NSW} is a deeper notion of the conflict set for NT, causing NT together with any subsequent variables to have no consistent solution. So the algorithm should backtrack to NSW and skip over T. A backjumping algorithm that uses conflict sets defined in this way is called conflict-directed backjumping. How to Compute:
Local search can be used in an online setting when the problem changes, this is particularly important in scheduling problems. The structure of problem
1. The structure of constraint graph The structure of the problem as represented by the constraint graph can be used to find solution quickly. e.g. The problem can be decomposed into 2 independent subproblems: Coloring T and coloring the mainland. Tree: A constraint graph is a tree when any two varyiable are connected by only one path. Directed arc consistency (DAC): A CSP is defined to be directed arc-consistent under an ordering of variables X 1 , X 2 , … , Xn if and only if every Xi is arc-consistent with each Xj for j>i. By using DAC, any tree-structured CSP can be solved in time linear in the number of variables. How to solve a tree-structure CSP: Pick any variable to be the root of the tree; Choose an ordering of the variable such that each variable appears after its parent in the tree. (topological sort) Any tree with n nodes has n-1 arcs, so we can make this graph directed arc-consistent in O(n) steps, each of which must compare up to d possible domain values for 2 variables, for a total time of O(nd^2 ). Once we have a directed arc-consistent graph, we can just march down the list of variables and choose any remaining value. Since each link from a parent to its child is arc consistent, we won’t have to backtrack, and can move linearly through the variables.
There are 2 primary ways to reduce more general constraint graphs to trees:
1. Based on removing nodes; e.g. We can delete SA from the graph by fixing a value for SA and deleting from the domains of other variables any values that are inconsistent with the value chosen for SA. The general algorithm: Choose a subset S of the CSP’s variables such that the constraint graph becomes a tree after removal of S. S is called a cycle cutset. For each possible assignment to the variables in S that satisfies all constraints on S, (a) remove from the domain of the remaining variables any values that are inconsistent with the assignment for S, and (b) If the remaining CSP has a solution, return it together with the assignment for S. Time complexity: O(dc·(n-c)d^2 ), c is the size of the cycle cut set.
By introducing a symmetry-breaking constraint, we can break the value symmetry and reduce the search space by a factor of n!. E.g. Consider the map-coloring problems with n colors, for every consistent solution, there is actually a set of n! solutions formed by permuting the color names.(value symmetry) On the Australia map, WA, NT and SA must all have different colors, so there are 3!=6 ways to assign. We can impose an arbitrary ordering constraint NT Knowledge base: A knowledge-based agent's knowledge base, often known as KB, is a critical component. It's a group of sentences ('sentence' is a technical term that isn't the same as'sentence' in English). These sentences are written in what is known as a knowledge representation language. The KBA Knowledge Base contains information about the world. Why use a knowledge base? For an agent to learn from experiences and take action based on the knowledge, a knowledge base is required. Inference system Inference is the process of creating new sentences from existing ones. We can add a new sentence to the knowledge base using the inference mechanism. A proposition about the world is a sentence. The inference system uses logical rules to deduce new information from the KB. The inference system generates new facts for an agent to update the knowledge base. An inference system is based on two rules, which are as follows: ● Forward chaining ● Backward chaining The Wumpus World in Artificial intelligence The Wumpus world is a basic world example that demonstrates the value of a knowledge-based agent and how knowledge representation is represented. It was inspired by Gregory Yob's 1973 video game Hunt the Wumpus. The Wumpus world is a cave with 4/4 rooms and pathways connecting them. As a result, there are a total of 16 rooms that are interconnected. We now have a knowledge-based AI capable of progressing in this world. There is an area in the cave with a beast named Wumpus who eats everybody who enters. The agent can shoot the Wumpus, but he only has a single arrow. There are some Pits chambers in the Wumpus world that are bottomless, and if an agent falls into one, he will be stuck there indefinitely. The intriguing thing about this cave is that there is a chance of finding a gold heap in one of the rooms. So the agent's mission is to find the gold and get out of the cave without getting eaten by Wumpus or falling into Pits. the agent returns with gold, he will be rewarded, but if he is devoured by Wumpus or falls into the pit, he will be penalized. Note: Wumpus is immobile in this scene. A sample diagram for portraying the Wumpus world is shown below. It depicts some rooms with Pits, one room with Wumpus, and one agent in the world's (1, 1) square position. There are also some components which can help the agent to navigate the cave. These components are given as follows: ● The rooms adjacent to the Wumpus room are stinky, thus there is a stench there. ● The room next to PITs has a breeze, so if the agent gets close enough to PIT, he will feel it. ● If and only if the room contains gold, there will be glitter. ● If the agent is facing the Wumpus, the agent can kill it, and Wumpus will cry horribly, which can be heard anywhere.