160 likes | 342 Views
G53CLP Constraint Logic Programming. Solving 8-Queen Puzzle – Demo. Dr Rong Qu. CPLEX Optimization software package Sold via CPLEX Optimization Inc. Acquired by ILOG Inc in 1997 Acquired by IBM in 2009 Also solves integer programming and large linear programming problems. ILOG OPL Studio.
E N D
G53CLPConstraint Logic Programming Solving 8-Queen Puzzle – Demo Dr Rong Qu
CPLEX Optimization software package Sold via CPLEX Optimization Inc. Acquired by ILOG Inc in 1997 Acquired by IBM in 2009 Also solves integer programming and large linear programming problems ILOG OPL Studio http://www.ilog.com/products/cplex/ G53CLP – Constraint Logic Programming Dr R. Qu
OPL Studio One of the modeling systems in ILOG For both mathematic programming and constraint programming OPL (Optimization Programming Language) was originally developed by Pascal van Hentenryck Provide an interpreter OPL models; A script language An IDE; An API ILOG OPL Studio G53CLP – Constraint Logic Programming Dr R. Qu
Gecode 1.0.1 Java interface for constraint programming Free for download Released in Nov 2006 Possible coursework next year? http://www.gecode.org/gecodej/ Other CP Solvers? G53CLP – Constraint Logic Programming Dr R. Qu
Solving the 8-Queen Problem G53CLP – Constraint Logic Programming Dr R. Qu
Solving The 8-Queen Problem – model 2 • Variables • x1, x2, …, xn: position of queens on the chessboard • Domain • {0 … n2-1}: tile index of each queen placed • Constraint R = xi / n + 1 C = xi mod n + 1 Given R1, R2 and C1, C2 of two queens’ positions • One queen each row/column • R1 ≠ R2; C1 ≠ C2 • One queen each diagnal • R1 – R2 ≠ C1 – C2 • R1 – R2 ≠ C2 – C1 G53CLP – Constraint Logic Programming Dr R. Qu
ILOG OPL Studio G53CLP – Constraint Logic Programming Dr R. Qu
Solving The 8-Queen Problem – model 2 //.mod file //declaration part var int queens[1..8] in 0..63; var int r[1..8] in 1..8; var int c[1..8] in 1..8; // problem model solve { … }; • x1, x2, …, xn: position of queens on the chessboard • {0 … n2-1}: tile index of each queen placed • R = xi / n + 1 • C = xi mod n + 1 • R1 ≠ R2; C1 ≠ C2 • R1 – R2 ≠ C1 – C2 • R1 – R2 ≠ C2 – C1 G53CLP – Constraint Logic Programming Dr R. Qu
Solving The 8-Queen Problem – model 2 //.mod file //declaration part … //problem model solve { forall(ordered i,j in 1..8) { r[i] = queens[i] / 8 + 1; c[i] = queens[i] mod 8 + 1; r[j] = queens[j] / 8 + 1; c[j] = queens[j] mod 8 + 1; … }; }; • R = xi / n + 1 • C = xi mod n + 1 • R1 ≠ R2; C1 ≠ C2 • R1 – R2 ≠ C1 – C2 • R1 – R2 ≠ C2 – C1 G53CLP – Constraint Logic Programming Dr R. Qu
Solving The 8-Queen Problem – model 2 //.mod file //declaration part … //problem model solve { forall(ordered i,j in 1..8) { … r[i] <> r[j] ; c[i] <> c[j] ; r[i] - r[j] <> c[i] - c[j]; r[i] - r[j] <> c[j] - c[i]; }; }; • R = xi / n + 1 • C = xi mod n + 1 • R1 ≠ R2; C1 ≠ C2 • R1 – R2 ≠ C1 – C2 • R1 – R2 ≠ C2 – C1 G53CLP – Constraint Logic Programming Dr R. Qu
Solving The 8-Queen Problem – model 2 G53CLP – Constraint Logic Programming Dr R. Qu
Solving The 8-Queen Problem – models 1&3 • Lab sessions start next week • I: comparing the 3 models for solving the n-Queen problem • II: G53CLP – Constraint Logic Programming Dr R. Qu
Solving The 8-Queen Problem • To display decision tree • Debug/Display Decision Tree • To run • Execution/Run, or • To stop at a decision point • Debug/Stop at Decision Point • Next solution • All solutions G53CLP – Constraint Logic Programming Dr R. Qu