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 <gecode/driver.hh>
00039
00040 #include <gecode/int.hh>
00041 #include <gecode/minimodel.hh>
00042
00043 using namespace Gecode;
00044
00053 class Alpha : public Script {
00054 protected:
00056 static const int n = 26;
00058 IntVarArray le;
00059 public:
00061 enum {
00062 BRANCH_NONE,
00063 BRANCH_INVERSE,
00064 BRANCH_SIZE
00065 };
00067 Alpha(const Options& opt) : le(*this,n,1,n) {
00068 IntVar
00069 a(le[ 0]), b(le[ 1]), c(le[ 2]), e(le[ 4]), f(le[ 5]),
00070 g(le[ 6]), h(le[ 7]), i(le[ 8]), j(le[ 9]), k(le[10]),
00071 l(le[11]), m(le[12]), n(le[13]), o(le[14]), p(le[15]),
00072 q(le[16]), r(le[17]), s(le[18]), t(le[19]), u(le[20]),
00073 v(le[21]), w(le[22]), x(le[23]), y(le[24]), z(le[25]);
00074
00075 post(*this, b+a+l+l+e+t == 45, opt.icl());
00076 post(*this, c+e+l+l+o == 43, opt.icl());
00077 post(*this, c+o+n+c+e+r+t == 74, opt.icl());
00078 post(*this, f+l+u+t+e == 30, opt.icl());
00079 post(*this, f+u+g+u+e == 50, opt.icl());
00080 post(*this, g+l+e+e == 66, opt.icl());
00081 post(*this, j+a+z+z == 58, opt.icl());
00082 post(*this, l+y+r+e == 47, opt.icl());
00083 post(*this, o+b+o+e == 53, opt.icl());
00084 post(*this, o+p+e+r+a == 65, opt.icl());
00085 post(*this, p+o+l+k+a == 59, opt.icl());
00086 post(*this, q+u+a+r+t+e+t == 50, opt.icl());
00087 post(*this, s+a+x+o+p+h+o+n+e == 134, opt.icl());
00088 post(*this, s+c+a+l+e == 51, opt.icl());
00089 post(*this, s+o+l+o == 37, opt.icl());
00090 post(*this, s+o+n+g == 61, opt.icl());
00091 post(*this, s+o+p+r+a+n+o == 82, opt.icl());
00092 post(*this, t+h+e+m+e == 72, opt.icl());
00093 post(*this, v+i+o+l+i+n == 100, opt.icl());
00094 post(*this, w+a+l+t+z == 34, opt.icl());
00095
00096 distinct(*this, le, opt.icl());
00097
00098 switch (opt.branching()) {
00099 case BRANCH_NONE:
00100 branch(*this, le, INT_VAR_NONE, INT_VAL_MIN);
00101 break;
00102 case BRANCH_INVERSE:
00103 {
00104 IntVarArgs el(le.size());
00105 int j=0;
00106 for (int i=le.size(); i--; )
00107 el[j++]=le[i];
00108 branch(*this, el, INT_VAR_NONE, INT_VAL_MIN);
00109 }
00110 break;
00111 case BRANCH_SIZE:
00112 branch(*this, le, INT_VAR_SIZE_MIN, INT_VAL_MIN);
00113 break;
00114 }
00115 }
00116
00118 Alpha(bool share, Alpha& s) : Script(share,s) {
00119 le.update(*this, share, s.le);
00120 }
00122 virtual Space*
00123 copy(bool share) {
00124 return new Alpha(share,*this);
00125 }
00127 virtual void
00128 print(std::ostream& os) const {
00129 os << "\t";
00130 for (int i = 0; i < n; i++) {
00131 os << ((char) (i+'a')) << '=' << le[i] << ((i<n-1)?", ":"\n");
00132 if ((i+1) % 8 == 0)
00133 os << std::endl << "\t";
00134 }
00135 os << std::endl;
00136 }
00137 };
00138
00142 int
00143 main(int argc, char* argv[]) {
00144 Options opt("Alpha");
00145 opt.solutions(0);
00146 opt.iterations(10);
00147 opt.branching(Alpha::BRANCH_NONE);
00148 opt.branching(Alpha::BRANCH_NONE, "none");
00149 opt.branching(Alpha::BRANCH_INVERSE, "inverse");
00150 opt.branching(Alpha::BRANCH_SIZE, "size");
00151 opt.parse(argc,argv);
00152 Script::run<Alpha,DFS,Options>(opt);
00153 return 0;
00154 }
00155
00156
00157