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 #include <gecode/driver.hh>
00037 #include <gecode/int.hh>
00038 #include <gecode/minimodel.hh>
00039
00040 using namespace Gecode;
00041
00059 class MagicSequence : public Script {
00060 private:
00062 const int n;
00064 IntVarArray s;
00065 public:
00067 enum {
00068 PROP_COUNT,
00069 PROP_GCC
00070 };
00072 MagicSequence(const SizeOptions& opt)
00073 : Script(opt), n(opt.size()), s(*this,n,0,n-1) {
00074 switch (opt.propagation()) {
00075 case PROP_COUNT:
00076 for (int i=n; i--; )
00077 count(*this, s, i, IRT_EQ, s[i]);
00078 linear(*this, s, IRT_EQ, n);
00079 break;
00080 case PROP_GCC:
00081 count(*this, s, s, opt.ipl());
00082 break;
00083 }
00084 linear(*this, IntArgs::create(n,-1,1), s, IRT_EQ, 0);
00085 branch(*this, s, INT_VAR_NONE(), INT_VAL_MAX());
00086 }
00087
00089 MagicSequence(MagicSequence& e) : Script(e), n(e.n) {
00090 s.update(*this, e.s);
00091 }
00093 virtual Space*
00094 copy(void) {
00095 return new MagicSequence(*this);
00096 }
00098 virtual
00099 void print(std::ostream& os) const {
00100 os << "\t";
00101 for (int i = 0; i<n; i++) {
00102 os << s[i] << ", ";
00103 if ((i+1) % 20 == 0)
00104 os << std::endl << "\t";
00105 }
00106 os << std::endl;
00107 }
00108
00109 };
00110
00114 int
00115 main(int argc, char* argv[]) {
00116 SizeOptions opt("MagicSequence");
00117 opt.solutions(0);
00118 opt.iterations(4);
00119 opt.size(500);
00120 opt.propagation(MagicSequence::PROP_COUNT);
00121 opt.propagation(MagicSequence::PROP_COUNT, "count");
00122 opt.propagation(MagicSequence::PROP_GCC, "gcc");
00123 opt.parse(argc,argv);
00124 Script::run<MagicSequence,DFS,SizeOptions>(opt);
00125 return 0;
00126 }
00127
00128
00129