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

queens.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-03 13:51:17 +0200 (Thu, 03 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3506 $
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 
00034 class Queens : public Example {
00035 protected:
00037   IntVarArray q;
00038 public:
00040   Queens(const Options& opt)
00041     : q(this,opt.size,0,opt.size-1) {
00042     const int n = q.size();
00043     if (opt.naive) {
00044       for (int i = 0; i<n; i++)
00045         for (int j = i+1; j<n; j++) {
00046           post(this, q[i] != q[j]);
00047           post(this, q[i]+i != q[j]+j);
00048           post(this, q[i]-i != q[j]-j);
00049         }
00050     } else {
00051       IntArgs c(n);
00052       for (int i = n; i--; ) c[i] = i;
00053       distinct(this, c,q, opt.icl);
00054       for (int i = n; i--; ) c[i] = -i;
00055       distinct(this, c,q, opt.icl);
00056       distinct(this, q, opt.icl);
00057     }
00058     branch(this, q, BVAR_SIZE_MIN, BVAL_MIN);
00059   }
00060 
00062   Queens(bool share, Queens& s) : Example(share,s) {
00063     q.update(this, share, s.q);
00064   }
00065 
00067   virtual Space*
00068   copy(bool share) {
00069     return new Queens(share,*this);
00070   }
00071 
00073   virtual void
00074   print(void) {
00075     std::cout << "\t";
00076     for (int i = 0; i < q.size(); i++) {
00077       std::cout << q[i] << ", ";
00078       if ((i+1) % 10 == 0)
00079         std::cout << std::endl << "\t";
00080     }
00081     std::cout << std::endl;
00082     }
00083 };
00084 
00088 int
00089 main(int argc, char** argv) {
00090   Options opt("Queens");
00091   opt.iterations = 500;
00092   opt.size       = 100;
00093   opt.parse(argc,argv);
00094   Example::run<Queens,DFS>(opt);
00095   return 0;
00096 }
00097 
00098 // STATISTICS: example-any
00099