all-interval.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00065 dom(this, d, 1, n-1);
00066
00067 distinct(this, x, opt.icl);
00068 distinct(this, d, opt.icl);
00069
00070
00071 rel(this, x[0], IRT_LE, x[1]);
00072
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
00114