Generated on Tue Oct 22 2013 00:49:03 for Gecode by doxygen 1.8.4
base.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Mikael Lagerkvist <lagerkvist@gecode.org>
5  *
6  * Contributing authors:
7  * Christian Schulte <schulte@gecode.org>
8  *
9  * Copyright:
10  * Mikael Lagerkvist, 2007
11  * Christian Schulte, 2008
12  *
13  * Last modified:
14  * $Date: 2012-07-19 08:53:57 +0200 (Thu, 19 Jul 2012) $ by $Author: tack $
15  * $Revision: 12963 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 namespace Gecode { namespace Int { namespace Extensional {
42  /*
43  * The propagator proper
44  *
45  */
46 
47  template<class View, bool subscribe>
50  const TupleSet& t)
51  : Propagator(home), x(x0), tupleSet(t), last_data(NULL) {
52  if (subscribe)
53  x.subscribe(home, *this, PC_INT_DOM);
54 
55  assert(ts()->finalized());
56 
57  init_last(home, ts()->last, ts()->tuple_data);
58 
59  home.notice(*this,AP_DISPOSE);
60  }
61 
62  template<class View, bool subscribe>
65  : Propagator(home,share,p), last_data(NULL) {
66  x.update(home, share, p.x);
67  tupleSet.update(home, share, p.tupleSet);
68 
69  init_last(home, p.last_data, p.ts()->tuple_data);
70  }
71 
72  template<class View, bool subscribe>
73  forceinline void
75  if (last_data == NULL) {
76  int literals = static_cast<int>(ts()->domsize*x.size());
77  last_data = home.alloc<Tuple*>(literals);
78  for (int i = literals; i--; )
79  last_data[i] = ts()->tuple_data+(source[i]-base);
80  }
81  }
82 
83  template<class View, bool subscribe>
86  return tupleSet.implementation();
87  }
88 
89  template<class View, bool subscribe>
90  PropCost
92  return PropCost::quadratic(PropCost::HI,x.size());
93  }
94 
95 #define GECODE_LAST_TUPLE(l) (*(l))
96 
97  template<class View, bool subscribe>
100  return GECODE_LAST_TUPLE(last_data[(i*ts()->domsize) + n]);
101  }
102 
103  template<class View, bool subscribe>
106  assert(last(i,n) != NULL);
107  assert(last(i,n)[i] == n+ts()->min);
108  int pos = (i*static_cast<int>(ts()->domsize)) + n;
109  ++(last_data[pos]);
110  if (last(i,n)[i] != (n+ts()->min))
111  last_data[pos] = ts()->nullpointer;
112  return last(i,n);
113  }
114 
115 
116  template<class View, bool subscribe>
117  forceinline void
119  unsigned int domsize = ts()->domsize;
120  for (int i = x.size(); i--; ) {
121  dom[i].init(home, domsize);
122  for (ViewValues<View> vv(x[i]); vv(); ++vv)
123  dom[i].set(static_cast<unsigned int>(vv.val()-ts()->min));
124  }
125  }
126 
127  template<class View, bool subscribe>
128  forceinline bool
130  for (int i = x.size(); i--; )
131  if (!dom[i].get(static_cast<unsigned int>(t[i]-ts()->min)))
132  return false;
133  return true;
134  }
135 #undef GECODE_LAST_TUPLE
136  template<class View, bool subscribe>
139  Tuple l = last(i,n);
140  while ((l != NULL) && !valid(l, dom))
141  l = last_next(i,n);
142  return l;
143  }
144 
145 
146  template<class View, bool subscribe>
147  forceinline size_t
149  home.ignore(*this,AP_DISPOSE);
150  (void) Propagator::dispose(home);
151  if (subscribe)
152  x.cancel(home,*this,PC_INT_DOM);
153  // take care of last_data
154  unsigned int literals = ts()->domsize*x.size();
155  home.rfree(last_data, sizeof(Tuple*)*literals);
156  (void) tupleSet.~TupleSet();
157  return sizeof(*this);
158  }
159 
160 }}}
161 
162 // STATISTICS: int-prop
163