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 #include <gecode/driver.hh>
00035 #include <gecode/int.hh>
00036 #include <gecode/minimodel.hh>
00037
00038 using namespace Gecode;
00039
00044 class SchurOptions : public Options {
00045 public:
00046 int c, n;
00047
00048 SchurOptions(const char* s, int c0, int n0)
00049 : Options(s), c(c0), n(n0) {}
00051 void parse(int& argc, char* argv[]) {
00052 Options::parse(argc,argv);
00053 if (argc < 3)
00054 return;
00055 c = atoi(argv[1]);
00056 n = atoi(argv[2]);
00057 }
00059 virtual void help(void) {
00060 Options::help();
00061 std::cerr << "\t(unsigned int) default: " << c << std::endl
00062 << "\t\tparameter c (number of boxes)" << std::endl
00063 << "\t(unsigned int) default: " << n << std::endl
00064 << "\t\tparameter n (number of balls)" << std::endl;
00065 }
00066 };
00067
00068
00083 class Schur : public Script {
00084 protected:
00086 IntVarArray box;
00087 public:
00089 Schur(const SchurOptions& opt)
00090 : Script(opt), box(*this,opt.n,1,opt.c) {
00091 int n = opt.n;
00092
00093 IntVarArgs triple(3);
00094
00095
00096 for (int i=1; i<=n; i++) {
00097 triple[0] = box[i-1];
00098 for (int j=1; i+j<=n; j++) {
00099 triple[1] = box[j-1];
00100 triple[2] = box[i+j-1];
00101 rel(*this, triple, IRT_NQ);
00102 }
00103 }
00104
00105
00106 precede(*this, box, IntArgs::create(opt.c, 1));
00107
00108 branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
00109 }
00111 virtual void
00112 print(std::ostream& os) const {
00113 os << "\t" << box << std::endl;
00114 }
00115
00117 Schur(Schur& s) : Script(s) {
00118 box.update(*this, s.box);
00119 }
00121 virtual Space*
00122 copy(void) {
00123 return new Schur(*this);
00124 }
00125 };
00126
00130 int
00131 main(int argc, char* argv[]) {
00132 SchurOptions opt("Schur's Lemma",3,13);
00133 opt.parse(argc,argv);
00134 Script::run<Schur,DFS,SchurOptions>(opt);
00135 return 0;
00136 }
00137
00138
00139