Generated on Mon Aug 25 11:35:32 2008 for Gecode by doxygen 1.5.6

ind-set.cc

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, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2007-11-30 13:58:34 +0100 (Fri, 30 Nov 2007) $ by $Author: tack $
00011  *     $Revision: 5524 $
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 "examples/support.hh"
00039 #include "gecode/minimodel.hh"
00040 
00047 
00048 class Graph {
00049 public:
00050   const int  n_v; 
00051   const int  n_e; 
00052   const int* e;   
00053   Graph(const int n_v0, const int n_e0, const int* e0)
00054     : n_v(n_v0), n_e(n_e0), e(e0) {}
00055 };
00056 
00057 const int e_20_10[] = {
00058   0, 4,  2,12,  12,14,  18,19,   7,10,
00059   9,12,  5,11,   6,15,   3,18,   7,16
00060 };
00061 
00062 const Graph g_20_10(20,10,e_20_10);
00063 
00064 const int e_40_20[] = {
00065   21,30,   11,30,   19,38,   20,25,   11,24,
00066   20,33,    8,39,    4, 5,    6,16,    5,32,
00067   0, 9,    5,24,   25,28,   36,38,   14,20,
00068   19,25,   11,22,   13,30,    7,36,   15,33
00069 };
00070 
00071 const Graph g_40_20(40, 20, e_40_20);
00073 
00074 
00081 class IndSet : public Example {
00082 protected:
00084   const Graph& g;
00086   BoolVarArray v;
00088   IntVar       k;
00089 public:
00091   IndSet(const SizeOptions& opt)
00092     : g(opt.size() == 0 ?  g_20_10 : g_40_20),
00093       v(this,g.n_v,0,1), k(this,0,g.n_e) {
00094     const int* e = g.e;
00095     const int* e1 = e++; const int* e2 = e++;
00096     for (int i = g.n_e; i--; )
00097       rel(this, v[*e1], BOT_AND, v[*e2], 0, ICL_DEF, opt.pk());
00098     linear(this, v, IRT_EQ, k, ICL_DEF, opt.pk());
00099     branch(this, v, INT_VAR_NONE, INT_VAL_MIN);
00100   }
00101 
00103   IndSet(bool share, IndSet& s) : Example(share,s), g(s.g) {
00104     v.update(this, share, s.v);
00105     k.update(this, share, s.k);
00106   }
00108   virtual Space*
00109   copy(bool share) {
00110     return new IndSet(share,*this);
00111   }
00112 
00114   virtual void
00115   print(std::ostream& os) {
00116     os << "\tk = " << k << std::endl
00117        << "\tv[] = " << v << std::endl;
00118   }
00119 
00121   void
00122   constrain(Space* s) {
00123     rel(this, k, IRT_GR, static_cast<IndSet*>(s)->k.val());
00124   }
00125 };
00126 
00127 
00131 int
00132 main(int argc, char* argv[]) {
00133   SizeOptions opt("IndSet");
00134   opt.solutions(0);
00135   opt.size(1);
00136   opt.iterations(2000);
00137   opt.parse(argc,argv);
00138   Example::run<IndSet,BAB,SizeOptions>(opt);
00139   return 0;
00140 }
00141 
00142 // STATISTICS: example-any
00143