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

all-interval.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2006
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 
00025 #include <cstdlib>
00026 
00048 class AllInterval : public Example {
00049 private:
00051   IntVarArray x;
00052 public:
00054   AllInterval(const Options& opt) :
00055     x(this, opt.size, 0, opt.size - 1) {
00056     const int n = x.size();
00057 
00058     IntVarArgs d(n-1);
00059 
00060     // Set up variables for distance
00061     for (int i=0; i<n-1; i++)
00062       d[i] = abs(this, minus(this,x[i+1],x[i],opt.icl),opt.icl);
00063 
00064     // Constrain them to be between 1 and n-1
00065     dom(this, d, 1, n-1);
00066 
00067     distinct(this, x, opt.icl);
00068     distinct(this, d, opt.icl);
00069 
00070     // Break mirror symmetry
00071     rel(this, x[0], IRT_LE, x[1]);
00072     // Break symmetry of dual solution
00073     rel(this, d[0], IRT_GR, d[n-2]);
00074 
00075     branch(this, x, BVAR_SIZE_MIN, BVAL_SPLIT_MIN);
00076   }
00078   AllInterval(bool share, AllInterval& e)
00079     : Example(share, e) {
00080     x.update(this, share, e.x);
00081   }
00083   virtual Space*
00084   copy(bool share) {
00085     return new AllInterval(share, *this);
00086   }
00088   virtual void
00089   print(void) {
00090     const int n = x.size();
00091     std::cout << "\tx[" << n << "] = {";
00092     for (int i = 0; i < n-1; i++)
00093       std::cout << x[i] << "(" << abs(x[i+1].val()-x[i].val()) << "),";
00094     std::cout << x[n-1] << "}" << std::endl;
00095   }
00096 };
00097 
00098 
00099 int main(int argc, char** argv){
00100   Options opt("All-interval Series");
00101   opt.size       = 1000;
00102   opt.iterations = 5;
00103   opt.icl        = ICL_BND;
00104   opt.parse(argc, argv);
00105   if (opt.size < 2) {
00106     std::cerr << "n must be at least 2!" << std::endl;
00107     return -1;
00108   }
00109   Example::run<AllInterval,DFS>(opt);
00110   return 0;
00111 }
00112 
00113 // STATISTICS: example-any
00114