Game Search Constrained Search CMSC 25000 Artificial Intelligence

  • Slides: 62
Download presentation
Game Search & Constrained Search CMSC 25000 Artificial Intelligence January 20, 2004

Game Search & Constrained Search CMSC 25000 Artificial Intelligence January 20, 2004

Roadmap I • Searching for the right move – Review adversial search – Optimal

Roadmap I • Searching for the right move – Review adversial search – Optimal Alpha-beta – State-of-the-art: Specialized techniques – Dealing with chance

Optimal Alpha-Beta Ordering 1 2 5 6 3 7 8 4 9 10 11

Optimal Alpha-Beta Ordering 1 2 5 6 3 7 8 4 9 10 11 12 13 141516 171819 202122 232425 262728 293031 323334 353637 383940 14 15 16 17 18 19 20 21 22 13 14 15 26 27 28 29 30 31 13 14 15 35 36 37 38 39 40

Optimal Ordering Alpha-Beta • Significant reduction of work: – 11 of 27 static evaluations

Optimal Ordering Alpha-Beta • Significant reduction of work: – 11 of 27 static evaluations • Lower bound on # of static evaluations: – if d is even, s = 2*b^d/2 -1 – if d is odd, s = b^(d+1)/2+b^(d-1)/2 -1 • Upper bound on # of static evaluations: – b^d • Reality: somewhere between the two – Typically closer to best than worst

Heuristic Game Search • Handling time pressure – Focus search – Be reasonably sure

Heuristic Game Search • Handling time pressure – Focus search – Be reasonably sure “best” option found is likely to be a good option. • Progressive deepening – Always having a good move ready • Singular extensions – Follow out stand-out moves

Singular Extensions • Problem: Explore to some depth, but things change a lot in

Singular Extensions • Problem: Explore to some depth, but things change a lot in next ply – False sense of security – aka “horizon effect” • Solution: “Singular extensions” – If static value stands out, follow it out – Typically, “forced” moves: • E. g. follow out captures

Additional Pruning Heuristics • Tapered search: – Keep more branches for higher ranked children

Additional Pruning Heuristics • Tapered search: – Keep more branches for higher ranked children • Rank nodes cheaply • Rule out moves that look bad • Problem: – Heuristic: May be misleading • Could miss good moves

Deterministic Games Due to Russell and Norvig

Deterministic Games Due to Russell and Norvig

Games with Chance • Many games mix chance and strategy – E. g. Backgammon

Games with Chance • Many games mix chance and strategy – E. g. Backgammon – Combine dice rolls + opponent moves • Modeling chance in game tree – For each ply, add another ply of “chance nodes” – Represent alternative rolls of dice • One branch per roll • Associate probability of roll with branch

Expectiminimax: Minimax+Chance • Adding chance to minimax – For each roll, compute max/min as

Expectiminimax: Minimax+Chance • Adding chance to minimax – For each roll, compute max/min as before • Computing values at chance nodes – Calculate EXPECTED value – Sum of branches • Weight by probability of branch

Expecti… Tree

Expecti… Tree

Summary • Game search: – Key features: Alternating, adversarial moves • Minimax search: Models

Summary • Game search: – Key features: Alternating, adversarial moves • Minimax search: Models adversarial game • Alpha-beta pruning: – If a branch is bad, don’t need to see how bad! – Exclude branch once know can’t change value – Can significantly reduce number of evaluations • Heuristics: Search under pressure – Progressive deepening; Singular extensions

Constraint Propagation Artificial Intelligence CMSC 25000 January 20, 2004

Constraint Propagation Artificial Intelligence CMSC 25000 January 20, 2004

Agenda • Constraint Propagation: Motivation • Constraint Propagation Example – Waltz line labeling •

Agenda • Constraint Propagation: Motivation • Constraint Propagation Example – Waltz line labeling • Constraint Propagation Mechanisms – Arc consistency – CSP as search • Forward-checking • Back-jumping • Summary

Leveraging Representation • General search problems encode taskspecific knowledge – Successor states, goal tests,

Leveraging Representation • General search problems encode taskspecific knowledge – Successor states, goal tests, state structure – “black box” wrt to search algorithm • Constraint satisfaction fixes representation – Variables, values, constraints – Allows more efficient, structure-specific search

Constraint Satisfaction Problems • Very general: Model wide range of tasks • Key components:

