/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * Mikael Lagerkvist * * Copyright: * Guido Tack, 2006 * Mikael Lagerkvist, 2006 * * Last modified: * $Date: 2010-10-07 20:52:01 +1100 (Thu, 07 Oct 2010) $ by $Author: schulte $ * $Revision: 11473 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include #include #include using namespace Gecode; namespace { /** \brief Board specifications * * \relates Domino */ extern const int *specs[]; /** \brief Number of board specifications * * \relates Domino */ extern const unsigned int n_examples; } /** * \brief %Example: Solitaire domino * * The task is to place domino pieces on a board. Each piece covers two * fields and has two numbers. There are 28 pieces, from 0-0 to 6-6. * The board is set up with a number in each field that must match the * number of the domino piece placed on that field. * * \ingroup Example * */ class Domino : public Script { private: /// Specification of the board const int *spec; /// Width of the board int width; /// Height of the board int height; /// The board representing the number of the piece at each position IntVarArray x; public: /// Propagation to use for model enum { PROP_ELEMENT, ///< Use element constraints PROP_EXTENSIONAL ///< Use extensional constraints }; /// Actual model Domino(const SizeOptions& opt) : spec(specs[opt.size()]), width(spec[0]), height(spec[1]), x(*this, (width+1)*height, 0, 28) { spec+=2; // skip board size information // Copy spec information to the board IntArgs board((width+1)*height); for (int i=0; i= n_examples) { std::cerr << "Error: size must be between 0 and " << n_examples-1 << std::endl; return 1; } Script::run(opt); return 0; } namespace { /** \name Puzzle specifications * * \relates Domino */ //@{ /// %Example 0 const int domino0[] = { // width*height of the board 8,7, // the board itself 2,1,0,3,0,4,5,5, 6,2,0,6,3,1,4,0, 3,2,3,6,2,5,4,3, 5,4,5,1,1,2,1,2, 0,0,1,5,0,5,4,4, 4,6,2,1,3,6,6,1, 4,2,0,6,5,3,3,6 }; /// %Example 1 const int domino1[] = { // width*height of the board 8,7, // the board itself 5,1,2,4,6,2,0,5, 6,6,4,3,5,0,1,5, 2,0,4,0,4,0,5,0, 6,1,3,6,3,5,4,3, 3,1,0,1,2,2,1,4, 3,6,6,2,4,0,5,4, 1,3,6,1,2,3,5,2 }; /// %Example 2 const int domino2[] = { // width*height of the board 8,7, // the board itself 4,4,5,4,0,3,6,5, 1,6,0,1,5,3,4,1, 2,6,2,2,5,3,6,0, 1,3,0,6,4,4,2,3, 3,5,5,2,4,2,2,1, 2,1,3,3,5,6,6,1, 5,1,6,0,0,0,4,0 }; /// %Example 3 const int domino3[] = { // width*height of the board 8,7, // the board itself 3,0,2,3,3,4,4,3, 6,5,3,4,2,0,2,1, 6,5,1,2,3,0,2,0, 4,5,4,1,6,6,2,5, 4,3,6,1,0,4,5,5, 1,3,2,5,6,0,0,1, 0,5,4,6,2,1,6,1 }; /// %Example 4 const int domino4[] = { // width*height of the board 8,7, // the board itself 4,1,5,2,4,4,6,2, 2,5,6,1,4,6,0,2, 6,5,1,1,0,1,4,3, 6,2,1,1,3,2,0,6, 3,6,3,3,5,5,0,5, 3,0,1,0,0,5,4,3, 3,2,4,5,4,2,6,0 }; /// %Example 5 const int domino5[] = { // width*height of the board 8,7, // the board itself 4,1,2,1,0,2,4,4, 5,5,6,6,0,4,6,3, 6,0,5,1,1,0,5,3, 3,4,2,2,0,3,1,2, 3,6,5,6,1,2,3,2, 2,5,0,6,6,3,3,5, 4,1,0,0,4,1,4,5 }; /// List of specifications const int *specs[] = {domino0,domino1,domino2,domino3,domino4,domino5}; /// Number of specifications const unsigned n_examples = sizeof(specs)/sizeof(int*); //@} } // STATISTICS: example-any