all-interval.cpp
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 #include <gecode/driver.hh>
00035 #include <gecode/int.hh>
00036 #include <gecode/minimodel.hh>
00037
00038 #include <cstdlib>
00039
00040 using namespace Gecode;
00041
00062 class AllInterval : public Script {
00063 private:
00065 IntVarArray x;
00067 IntVarArray d;
00068 public:
00070 AllInterval(const SizeOptions& opt) :
00071 Script(opt),
00072 x(*this, opt.size(), 0, opt.size()-1),
00073 d(*this, opt.size()-1, 1, opt.size()-1) {
00074 const int n = x.size();
00075
00076
00077 for (int i=0; i<n-1; i++)
00078 rel(*this, d[i] == abs(x[i+1]-x[i]), opt.ipl());
00079
00080 distinct(*this, x, opt.ipl());
00081 distinct(*this, d, opt.ipl());
00082
00083
00084 rel(*this, x[0], IRT_LE, x[1]);
00085
00086 rel(*this, d[0], IRT_GR, d[n-2]);
00087
00088 branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN());
00089 }
00091 AllInterval(AllInterval& s)
00092 : Script(s) {
00093 x.update(*this, s.x);
00094 d.update(*this, s.d);
00095 }
00097 virtual Space*
00098 copy(void) {
00099 return new AllInterval(*this);
00100 }
00102 virtual void
00103 print(std::ostream& os) const {
00104 const int n = x.size();
00105 os << "\tx[" << n << "] = {";
00106 for (int i = 0; i < n-1; i++)
00107 os << x[i] << "(" << d[i] << "),";
00108 os << x[n-1] << "}" << std::endl;
00109 }
00110 };
00111
00112
00116 int
00117 main(int argc, char* argv[]){
00118 SizeOptions opt("AllInterval");
00119 opt.size(1000);
00120 opt.iterations(5);
00121 opt.ipl(IPL_BND);
00122 opt.parse(argc, argv);
00123 if (opt.size() < 2) {
00124 std::cerr << "size must be at least 2!" << std::endl;
00125 return -1;
00126 }
00127 Script::run<AllInterval,DFS,SizeOptions>(opt);
00128 return 0;
00129 }
00130
00131
00132