Generated on Thu Mar 22 10:39:31 2012 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  *  Last modified:
00012  *     $Date: 2010-10-07 11:52:01 +0200 (Thu, 07 Oct 2010) $ by $Author: schulte $
00013  *     $Revision: 11473 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #include <gecode/driver.hh>
00041 #include <gecode/int.hh>
00042 #include <gecode/minimodel.hh>
00043 
00044 using namespace Gecode;
00045 
00063 class MagicSequence : public Script {
00064 private:
00066   const int n;
00068   IntVarArray s;
00069 public:
00071   enum {
00072     PROP_COUNT,   
00073     PROP_GCC      
00074   };
00076   MagicSequence(const SizeOptions& opt)
00077     : n(opt.size()), s(*this,n,0,n-1) {
00078     switch (opt.propagation()) {
00079     case PROP_COUNT:
00080       for (int i=n; i--; )
00081         count(*this, s, i, IRT_EQ, s[i]);
00082       linear(*this, s, IRT_EQ, n);
00083       break;
00084     case PROP_GCC:
00085       count(*this, s, s, opt.icl());
00086       break;
00087     }
00088     linear(*this, IntArgs::create(n,-1,1), s, IRT_EQ, 0);
00089     branch(*this, s, INT_VAR_NONE, INT_VAL_MAX);
00090   }
00091 
00093   MagicSequence(bool share, MagicSequence& e) : Script(share,e), n(e.n) {
00094     s.update(*this, share, e.s);
00095   }
00097   virtual Space*
00098   copy(bool share) {
00099     return new MagicSequence(share,*this);
00100   }
00102   virtual
00103   void print(std::ostream& os) const {
00104     os << "\t";
00105     for (int i = 0; i<n; i++) {
00106       os << s[i] << ", ";
00107       if ((i+1) % 20 == 0)
00108         os << std::endl << "\t";
00109     }
00110     os << std::endl;
00111   }
00112 
00113 };
00114 
00118 int
00119 main(int argc, char* argv[]) {
00120   SizeOptions opt("MagicSequence");
00121   opt.solutions(0);
00122   opt.iterations(4);
00123   opt.size(500);
00124   opt.propagation(MagicSequence::PROP_COUNT);
00125   opt.propagation(MagicSequence::PROP_COUNT,   "count");
00126   opt.propagation(MagicSequence::PROP_GCC,     "gcc");
00127   opt.parse(argc,argv);
00128   Script::run<MagicSequence,DFS,SizeOptions>(opt);
00129   return 0;
00130 }
00131 
00132 // STATISTICS: example-any
00133