Generated on Thu Mar 7 2013 10:21:14 for Gecode by doxygen 1.8.3.1
ind-set.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2002
8  *
9  * Last modified:
10  * $Date: 2010-10-07 20:52:01 +1100 (Thu, 07 Oct 2010) $ by $Author: schulte $
11  * $Revision: 11473 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/driver.hh>
39 #include <gecode/int.hh>
40 #include <gecode/minimodel.hh>
41 
42 using namespace Gecode;
43 
50 
51 class Graph {
52 public:
53  const int n_v;
54  const int n_e;
55  const int* e;
56  Graph(const int n_v0, const int n_e0, const int* e0)
57  : n_v(n_v0), n_e(n_e0), e(e0) {}
58 };
59 
60 const int e_20_10[] = {
61  0, 4, 2,12, 12,14, 18,19, 7,10,
62  9,12, 5,11, 6,15, 3,18, 7,16
63 };
64 
65 const Graph g_20_10(20,10,e_20_10);
66 
67 const int e_40_20[] = {
68  21,30, 11,30, 19,38, 20,25, 11,24,
69  20,33, 8,39, 4, 5, 6,16, 5,32,
70  0, 9, 5,24, 25,28, 36,38, 14,20,
71  19,25, 11,22, 13,30, 7,36, 15,33
72 };
73 
74 const Graph g_40_20(40, 20, e_40_20);
76 
77 
84 class IndSet : public MaximizeScript {
85 protected:
87  const Graph& g;
92 public:
95  : g(opt.size() == 0 ? g_20_10 : g_40_20),
96  v(*this,g.n_v,0,1), k(*this,0,g.n_v) {
97  const int* e = g.e;
98  for (int i = g.n_e; i--; ) {
99  const int* e1 = e++; const int* e2 = e++;
100  rel(*this, v[*e1], BOT_AND, v[*e2], 0);
101  }
102  linear(*this, v, IRT_EQ, k);
103  branch(*this, v, INT_VAR_NONE, INT_VAL_MIN);
104  }
105 
107  IndSet(bool share, IndSet& s) : MaximizeScript(share,s), g(s.g) {
108  v.update(*this, share, s.v);
109  k.update(*this, share, s.k);
110  }
112  virtual Space*
113  copy(bool share) {
114  return new IndSet(share,*this);
115  }
117  virtual void
118  print(std::ostream& os) const {
119  os << "\tk = " << k << std::endl
120  << "\tv[] = " << v << std::endl;
121  }
123  virtual IntVar cost(void) const {
124  return k;
125  }
126 };
127 
128 
132 int
133 main(int argc, char* argv[]) {
134  SizeOptions opt("IndSet");
135  opt.solutions(0);
136  opt.size(1);
137  opt.iterations(2000);
138  opt.parse(argc,argv);
139  MaximizeScript::run<IndSet,BAB,SizeOptions>(opt);
140  return 0;
141 }
142 
143 // STATISTICS: example-any
144