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
00094 for (int i=1; i<=n; i++)
00095 for (int j=1; i+j<=n; j++)
00096 rel(*this, {box[i-1],box[j-1],box[i+j-1]}, IRT_NQ);
00097
00098
00099 precede(*this, box, IntArgs::create(opt.c, 1));
00100
00101 branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
00102 }
00104 virtual void
00105 print(std::ostream& os) const {
00106 os << "\t" << box << std::endl;
00107 }
00108
00110 Schur(Schur& s) : Script(s) {
00111 box.update(*this, s.box);
00112 }
00114 virtual Space*
00115 copy(void) {
00116 return new Schur(*this);
00117 }
00118 };
00119
00123 int
00124 main(int argc, char* argv[]) {
00125 SchurOptions opt("Schur's Lemma",3,13);
00126 opt.parse(argc,argv);
00127 Script::run<Schur,DFS,SchurOptions>(opt);
00128 return 0;
00129 }
00130
00131
00132