Generated on Fri Oct 19 11:24:48 2018 for Gecode by doxygen 1.6.3

magic-sequence.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2001
00009  *     Guido Tack, 2006
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #include <gecode/driver.hh>
00037 #include <gecode/int.hh>
00038 #include <gecode/minimodel.hh>
00039 
00040 using namespace Gecode;
00041 
00059 class MagicSequence : public Script {
00060 private:
00062   const int n;
00064   IntVarArray s;
00065 public:
00067   enum {
00068     PROP_COUNT,   
00069     PROP_GCC      
00070   };
00072   MagicSequence(const SizeOptions& opt)
00073     : Script(opt), n(opt.size()), s(*this,n,0,n-1) {
00074     switch (opt.propagation()) {
00075     case PROP_COUNT:
00076       for (int i=n; i--; )
00077         count(*this, s, i, IRT_EQ, s[i]);
00078       linear(*this, s, IRT_EQ, n);
00079       break;
00080     case PROP_GCC:
00081       count(*this, s, s, opt.ipl());
00082       break;
00083     }
00084     linear(*this, IntArgs::create(n,-1,1), s, IRT_EQ, 0);
00085     branch(*this, s, INT_VAR_NONE(), INT_VAL_MAX());
00086   }
00087 
00089   MagicSequence(MagicSequence& e) : Script(e), n(e.n) {
00090     s.update(*this, e.s);
00091   }
00093   virtual Space*
00094   copy(void) {
00095     return new MagicSequence(*this);
00096   }
00098   virtual
00099   void print(std::ostream& os) const {
00100     os << "\t";
00101     for (int i = 0; i<n; i++) {
00102       os << s[i] << ", ";
00103       if ((i+1) % 20 == 0)
00104         os << std::endl << "\t";
00105     }
00106     os << std::endl;
00107   }
00108 
00109 };
00110 
00114 int
00115 main(int argc, char* argv[]) {
00116   SizeOptions opt("MagicSequence");
00117   opt.solutions(0);
00118   opt.iterations(4);
00119   opt.size(500);
00120   opt.propagation(MagicSequence::PROP_COUNT);
00121   opt.propagation(MagicSequence::PROP_COUNT,   "count");
00122   opt.propagation(MagicSequence::PROP_GCC,     "gcc");
00123   opt.parse(argc,argv);
00124   Script::run<MagicSequence,DFS,SizeOptions>(opt);
00125   return 0;
00126 }
00127 
00128 // STATISTICS: example-any
00129