Generated on Tue May 22 09:39:39 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     IntVarArgs triple(3);
00094 
00095     // Iterate over balls and find triples
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     // Break value symmetries
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 // STATISTICS: example-any
00139