Constraint Satisfaction Problems • Very general: Model wide range of tasks • Key components: – Variables: Take on a value – Domains: Values that can be assigned to vars – Constraints: Restrictions on assignments • Constraints are HARD – Not preferences: Must be observed • E. g. Can’t schedule two classes: same room, same time

Constraint Satisfaction Problem • Graph/Map Coloring: Label a graph such that no two adjacent

Constraint Satisfaction Problem • Graph/Map Coloring: Label a graph such that no two adjacent vertexes same color – Variables: Vertexes – Domain: Colors – Constraints: If E(a, b), then C(a) != C(b)

Constraint Satisfaction Problems • Resource Allocation: – Scheduling: N classes over M terms, 4

Constraint Satisfaction Problems • Resource Allocation: – Scheduling: N classes over M terms, 4 classes/term – Aircraft at airport gates • Satisfiability: e. g. 3 -SAT – Assignments of truth values to variables such that 1) consistent and 2) clauses true

Constraint Satisfaction Problem • “N-Queens”: – Place N queens on an Nx. N chessboard

Constraint Satisfaction Problem • “N-Queens”: – Place N queens on an Nx. N chessboard such that none attacks another – Variables: Queens (1/column) – Domain: Rows – Constraints: Not same row, column, or diagonal

N-queens Q 3 Q 1 Q 4 Q 2

N-queens Q 3 Q 1 Q 4 Q 2

Constraint Satisfaction Problem • Range of tasks: – Coloring, Resource Allocation, Satisfiability – Varying

Constraint Satisfaction Problem • Range of tasks: – Coloring, Resource Allocation, Satisfiability – Varying complexity: E. g. 3 -SAT NP-complete • Complexity: Property of problem NOT CSP • Basic Structure: – Variables: Graph nodes, Classes, Boolean vars – Domains: Colors, Time slots, Truth values – Constraints: No two adjacent nodes with same color, • No two classes in same time, consistent, satisfying ass’t

Problem Characteristics • Values: – Finite? Infinite? Real? • Discrete vs Continuous • Constraints

Problem Characteristics • Values: – Finite? Infinite? Real? • Discrete vs Continuous • Constraints – Unary? Binary? N-ary? • Note: all higher order constraints can be reduced to binary

Representational Advantages • Simple goal test: – Complete, consistent assignment • Complete: All variables

Representational Advantages • Simple goal test: – Complete, consistent assignment • Complete: All variables have a value • Consistent: No constraints violates • Maximum depth? – Number of variables • Search order? – Commutative, reduces branching – Strategy: Assign value to one variable at a time

Constraint Satisfaction Questions • Can we rule out possible search paths based on current

Constraint Satisfaction Questions • Can we rule out possible search paths based on current values and constraints? • How should we pick the next variable to assign? • Which value should we assign next? • Can we exploit problem structure for efficiency?

Constraint Propagation Method • For each variable, – Get all values for that variable

Constraint Propagation Method • For each variable, – Get all values for that variable – Remove all values that conflict with ALL adjacent • A: For each neighbor, remove all values that conflict with ALL adjacent – Repeat A as long as some label set is reduced

Constraint Propagation Example • Image interpretation: – From a 2 -D line drawing, automatically

Constraint Propagation Example • Image interpretation: – From a 2 -D line drawing, automatically determine for each line, if it forms a concave, convex or boundary surface – Segment image into objects • Simplifying assumptions: – World of polyhedra • No shadows, no cracks

CSP Example: Line Labeling • 3 Line Labels: – Boundary line: regions do not

CSP Example: Line Labeling • 3 Line Labels: – Boundary line: regions do not abut: > • Arrow direction: right hand side walk – Interior line: regions do abut • Concave edge line: _ • Convex edge line : + • Junction labels: – Where line labels meet

CSP Example: Line Labeling • Simplifying (initial) restrictions: – No shadows, cracks – Three-faced

CSP Example: Line Labeling • Simplifying (initial) restrictions: – No shadows, cracks – Three-faced vertexes – General position: • small changes in view-> no change in junction type • 4^2 labels for 2 line junction: L • 4^3; 3 -line junction : Fork, Arrow, T • Total: 208 junction labelings

CSP Example: Line Labeling • Key observation: Not all 208 realizable – How many?

CSP Example: Line Labeling • Key observation: Not all 208 realizable – How many? 18 physically realizable All Junctions L junctions + _ Fork Junctions + + _ _ T junctions + _ + _ _ Arrow junctions + _ _ _+ _ +

CSP Example: Line Labeling • Label boundaries clockwise • Label arrow junctions + +

