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

hamming.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004
00008  *     Christian Schulte, 2004
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-08-03 13:51:17 +0200 (Thu, 03 Aug 2006) $ by $Author: schulte $
00012  *     $Revision: 3506 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
00021  *
00022  */
00023 
00024 #include "gecode/set.hh"
00025 #include "examples/support.hh"
00026 #include "gecode/minimodel.hh"
00027 
00041 class Hamming : public Example {
00042 public:
00043   SetVarArray xs;
00044 
00045   static const int bits = 20;
00046   static const int dist = 3;
00047 
00048   Hamming(const Options& o) :
00049     xs(this,o.size,IntSet::empty,1,bits) {
00050     SetVarArray cxs(this,xs.size());
00051     for (int i=0; i<xs.size(); i++)
00052       rel(this, xs[i], SRT_CMPL, cxs[i]);
00053 
00054     for (int i=0; i<xs.size(); i++) {
00055       SetVar y = xs[i];
00056       SetVar cy = cxs[i];
00057       for (int j=i+1; j<xs.size(); j++) {
00058         SetVar x = xs[j];
00059         SetVar cx = cxs[j];
00060 
00061         SetVar xIntCy(this);
00062         SetVar yIntCx(this);
00063 
00064         rel(this, x, SOT_INTER, cy, SRT_EQ, xIntCy);
00065         rel(this, y, SOT_INTER, cx, SRT_EQ, yIntCx);
00066         IntVar diff1(this,0,1024);
00067         IntVar diff2(this,0,1204);
00068         cardinality(this, xIntCy,diff1);
00069         cardinality(this, yIntCx,diff2);
00070         post(this, diff1+diff2 >= dist);
00071 
00072       }
00073     }
00074 
00075     branch(this, xs, SETBVAR_NONE, SETBVAL_MIN);
00076   }
00077 
00078   Hamming(bool share, Hamming& s) : Example(share,s) {
00079     xs.update(this, share, s.xs);
00080   }
00081 
00082   virtual Space*
00083   copy(bool share) {
00084     return new Hamming(share,*this);
00085   }
00086 
00087   virtual void
00088   print(void) {
00089     for (int i=0; i<xs.size(); i++) {
00090       std::cout << "\t[" << i << "]" << xs[i] << std::endl;
00091     }
00092   }
00093 };
00094 
00095 
00096 int
00097 main(int argc, char** argv) {
00098   Options o("Hamming");
00099   o.size = 32;
00100   o.parse(argc,argv);
00101   Example::run<Hamming,DFS>(o);
00102   return 0;
00103 }
00104 
00105 
00106 // STATISTICS: example-any
00107