schurs-lemma.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 #include <gecode/driver.hh>
00039 #include <gecode/int.hh>
00040 #include <gecode/minimodel.hh>
00041
00042 using namespace Gecode;
00043
00048 class SchurOptions : public Options {
00049 public:
00050 int c, n;
00051
00052 SchurOptions(const char* s, int c0, int n0)
00053 : Options(s), c(c0), n(n0) {}
00055 void parse(int& argc, char* argv[]) {
00056 Options::parse(argc,argv);
00057 if (argc < 3)
00058 return;
00059 c = atoi(argv[1]);
00060 n = atoi(argv[2]);
00061 }
00063 virtual void help(void) {
00064 Options::help();
00065 std::cerr << "\t(unsigned int) default: " << c << std::endl
00066 << "\t\tparameter c (number of boxes)" << std::endl
00067 << "\t(unsigned int) default: " << n << std::endl
00068 << "\t\tparameter n (number of balls)" << std::endl;
00069 }
00070 };
00071
00072
00087 class Schur : public Script {
00088 protected:
00090 IntVarArray box;
00091 public:
00093 Schur(const SchurOptions& opt)
00094 : Script(opt), box(*this,opt.n,1,opt.c) {
00095 int n = opt.n;
00096
00097 IntVarArgs triple(3);
00098
00099
00100 for (int i=1; i<=n; i++) {
00101 triple[0] = box[i-1];
00102 for (int j=1; i+j<=n; j++) {
00103 triple[1] = box[j-1];
00104 triple[2] = box[i+j-1];
00105 rel(*this, triple, IRT_NQ);
00106 }
00107 }
00108
00109
00110 precede(*this, box, IntArgs::create(opt.c, 1));
00111
00112 branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
00113 }
00115 virtual void
00116 print(std::ostream& os) const {
00117 os << "\t" << box << std::endl;
00118 }
00119
00121 Schur(bool share, Schur& s) : Script(share,s) {
00122 box.update(*this, share, s.box);
00123 }
00125 virtual Space*
00126 copy(bool share) {
00127 return new Schur(share,*this);
00128 }
00129 };
00130
00134 int
00135 main(int argc, char* argv[]) {
00136 SchurOptions opt("Schur's Lemma",3,13);
00137 opt.parse(argc,argv);
00138 Script::run<Schur,DFS,SchurOptions>(opt);
00139 return 0;
00140 }
00141
00142
00143