Generated on Wed Jan 4 17:49:07 2006 for Gecode by doxygen 1.4.6

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: 2005-11-04 15:30:42 +0100 (Fri, 04 Nov 2005) $ by $Author: schulte $
00010  *     $Revision: 2499 $
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 "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       IntVar t3(this,0,Limits::Int::int_max);
00060       rel(this, t2, IRT_EQ, s*100*100*100);
00061       mult(this, x[0], x[1], t0);
00062       mult(this, x[2], x[3], t1);
00063       mult(this, t0, t1, t2);
00064     }
00065 
00066     // Break symmetries: order the variables
00067     rel(this, x[0], IRT_LQ, x[1]);
00068     rel(this, x[1], IRT_LQ, x[2]);
00069     rel(this, x[2], IRT_LQ, x[3]);
00070 
00071     branch(this, x, BVAR_SIZE_MIN, BVAL_SPLIT_MAX);
00072   }
00073 
00075   Grocery(bool share, Grocery& s) : Example(share,s) {
00076     x.update(this, share, s.x);
00077   }
00078 
00080   virtual Space*
00081   copy(bool share) {
00082     return new Grocery(share,*this);
00083   }
00084 
00086   virtual void
00087   print(void) {
00088     std::cout << "\t";
00089     for (int i = 0; i < x.size(); i++) 
00090       std::cout << x[i] << ", ";
00091     std::cout << std::endl;
00092   }
00093 };
00094 
00098 int
00099 main(int argc, char** argv) {
00100   Options opt("Grocery");
00101   opt.iterations = 20;
00102   opt.parse(argc,argv);
00103   Example::run<Grocery,DFS>(opt);
00104   return 0;
00105 }
00106 
00107 // STATISTICS: example-any
00108