Generated on Thu Mar 22 10:39:31 2012 for Gecode by doxygen 1.6.3

ind-set.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, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-10-07 11:52:01 +0200 (Thu, 07 Oct 2010) $ by $Author: schulte $
00011  *     $Revision: 11473 $
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 
00050 
00051 class Graph {
00052 public:
00053   const int  n_v; 
00054   const int  n_e; 
00055   const int* e;   
00056   Graph(const int n_v0, const int n_e0, const int* e0)
00057     : n_v(n_v0), n_e(n_e0), e(e0) {}
00058 };
00059 
00060 const int e_20_10[] = {
00061   0, 4,  2,12,  12,14,  18,19,   7,10,
00062   9,12,  5,11,   6,15,   3,18,   7,16
00063 };
00064 
00065 const Graph g_20_10(20,10,e_20_10);
00066 
00067 const int e_40_20[] = {
00068   21,30,   11,30,   19,38,   20,25,   11,24,
00069   20,33,    8,39,    4, 5,    6,16,    5,32,
00070   0, 9,    5,24,   25,28,   36,38,   14,20,
00071   19,25,   11,22,   13,30,    7,36,   15,33
00072 };
00073 
00074 const Graph g_40_20(40, 20, e_40_20);
00076 
00077 
00084 class IndSet : public MaximizeScript {
00085 protected:
00087   const Graph& g;
00089   BoolVarArray v;
00091   IntVar       k;
00092 public:
00094   IndSet(const SizeOptions& opt)
00095     : g(opt.size() == 0 ?  g_20_10 : g_40_20),
00096       v(*this,g.n_v,0,1), k(*this,0,g.n_v) {
00097     const int* e = g.e;
00098     for (int i = g.n_e; i--; ) {
00099       const int* e1 = e++; const int* e2 = e++;
00100       rel(*this, v[*e1], BOT_AND, v[*e2], 0);
00101     }
00102     linear(*this, v, IRT_EQ, k);
00103     branch(*this, v, INT_VAR_NONE, INT_VAL_MIN);
00104   }
00105 
00107   IndSet(bool share, IndSet& s) : MaximizeScript(share,s), g(s.g) {
00108     v.update(*this, share, s.v);
00109     k.update(*this, share, s.k);
00110   }
00112   virtual Space*
00113   copy(bool share) {
00114     return new IndSet(share,*this);
00115   }
00117   virtual void
00118   print(std::ostream& os) const {
00119     os << "\tk = " << k << std::endl
00120        << "\tv[] = " << v << std::endl;
00121   }
00123   virtual IntVar cost(void) const {
00124     return k;
00125   }
00126 };
00127 
00128 
00132 int
00133 main(int argc, char* argv[]) {
00134   SizeOptions opt("IndSet");
00135   opt.solutions(0);
00136   opt.size(1);
00137   opt.iterations(2000);
00138   opt.parse(argc,argv);
00139   MaximizeScript::run<IndSet,BAB,SizeOptions>(opt);
00140   return 0;
00141 }
00142 
00143 // STATISTICS: example-any
00144