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
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "examples/support.hh"
00039 #include "gecode/minimodel.hh"
00040
00041 #include <cstdlib>
00042
00063 class AllInterval : public Example {
00064 private:
00066 IntVarArray x;
00067 public:
00069 AllInterval(const SizeOptions& opt) :
00070 x(this, opt.size(), 0, opt.size() - 1) {
00071 const int n = x.size();
00072
00073 IntVarArgs d(n-1);
00074
00075
00076 for (int i=0; i<n-1; i++)
00077 d[i] = abs(this, minus(this,x[i+1],x[i],opt.icl()),opt.icl());
00078
00079
00080 dom(this, d, 1, n-1);
00081
00082 distinct(this, x, opt.icl());
00083 distinct(this, d, opt.icl());
00084
00085
00086 rel(this, x[0], IRT_LE, x[1]);
00087
00088 rel(this, d[0], IRT_GR, d[n-2]);
00089
00090 branch(this, x, INT_VAR_SIZE_MIN, INT_VAL_SPLIT_MIN);
00091 }
00093 AllInterval(bool share, AllInterval& e)
00094 : Example(share, e) {
00095 x.update(this, share, e.x);
00096 }
00098 virtual Space*
00099 copy(bool share) {
00100 return new AllInterval(share, *this);
00101 }
00103 virtual void
00104 print(std::ostream& os) {
00105 const int n = x.size();
00106 os << "\tx[" << n << "] = {";
00107 for (int i = 0; i < n-1; i++)
00108 os << x[i] << "(" << abs(x[i+1].val()-x[i].val()) << "),";
00109 os << x[n-1] << "}" << std::endl;
00110 }
00111 };
00112
00113
00117 int
00118 main(int argc, char* argv[]){
00119 SizeOptions opt("AllInterval");
00120 opt.size(1000);
00121 opt.iterations(5);
00122 opt.icl(ICL_BND);
00123 opt.parse(argc, argv);
00124 if (opt.size() < 2) {
00125 std::cerr << "size must be at least 2!" << std::endl;
00126 return -1;
00127 }
00128 Example::run<AllInterval,DFS,SizeOptions>(opt);
00129 return 0;
00130 }
00131
00132
00133