CSP Example: Line Labeling • Label boundaries clockwise • Label arrow junctions + + +

CSP Example: Line Labeling • Label boundaries clockwise

CSP Example: Line Labeling • Label boundaries clockwise

CSP Example: Line Labeling • Label fork junctions with +’s + + + +

CSP Example: Line Labeling • Label fork junctions with +’s + + + +

CSP Example: Line Labeling • Label arrow junctions with -’s + + _ _

CSP Example: Line Labeling • Label arrow junctions with -’s + + _ _ + + + _ + +

Waltz’s Line Labeling • For each junction in image, – Get all labels for

Waltz’s Line Labeling • For each junction in image, – Get all labels for that junction type – Remove all labels that conflict with ALL adjacent • A: For each neighbor, remove all labels that conflict with ALL – Repeat A as long as some label set is reduced

Waltz Propagation Example + + X C D + _ X + B A

Waltz Propagation Example + + X C D + _ X + B A + _+ _ _ + X

Waltz’s Line Labeling • Full version: – Removes constraints on images • Adds special

Waltz’s Line Labeling • Full version: – Removes constraints on images • Adds special shadow and crack labels • Includes all possible junctions – Not just 3 face • Physically realizable junctions – Still small percentage of all junction labels – O(n) : n = # lines in drawing

Constraint Propagation Mechanism • Arc consistency – Arc V 1 ->V 2 is arc

Constraint Propagation Mechanism • Arc consistency – Arc V 1 ->V 2 is arc consistent if for all x in D 1, there exists y in D 2 such that (x, y) is allowed • Delete disallowed x’s to achieve arc consistency

