1 / 11

Solving Sudoku with Simulated Annealing

Solving Sudoku with Simulated Annealing. Bret Wilson. What is Simulated Annealing?. Analog of physical process of annealing in metals Heat, then cool slowly Start with random configuration Try nearby neighbors Lower temperature = become pickier. Heuristic.

jenski
Download Presentation

Solving Sudoku with Simulated Annealing

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. Solving Sudoku with Simulated Annealing Bret Wilson

  2. What is Simulated Annealing? • Analog of physical process of annealing in metals • Heat, then cool slowly • Start with random configuration • Try nearby neighbors • Lower temperature = become pickier

  3. Heuristic • Only consider states in which each small square has exactly 1 of each digit 0 – 9 • Why? It’s trivial to solve either small squares, rows, or columns by themselves – I chose small squares. • -1 point for each different number in each row and column • Minimum (best) score = -9 x 9 x 2 = -162

  4. Choosing a new state • Swap any 2 digits in same small square -> candidate • Accept new state if e-∆S/T – R > 0 • (Metropolis-Hastings Algorithm) • R is random number in range [0,1] • Always accept better states • Accept worse states more often when T is higher

  5. Example (score = -61-56 = -117)

  6. Example (score = -62-56 = -118)

  7. Example • ∆S = -1 • e-∆S/T will always be > 1, no matter what T and R are. • So we accept.

  8. Annealing Schedule • What should our initial value for T be? • Can find by trial and error • How fast should we decrease T? • Linear: T <= T – i where i > 0 • Geometric progression: T <= c*T where 0 < c < 1 • Change T based on current score

  9. Pseudocode currState<= createInitialState() currScore <= score(currState) bestState<= currState bestScore <= currScore while (T > END) newState <= generateNeighbor(currState) newScore <= score(newState) if (exp((currScore - newScore)/T) - rand(0,1) > 0) currState <= newState currScore <= newScore if (currScore < bestScore) bestState <= currState bestScore <= currScore T <= c*T return bestState

  10. Pros + Cons of Simulated Annealing • Good: Quickly finds a minimum • Bad: May not find global minimum (best solution) • Increasing temperature makes it slower, but less likely we will get stuck in local minimum

  11. References • Carr, Roger. "Simulated Annealing." From MathWorld--A Wolfram Web Resource, created by Eric W. Weisstein. http://mathworld.wolfram.com/SimulatedAnnealing.html • “Simulated Annealing.” Wikipedia. http://en.wikipedia.org/wiki/Simulated_annealing • “Simulated Annealing Applet.” Heaton Research. http://www.heatonresearch.com/articles/64/page1.html

More Related