this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 5 * 6 * Copyright: 7 * Vincent Barichard, 2013 8 * 9 * Last modified: 10 * $Date$ by $Author$ 11 * $Revision$ 12 * 13 * This file is part of Quacode: 14 * http://quacode.barichard.com 15 * 16 * Permission is hereby granted, free of charge, to any person obtaining 17 * a copy of this software and associated documentation files (the 18 * "Software"), to deal in the Software without restriction, including 19 * without limitation the rights to use, copy, modify, merge, publish, 20 * distribute, sublicense, and/or sell copies of the Software, and to 21 * permit persons to whom the Software is furnished to do so, subject to 22 * the following conditions: 23 * 24 * The above copyright notice and this permission notice shall be 25 * included in all copies or substantial portions of the Software. 26 * 27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 31 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 32 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 33 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 * 35 */ 36 37#include <iostream> 38#include <vector> 39 40#include <quacode/qspaceinfo.hh> 41#include <gecode/minimodel.hh> 42#include <gecode/driver.hh> 43 44 45using namespace Gecode; 46 47#ifdef GECODE_HAS_GIST 48namespace Gecode { namespace Driver { 49 /// Specialization for QDFS 50 template<typename S> 51 class GistEngine<QDFS<S> > { 52 public: 53 static void explore(S* root, const Gist::Options& opt) { 54 (void) Gist::explore(root, false, opt); 55 } 56 }; 57}} 58#endif 59 60 61/** 62 * \brief Options taking one additional parameter 63 */ 64class BakerOptions : public Options { 65public: 66 /// Print strategy or not 67 Gecode::Driver::BoolOption _printStrategy; 68 int n; /// Parameter to be given on the command line 69 /// Initialize options for example with name \a s 70 BakerOptions(const char* s, int n0) 71 : Options(s), 72 _printStrategy("-printStrategy","Print strategy",false), 73 n(n0) { 74 add(_printStrategy); 75 } 76 /// Parse options from arguments \a argv (number is \a argc) 77 void parse(int& argc, char* argv[]) { 78 Options::parse(argc,argv); 79 if (argc < 2) 80 return; 81 n = atoi(argv[1]); 82 } 83 /// Return true if the strategy must be printed 84 bool printStrategy(void) const { 85 return _printStrategy.value(); 86 } 87 /// Print help message 88 virtual void help(void) { 89 Options::help(); 90 std::cerr << "\t(unsigned int) default: " << n << std::endl 91 << "\t\tValue used to restrict the domain of w1 in order to make the problem harder" << std::endl; 92 } 93}; 94 95class QCSPBaker : public Script, public QSpaceInfo { 96 IntVarArray X; 97 98public: 99 QCSPBaker(const BakerOptions& opt) : Script(opt), QSpaceInfo() 100 { 101 std::cout << "Loading problem" << std::endl; 102 if (!opt.printStrategy()) strategyMethod(0); // disable build and print strategy 103 using namespace Int; 104 105 IntVarArgs w(*this,5,1,opt.n); 106 IntVar f(*this,1,opt.n); 107 setForAll(*this, f); 108 IntVarArgs c(*this,5,-1,1); 109 IntVarArgs vaX; 110 vaX << w << f << c; 111 X = IntVarArray(*this, vaX); 112 113 IntVar o1(*this,-opt.n,opt.n), o2(*this,-opt.n,opt.n), o3(*this,-opt.n,opt.n), o4(*this,-opt.n,opt.n), o5(*this,-opt.n,opt.n); 114 rel(*this, w[0] * c[0] == o1); 115 rel(*this, w[1] * c[1] == o2); 116 rel(*this, w[2] * c[2] == o3); 117 rel(*this, w[3] * c[3] == o4); 118 rel(*this, w[4] * c[4] == o5); 119 rel(*this, o1 + o2 + o3 + o4 + o5 == f); 120 121 branch(*this, X, INT_VAR_NONE(), INT_VALUES_MIN()); 122 } 123 124 QCSPBaker(bool share, QCSPBaker& p) : Script(share,p), QSpaceInfo(*this,share,p) 125 { 126 X.update(*this,share,p.X); 127 } 128 129 virtual Space* copy(bool share) { return new QCSPBaker(share,*this); } 130 131 132 void print(std::ostream& os) const { 133 strategyPrint(os); 134 } 135}; 136 137int main(int argc, char* argv[]) 138{ 139 140 BakerOptions opt("Baker Problem",40); 141 opt.parse(argc,argv); 142 Script::run<QCSPBaker,QDFS,BakerOptions>(opt); 143 144 return 0; 145}