magic-sequence.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
00035
00036
00037
00038
00039
00040 #include <gecode/driver.hh>
00041 #include <gecode/int.hh>
00042 #include <gecode/minimodel.hh>
00043
00044 using namespace Gecode;
00045
00060 class MagicSequence : public Script {
00061 private:
00063 const int n;
00065 IntVarArray s;
00066 public:
00068 enum {
00069 PROP_COUNT,
00070 PROP_GCC
00071 };
00073 MagicSequence(const SizeOptions& opt)
00074 : n(opt.size()), s(*this,n,0,n-1) {
00075 switch (opt.propagation()) {
00076 case PROP_COUNT:
00077 for (int i=n; i--; )
00078 count(*this, s, i, IRT_EQ, s[i]);
00079 linear(*this, s, IRT_EQ, n);
00080 break;
00081 case PROP_GCC:
00082 count(*this, s, s, opt.icl());
00083 break;
00084 }
00085 IntArgs c(n);
00086 for (int j = n; j--; )
00087 c[j] = j-1;
00088 linear(*this, c, s, IRT_EQ, 0);
00089 branch(*this, s, INT_VAR_NONE, INT_VAL_SPLIT_MAX);
00090 }
00091
00093 MagicSequence(bool share, MagicSequence& e) : Script(share,e), n(e.n) {
00094 s.update(*this, share, e.s);
00095 }
00097 virtual Space*
00098 copy(bool share) {
00099 return new MagicSequence(share,*this);
00100 }
00102 virtual
00103 void print(std::ostream& os) const {
00104 os << "\t";
00105 for (int i = 0; i<n; i++) {
00106 os << s[i] << ", ";
00107 if ((i+1) % 20 == 0)
00108 os << std::endl << "\t";
00109 }
00110 os << std::endl;
00111 }
00112
00113 };
00114
00118 int
00119 main(int argc, char* argv[]) {
00120 SizeOptions opt("MagicSequence");
00121 opt.solutions(0);
00122 opt.iterations(4);
00123 opt.size(500);
00124 opt.propagation(MagicSequence::PROP_COUNT);
00125 opt.propagation(MagicSequence::PROP_COUNT, "count");
00126 opt.propagation(MagicSequence::PROP_GCC, "gcc");
00127 opt.parse(argc,argv);
00128 Script::run<MagicSequence,DFS,SizeOptions>(opt);
00129 return 0;
00130 }
00131
00132
00133