1 / 40

Exhaustion

Exhaustion. Tam Siu Lung, Alan 96397999 Tam@SiuLung.com 99967891. Prerequisites. Basic knowledge of Recursion Elementary Graph Theory Experience in solving Exhaustion problems. When can we use Exhaustion?. We can list out ALL possible states

Download Presentation

Exhaustion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Exhaustion Tam Siu Lung, Alan 96397999 Tam@SiuLung.com 99967891

  2. Prerequisites • Basic knowledge of Recursion • Elementary Graph Theory • Experience in solving Exhaustion problems

  3. When can we use Exhaustion? • We can list out ALL possible states • We can justify whether any given state is a goal • List out all possible states • Solve for a single goal state • Solve for the optimal goal state • Know how to order two states • Solve as good as you can for a state • Know how to evaluate a state

  4. Constraint SatisfactionWhy some states are not goal? • There are n variables (a1..an) • Each variable takes one of the m values (domain of values) (v1..vm) • There are p constraints (c1..cp) • A state is a partial assignment • Initial state is a state without assignments • A goal state is a state with all variables assigned with values • Operation: assign a value to a variable

  5. Example 1: 8 Queen Problem • Variable: 8 Queens • Values: 64 Locations • Constraints: No two Queens attack • Initial state: no queen • Goal state: 8 Queens • Solution: Any goal state

  6. Solve for: YYZ ZX + X XYZ ONE TWO FIVE NINE ELEVEN TWELVE + FIFTY NINETY Variables: X, Y, Z Values: 0~9 Constraints: Z+2X=Z+10C0 Y+Z+C0=Y+10C1 Y+C1=X X ≠ Y Y ≠ Z X ≠ Z Example 2: Crypto-arithmetic

  7. NT Q WA SA NSW V T Example 3: Map Coloring • To color the map of Australia ... • Variables: “States” • Values: Colors • Constraints: Neighbor “States” have Different Colors

  8. Variables: Position of A, B, C, D Values: 1, 2, 3, 4 Constraints: Positions of A, B, C, D are all different Variables: 4 Positions Values: A, B, C, D Constraints: Positions of A, B, C, D are all different Example 4: PermutationsFind all permutations of ABCD

  9. Algorithm 1 • Given a state • If it is a goal state, ... • For each of the unassigned variables • For each of the values in the domain • Assign the value to the variable • Test the constraints • Test if this “new” state works • Undo the assignment • When all the assignment failed, declare failed

  10. ABC CBA CBA ABC Search Tree ??? No variables assigned A?? ?A? ??A B?? ?B? ??B C?? ?C? ??C 1 variable assigned AB? ?BA CB? ?BC 2 variables assigned 3 variables assigned

  11. Search Tree ??? No variables assigned 1 variable assigned A?? B?? C?? AB? AC? 2 variables assigned ABC ACB 3 variables assigned

  12. Algorithm 2 • Given a state • If it is a goal state, ... • Pick one variable • For each of the values in the domain • Assign the value to the variable • Test the constraints • Test if this “new” state works • Undo the assignment • When all the assignment failed, declare failed

  13. What to do for goal state? • If you want all goals • Print it out • If you want any goal • Print it out and terminate • If you want the best goal • Update the best goal till now if the new one is better

  14. How to check the constraints? • Constraints checked after every assignment • In each assignment, only one value affected • Associate a list of constraints to the variables • Reduce constraints to binary constraints

  15. Order Analysis • Search depth is n • Search breadth is m • Order = Size of Tree = O(nm) • In general CSP’s are NP-hard

  16. Doing better • How to pick a good variable, i.e. what is a good ordering of variables? • How to know earlier that a branch is doomed? • When we backtrack from a doomed branch, how do we avoid the same mistake by modifying an irrelevant variable? • How to decompose a large problem into more manageable ones?

  17. NT Q WA SA NSW V T Search Tree WA=R WA=G WA=B WA=R NT=G WA=R NT=B WA=R NT=G SA=B WA=R NT=B SA=G

  18. Minimum Remaining Values(MRV) • Choosing the variable with MRV • So we won’t try meaningless moves (reduced the tree size) • Which node to try at the very beginning? • If two variables have the same MRV, choose the one with the largest degree

  19. NT Q WA SA NSW V T Search Tree WA=R WA=G WA=B WA=R NT=G WA=R NT=B WA=R NT=G Q=R WA=R NT=G Q=B

  20. Least Constraining Value(LCV) • When choosing a value, choose the LCV • The LCV makes a branch dooms faster • Why not aim at reducing the tree size this time?

  21. Forward CheckingData Structures • Forward checking done to store the number of RV for each node • Stored what values are impossible • Effectively reduced branching factor

  22. NT Q WA SA NSW V T Search Tree WA=R WA=G WA=B WA=R NSW=R WA=R NSW=G WA=R NSW=B WA=R NSW=R T=R WA=R NSW=R T=G WA=R NSW=R T=B

  23. Back Jumping • Don’t try another value when the conflict is not caused by the current node • Define conflict set be the set of variables that however assigned will cause conflict • When failure, return the conflict set • If the current variable is not in the conflict set, declare failure immediately with the same conflict set • When all values exhausts, adds itself to the union all conflict sets of its branches

  24. Back JumpingData Structures • Store a set for each variable, initially empty • Whenever assignment of variable a1 constrains another variable a2, add a1 to the conflict set of a2 • When a branch fails, the conflict set is there already

  25. Tree CSP A E B D C F A B C D E F

  26. Decomposition (Optional) • Split a problem into several smaller problems • If the problem is Tree CSP, then it runs in linear time

  27. Removing Nodes (Optional) • Find a set of variables so that when it is removed the graph becomes a tree (Cycle Cutset) • How to remove? • O(kn) where k is the size of the Cycle Cutset NT Q WA NSW V T

  28. Tree Decomposition • Sub-problems form a tree • Each sub-problem is a variable in the original problem • Two values conflict if their common “variables” are different NT Q SA NT WA SA Q SA NSW NSW SA V T

  29. Solving for Optimality • How about if we are asked to find the minimum number of colors that we have to use? • Algorithm 1 • Try them one by one upwards • Slow? • Algorithm 2 • No fix amount of available variables

  30. Example 5: Coins • SEARCC 2001 HK TFT • Given a set of coin values • 100, 30, 8, 5, 1 • Find the minimum number of coins required to pay for a given amount, e.g. 112 • Variables, Values, Conflicts?

  31. Example 5: Coins • Variables: the coins picked • Values: values of coins • Cost: the amount not yet paid • Operation: Pick a coin

  32. Search Tree 100 30 8 100+8 100+1 30+30 100+5 30+8 100+8+1 100+5+5 100+5+1 100+1+1 30+30 +30 100+8 +1+1 100+5 +5+1 100+5 +1+1 100+1 +1+1 30+30 +30+8 100+8 +1+1+1 100+5 +5+1+1 100+5 +1+1+1 100+1 +1+1+1 30+30 +30+8 +1 30+30 +30+30 +8+1 100+8 +1+1 +1+1 100+5 +1+1+1 +1 100+1 +1+1+1 +1

  33. Example 5: Coins • Why can we cut the nodes to early? • What is the prerequisite?

  34. Local SearchHill Climbing • Don’t try to search all. Only store one (Local) state and search from it. • A state is NOT a partial assignment, but an full assignment with constraints violated • Use an objective function to guide our search, e.g. the number of conflicts present • Every step tries to modify the Local state, aiming at performing an upward move • The objective is to move to the global maximum

  35. Example 1: 8-Queen Problem • State: A full assignment of all 8 queens, say one in a column • Operation: Modify one/some queens • Initial state: random • Cost function: number of pair of queens attacking with each other

  36. Difficulties • Local Maxima: every single move will worsen, but another move may give rise to somewhere even higher • We will solve this later • Plateau: everywhere is the same • Allow some sideway moves until you are confirmed enough it is local maxima

  37. Random Restart • When we have reached somewhere that we cannot make more improvements • Remember the best solution • Restart from another random initial state

  38. Simulated Annealing • Instead of just choose a random next-state, move on a probability depending on how much it worsen our solution • But we want randomness to decreases with time • With high enough “temperature”, one can make a bad move to a certain extent • Assign a schedule of temperature decrease

  39. Local Beam Search • Keep more than one local states • Many simultaneous local searches with communication • States which are bad will die soon • But we want diversity ...

  40. Stochastic Beam Search • Don’t always use the best states • Allow some not so good states given a probability

More Related