How to Play Sudoku Win Integer Programming Formulation

  • Slides: 17
Download presentation
How to Play Sudoku & Win Integer Programming Formulation of a Popular Game Sven

How to Play Sudoku & Win Integer Programming Formulation of a Popular Game Sven Leyffer, Argonne, Feb. 15, 2005 (windoze powerpoint sumi painting style)

Sudoku Rules Given initial data Fill digits 1 -9 into boxes such that Every

Sudoku Rules Given initial data Fill digits 1 -9 into boxes such that Every digit 1 -9 appears in every row, column, and 3 x 3 box. Works for letters, names etc. 1 6 2 3 3 7 7 9 6 5 8 4 9 4 2 2 4 5 9 1 7 6 8 9 1 6 2 4 9 7 6 3

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate 2 from 3 x 3 box: 1 6 2 3 3 7 7 9 6 5 8 4 9 4 2 2 4 5 9 1 7 6 8 9 1 6 2 4 9 7 6 3

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate 2 from 3 x 3 box: Gives new 2 1 6 2 3 3 7 7 2 9 6 5 8 4 9 4 2 2 4 5 9 1 7 6 8 9 1 6 2 4 9 7 6 3

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate 2 from 3 x 3 box: Gives new 2 Continue … 1 6 2 3 3 7 7 2 9 6 5 8 4 9 4 2 2 4 5 9 1 7 6 2 9 1 8 6 2 4 9 7 6 3

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate 2 from 3 x 3 box: Gives new 2 Continue … … fill other digits 1 2 7 2 9 6 5 8 4 3 2 7 5 9 1 4 6 2 3 3 9 4 2 2 4 6 2 9 1 8 6 2 9 7 2 6 7

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate

Solving Sudoku Eliminate rows & cols from 3 x 3 box E. g. eliminate 2 from 3 x 3 box: Gives new 2 Continue … … fill other digits Fill 3 x 3 boxes 1 6 2 7 2 9 6 5 8 4 5 9 1 4 6 2 3 3 9 4 2 2 4 2 3 4 7 2 9 1 8 5 6 2 9 7 2 6 7

Solving Sudoku by Integer Optimization 0 -1 variables model digit assignment & linear equations

Solving Sudoku by Integer Optimization 0 -1 variables model digit assignment & linear equations model rules … gives integer linear program (ILP) NP-complete (graph coloring) problem (6, 670, 903, 752, 021, 072, 936, 960 sols) Solve using ILP solvers: CPLEX, MINTO See ~leyffer/sudoku/ for AMPL models

Branch-and-Bound Solver Solve continuous relaxation: [0, 1] Branch on nonintegral variable: v Two new

Branch-and-Bound Solver Solve continuous relaxation: [0, 1] Branch on nonintegral variable: v Two new probs: v Set y=1 or y=0 Continue until all nodes explored

Solution to Simple Example v v Solver: CPLEX Simple Problem: Time: 0 Nodes: 0

Solution to Simple Example v v Solver: CPLEX Simple Problem: Time: 0 Nodes: 0 … AMPL presolve Challenging Problem Time: 0. 03 seconds Nodes: 0 … integral LP soln 1 8 4 7 2 9 6 3 5 7 6 9 1 5 3 2 4 8 5 2 3 8 4 6 9 1 7 4 3 8 9 1 7 5 2 6 9 7 5 4 6 2 3 8 1 6 1 2 3 8 5 4 7 9 3 4 7 5 9 1 8 6 2 2 9 1 6 3 8 7 5 4 8 5 6 2 7 4 1 9 3

Sudokus Without Solutions No solution AMPL/CPLEX: Infeasible constraints by presolve Proof of nonexistence of

Sudokus Without Solutions No solution AMPL/CPLEX: Infeasible constraints by presolve Proof of nonexistence of solution 1 6 2 3 3 8 7 7 9 6 5 8 4 9 4 2 2 4 5 9 1 7 6 8 9 1 6 2 4 9 7 6 3

Sudokus With Multiple Solutions Many solution AMPL/MINTO: Find first solution Integer cuts to remove

Sudokus With Multiple Solutions Many solution AMPL/MINTO: Find first solution Integer cuts to remove solution Resolve to find new solution Stop when infeasible Soln at root node what’s the secret? 1 6 3 2 7 9 6 6 2 9 5 1 7 6 4 9 7 3

AMPL’s Primal Presolve Transform problem to smaller/easier equivalent problem Remove fixed variables Remove constraints

AMPL’s Primal Presolve Transform problem to smaller/easier equivalent problem Remove fixed variables Remove constraints that express variable bounds Iteratively tighten bounds on variables, using Gauss-Seidel Todd has experience with NCP presolve!

MINTO’s Primal Heuristics Find solution early … reduce tree-search Probing: tentatively set binaries to

MINTO’s Primal Heuristics Find solution early … reduce tree-search Probing: tentatively set binaries to 0 or 1 Rounding & feasibility pump LP relaxation: solution x … round to r(x) Solve LP min dist(y, r(x)) subject to Ax=b LP solution y … round to r(y) & repeat Heuristics: genetic algorithms, et al.

Integer Optimization Applications Crew scheduling Machine scheduling Reactor core reload: Max fuel efficiency Subject

Integer Optimization Applications Crew scheduling Machine scheduling Reactor core reload: Max fuel efficiency Subject to safety & diffusion PDE Find reloading schedule … integer & nonlinear

Constrained Logic Programming CLP origins: AI & logic CLP: declarative language to formulate logical

Constrained Logic Programming CLP origins: AI & logic CLP: declarative language to formulate logical problems, scheduling etc CLP: combines constraints with logic & constraint satisfaction CLP allows tailored solutions/rules CHIP, ECLi. PSe, GNU Prolog, IF/Prolog, ILOG, Koalog, MOzart, and SICStus

References: Wikipedia: en. wikipedia. org/wiki/Sudoku Th. Koch: How to Solve Sudoku … M. J.

References: Wikipedia: en. wikipedia. org/wiki/Sudoku Th. Koch: How to Solve Sudoku … M. J. Chlond: IP Modeling: Su Doku (05) W. Shortz: Sudoku – 100 wordless puzzles Fourer & Gay: AMPL’s Primal Presolve (93) Sudoku Programmers Forum