Arc Consistency Example • Graph Coloring: • Variables: Nodes • Domain: Colors (R, G,

Arc Consistency Example • Graph Coloring: • Variables: Nodes • Domain: Colors (R, G, B) • Constraint: If E(a, b), then C(a) != C(b) • Initial assignments R, G, B Y R, B X B Z

Arc Consistency Example Arc X -> Y X -> Z Y-> Z X ->

Arc Consistency Example Arc X -> Y X -> Z Y-> Z X -> Y Rm Value None X=B Y=B X=R X -> Z Y -> Z None Y ======> R, G, B R, B Assignments: X=G Y=R Z=B X B Z

Limitations of Arc Consistency • Arc consistent: G, B – No legal assignment •

Limitations of Arc Consistency • Arc consistent: G, B – No legal assignment • Arc consistent: Y G, B X G, B Z – >1 legal assignment R, G Y G, B X G, B Z

CSP as Search • Constraint Satisfaction Problem (CSP) is a restricted class of search

CSP as Search • Constraint Satisfaction Problem (CSP) is a restricted class of search problem – State: Set of variables & assignment info • Initial State: No variables assigned • Goal state: Set of assignments consistent with constraints – Operators: Assignment of value to variable

CSP as Search • Depth: Number of Variables • Branching Factor: |Domain| • Leaves:

CSP as Search • Depth: Number of Variables • Branching Factor: |Domain| • Leaves: Complete Assignments • Blind search strategy: – Bounded depth -> Depth-first strategy • Backtracking: – Recover from dead ends – Find satisfying assignment

CSP as Search X=B X=R Y=R X=G Y=B Y=R Y=B No! Z=B Z=RZ=B Z=R

CSP as Search X=B X=R Y=R X=G Y=B Y=R Y=B No! Z=B Z=RZ=B Z=R No! No! Yes! Z=B Z=R No!

Backtracking Issues • CSP as Search – Depth-first search • Maximum depth = #

Backtracking Issues • CSP as Search – Depth-first search • Maximum depth = # of variables – Continue until (partial/complete) assignment • Consistent: return result • Violates constraint -> backtrack to previous assignment – Wasted effort • Explore branches with no possible legal assignment

Backtracking with Forward Checking • Augment DFS with backtracking – Add some constraint propagation

Backtracking with Forward Checking • Augment DFS with backtracking – Add some constraint propagation • Propagate constraints – Remove assignments which violate constraint – Only propagate when domain = 1 • “Forward checking” • Limit constraints to test

Backtracking+Forward Checking X=R Y=B Y=R No! Z=B X=G Y=B Y=R Z=R Yes! No!

Backtracking+Forward Checking X=R Y=B Y=R No! Z=B X=G Y=B Y=R Z=R Yes! No!

Heuristic CSP • Improving Backtracking – Standard backtracking • Back up to last assignment

Heuristic CSP • Improving Backtracking – Standard backtracking • Back up to last assignment – Back-jumping • Back up to last assignment that reduced current domain • Change assignment that led to dead end

Heuristic backtracking: Back-jumping C 1 C 3 C 5 C 2 C 4

Heuristic backtracking: Back-jumping C 1 C 3 C 5 C 2 C 4

Heuristic Backtracking: Backjumping C 1 C 2 C 3 C 4 C 5

Heuristic Backtracking: Backjumping C 1 C 2 C 3 C 4 C 5

Heuristic Backtracking: Backjumping C 1 C 2 C 3 C 4 Dead end! Why?

Heuristic Backtracking: Backjumping C 1 C 2 C 3 C 4 Dead end! Why? C 5

Back-jumping • Previous assignment reduced domain – C 3 = B • Changes to

Back-jumping • Previous assignment reduced domain – C 3 = B • Changes to intermediate assignment can’t affect dead end • Backtrack up to C 3 – Avoid wasted work - alternatives at C 4 • In general, forward checking more effective

Heuristic CSP: Dynamic Ordering • Question: What to explore next • Current solution: –

Heuristic CSP: Dynamic Ordering • Question: What to explore next • Current solution: – Static: Next in fixed order • Lexicographic, leftmost. . – Random • Alternative solution: – Dynamic: Select “best” in current state

Dynamic Ordering • Heuristic CSP – Most constrained variable: • Pick variable with smallest

Dynamic Ordering • Heuristic CSP – Most constrained variable: • Pick variable with smallest current domain – Least constraining value: • Pick value that removes fewest values from domains of other variables • Improve chance of finding SOME assignment • Can increase feasible size of CSP problem

Dynamic Ordering C 1 C 3 C 5 C 2 C 4

Dynamic Ordering C 1 C 3 C 5 C 2 C 4

Dynamic Ordering with FC C 1 C 2 C 5 C 3 C 4

Dynamic Ordering with FC C 1 C 2 C 5 C 3 C 4

Incremental Repair • Start with initial complete assignment – Use greedy approach – Probably

Incremental Repair • Start with initial complete assignment – Use greedy approach – Probably invalid - I. e. violates some constraints • Incrementally convert to valid solution – Use heuristic to replace value that violates – “min-conflict” strategy: • Change value to result in fewest constraint violations • Break ties randomly • Incorporate in local or backtracking hill-climber

Incremental Repair Q 2 Q 1 Q 4 5 conflicts Q 3 Q 2

Incremental Repair Q 2 Q 1 Q 4 5 conflicts Q 3 Q 2 Q 4 Q 1 Q 3 2 conflicts 0 conflicts

Min-Conflict Effectiveness • N-queens: Given initial random assignment, can solve in ~ O(n) –

Min-Conflict Effectiveness • N-queens: Given initial random assignment, can solve in ~ O(n) – For n < 10^7 • GSAT (satisfiability) – Best (near linear in practice) solution uses minconflict-type hill-climbing strategy • Adds randomization to escape local min • ~Linear seems true for most CSPs – Except for some range of ratios of constraints to variables • Avoids storage of assignment history (for BT)

CSP Complexity • Worst-case in general: – Depth-first search: • Depth= # of variables

CSP Complexity • Worst-case in general: – Depth-first search: • Depth= # of variables • Branching factor: |Domain| • |D|^n+1 • Tree-structured CSPs – No loops in constraint graph – O(n|D|^2)

Tree-structured CSPs C 1 C 5 C 2 C 3 Constraint Graph C 4

Tree-structured CSPs C 1 C 5 C 2 C 3 Constraint Graph C 4 C 6 Create breadth-first ordering Starting from leaf nodes [O(n)], remove all values from parent domain that do not participate in some valid pairwise constraint [O(|D|^2)] Starting from root node, assign value to variable

Iterative Improvement • Alternate formulation of CSP – Rather than DFS through partial assignments

Iterative Improvement • Alternate formulation of CSP – Rather than DFS through partial assignments – Start with some complete, valid assignment • Search for optimal assignment wrt some criterion • Example: Traveling Salesman Problem – Minimum length tour through cities, visiting each one once

Iterative Improvement Example • TSP – Start with some valid tour • E. g.

Iterative Improvement Example • TSP – Start with some valid tour • E. g. find greedy solution – Make incremental change to tour • E. g. hill-climbing - take change that produces greatest improvement – Problem: Local minima – Solution: Randomize to search other parts of space • Other methods: Simulated annealing, Genetic alg’s