/* * 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 Implements the "same" constraint * * Posts the constraint \f$\biguplus_i \{a_i\}=\biguplus_i \{b_i\}\f$ * where both are a subset of \f$1\dots\mathit{nn}\f$ */ void same(Space* home, int nn, IntVarArgs a, IntVarArgs b) { SetVar u(home, IntSet::empty, 1, nn); rel(home, SOT_DUNION, a, u); rel(home, SOT_DUNION, b, u); } MiniModel::Matrix::Slice block_col(MiniModel::Matrix m, int n, int bc, int i, int j) { return m.slice(bc*n+i, bc*n+i+1, j*n, (j+1)*n); } MiniModel::Matrix::Slice block_row(MiniModel::Matrix m, int n, int br, int i, int j) { return m.slice(j*n, (j+1)*n, br*n+i, br*n+i+1); } /** * \brief %Example: Some %Sudoku puzzles using finite domain and set constraints * * The problem does not really require any explanation... * * This implementation combines both the finite domain and the finite set * model using channelling constraints. * * \ingroup Example * */ class SudokuMixed : public Example { protected: const int n; SetVarArray x; public: /// Actual model SudokuMixed(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; /******************************************************** * * Finite Domain model * */ IntVarArray y(this,n*n*n*n,1,n*n); MiniModel::Matrix m(y, nn, nn); // Constraints for rows and columns 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