Generated on Wed Nov 1 15:04:27 2006 for Gecode by doxygen 1.4.5

magic-sequence.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2001
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-04 16:06:52 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3517 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "examples/support.hh"
00023 #include "gecode/minimodel.hh"
00024 
00037 class MagicSequence : public Example {
00038 private:
00040   const int n;
00042   IntVarArray s;
00043 public:
00045   void
00046   exactly(IntVarArray& v, IntVar& x, int i) {
00047     // I occurs in V X times
00048     BoolVarArgs b(v.size());
00049     for (int j = v.size(); j--; )
00050       b[j] = post(this, ~(v[j] == i));
00051     linear(this, b, IRT_EQ, x);
00052   }
00054   MagicSequence(const Options& opt)
00055     : n(opt.size), s(this,n,0,n-1) {
00056     if (opt.naive)
00057       for (int i=n; i--; )
00058         exactly(s, s[i], i);
00059     else
00060       for (int i=n; i--; )
00061         count(this, s, i, IRT_EQ, s[i]);
00062     linear(this, s, IRT_EQ, n);
00063     IntArgs c(n);
00064     for (int j = n; j--; )
00065       c[j] = j-1;
00066     linear(this, c, s, IRT_EQ, 0);
00067     branch(this, s, BVAR_NONE, BVAL_SPLIT_MAX);
00068   }
00069 
00071   MagicSequence(bool share, MagicSequence& e) : Example(share,e), n(e.n) {
00072     s.update(this, share, e.s);
00073   }
00075   virtual Space*
00076   copy(bool share) {
00077     return new MagicSequence(share,*this);
00078   }
00080   virtual
00081   void print(void) {
00082     std::cout << "\t";
00083     for (int i = 0; i<n; i++) {
00084       std::cout << s[i] << ", ";
00085       if ((i+1) % 20 == 0)
00086         std::cout << std::endl << "\t";
00087     }
00088     std::cout << std::endl;
00089   }
00090 
00091 };
00092 
00096 int
00097 main(int argc, char** argv) {
00098   Options opt("MagicSequence");
00099   opt.solutions  = 0;
00100   opt.iterations = 4;
00101   opt.size       = 500;
00102   opt.parse(argc,argv);
00103   Example::run<MagicSequence,DFS>(opt);
00104   return 0;
00105 }
00106 
00107 // STATISTICS: example-any
00108