Generated on Thu Mar 22 10:39:31 2012 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  *  Last modified:
00010  *     $Date: 2011-07-08 12:09:31 +0200 (Fri, 08 Jul 2011) $ by $Author: schulte $
00011  *     $Revision: 12164 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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) : box(*this,opt.n,1,opt.c) {
00094     int n = opt.n;
00095 
00096     IntVarArgs triple(3);
00097 
00098     // Iterate over balls and find triples
00099     for (int i=1; i<=n; i++) {
00100       triple[0] = box[i-1];
00101       for (int j=1; i+j<=n; j++) {
00102         triple[1] = box[j-1];
00103         triple[2] = box[i+j-1];
00104         rel(*this, triple, IRT_NQ);
00105       }
00106     }
00107 
00108     // Break value symmetries
00109     precede(*this, box, IntArgs::create(opt.c, 1));
00110 
00111     branch(*this, box, INT_VAR_SIZE_AFC_MIN, INT_VAL_MIN);
00112   }
00114   virtual void
00115   print(std::ostream& os) const {
00116     os << "\t" << box << std::endl;
00117   }
00118 
00120   Schur(bool share, Schur& s) : Script(share,s) {
00121     box.update(*this, share, s.box);
00122   }
00124   virtual Space*
00125   copy(bool share) {
00126     return new Schur(share,*this);
00127   }
00128 };
00129 
00133 int
00134 main(int argc, char* argv[]) {
00135   SchurOptions opt("Schur's Lemma",3,13);
00136   opt.parse(argc,argv);
00137   Script::run<Schur,DFS,SchurOptions>(opt);
00138   return 0;
00139 }
00140 
00141 // STATISTICS: example-any
00142