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

grocery.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 
00041 class Grocery : public Example {
00042 protected:
00044   IntVarArray x;
00046   static const int s = 711;
00047 public:
00049   Grocery(const Options&) : x(this,4,0,s) {
00050 
00051     // The sum of all variables is s
00052     post(this, x[0]+x[1]+x[2]+x[3] == s);
00053 
00054     // The product of all variables is s (corrected by scale factor)
00055     {
00056       IntVar t0(this,0,Limits::Int::int_max);
00057       IntVar t1(this,0,Limits::Int::int_max);
00058       IntVar t2(this,0,Limits::Int::int_max);
00059       rel(this, t2, IRT_EQ, s*100*100*100);
00060       mult(this, x[0], x[1], t0);
00061       mult(this, x[2], x[3], t1);
00062       mult(this, t0, t1, t2);
00063     }
00064 
00065     // Break symmetries: order the variables
00066     rel(this, x[0], IRT_LQ, x[1]);
00067     rel(this, x[1], IRT_LQ, x[2]);
00068     rel(this, x[2], IRT_LQ, x[3]);
00069 
00070     branch(this, x, BVAR_SIZE_MIN, BVAL_SPLIT_MAX);
00071   }
00072 
00074   Grocery(bool share, Grocery& s) : Example(share,s) {
00075     x.update(this, share, s.x);
00076   }
00077 
00079   virtual Space*
00080   copy(bool share) {
00081     return new Grocery(share,*this);
00082   }
00083 
00085   virtual void
00086   print(void) {
00087     std::cout << "\t";
00088     for (int i = 0; i < x.size(); i++)
00089       std::cout << x[i] << ", ";
00090     std::cout << std::endl;
00091   }
00092 };
00093 
00097 int
00098 main(int argc, char** argv) {
00099   Options opt("Grocery");
00100   opt.iterations = 20;
00101   opt.parse(argc,argv);
00102   Example::run<Grocery,DFS>(opt);
00103   return 0;
00104 }
00105 
00106 // STATISTICS: example-any
00107