Generated on Fri Oct 19 11:24:49 2018 for Gecode by doxygen 1.6.3

schurs-lemma.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2011
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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     // Iterate over balls and find triples
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     // Break value symmetries
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 // STATISTICS: example-any
00132