/* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2005 * * Last modified: * $Date: 2006-08-04 16:06:52 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $ * $Revision: 3517 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * See the file "LICENSE" for information on usage and * redistribution of this file, and for a * DISCLAIMER OF ALL WARRANTIES. * */ #include "gecode/set.hh" #include "examples/support.hh" #include "gecode/minimodel.hh" #include "examples/sudoku.icc" /** * \brief %Example: Some %Sudoku puzzles using set constraints * * Does not really require any explanation... * * \ingroup Example * */ class SudokuSet : public Example { protected: const int n; SetVarArray x; public: /// Actual model SudokuSet(const Options& opt) : n(example_size(examples[opt.size])), x(this,n*n,IntSet::empty,1,n*n*n*n,9,9) { const int nn = n*n; IntSet row[9]; IntSet col[9]; IntSet block[9]; // Set up the row and column set constants for (int i=0; i<9; i++) { IntSet dsr((i*nn)+1, (i*nn)+9); row[i] = dsr; int dsc_arr[9] = { 1+i, 10+i, 19+i, 28+i, 37+i, 46+i, 55+i, 64+i, 73+i }; IntSet dsc(dsc_arr, 9); col[i] = dsc; } // Set up the block set constants for (int i=0; i<3; i++) for (int j=0; j<3; j++) { int dsb_arr[9] = { (j*27)+(i*3)+1, (j*27)+(i*3)+2, (j*27)+(i*3)+3, (j*27)+(i*3)+10, (j*27)+(i*3)+11, (j*27)+(i*3)+12, (j*27)+(i*3)+19, (j*27)+(i*3)+20, (j*27)+(i*3)+21 }; IntSet dsb(dsb_arr, 9); block[i*3+j]=dsb; } // All x must be pairwise disjoint for (int i=0; i= n_examples) { std::cerr << "Error: size must be between 0 and " << n_examples-1 << std::endl; return 1; } if (example_size(examples[opt.size]) != 3) { std::cerr << "Set-based version only available with exmples of size 9*9" << std::endl; return 2; } Example::run(opt); return 0; } // STATISTICS: example-any