Generated on Tue Mar 5 2013 22:37:24 for Gecode by doxygen 1.8.3.1
support-values.hpp
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, 2008
8  *
9  * Last modified:
10  * $Date: 2010-01-29 03:13:59 +1100 (Fri, 29 Jan 2010) $ by $Author: schulte $
11  * $Revision: 10244 $
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 namespace Gecode { namespace Int {
39 
40  template<class View, class A>
41  forceinline void
43  rp = rp_fst; v = rp->min;
44  max = rp->min + static_cast<int>((rp+1)->pos - rp->pos) - 1;
45  }
46 
47  template<class View, class A>
48  inline
50  : a(a0), x(x0), bs(a,x.size(),true) {
51  unsigned int n = 0;
52  for (ViewRanges<View> r(x); r(); ++r)
53  n++;
54  rp_fst = a.template alloc<RangePos>(n+1);
55  rp_lst = rp_fst + n;
56  unsigned int p = 0;
57  int i = 0;
58  for (ViewRanges<View> r(x); r(); ++r) {
59  rp_fst[i].min = r.min();
60  rp_fst[i].pos = p;
61  p += r.width(); i++;
62  }
63  rp_fst[i].pos=p;
64  reset();
65  }
66 
67  template<class View, class A>
70  bs.dispose(a);
71  a.free(rp_fst,static_cast<unsigned long int>(rp_lst-rp_fst+1));
72  }
73 
74  template<class View, class A>
75  forceinline void
77  if (++v > max)
78  if (++rp < rp_lst) {
79  v = rp->min;
80  max = rp->min + static_cast<int>((rp+1)->pos - rp->pos) - 1;
81  }
82  }
83 
84  template<class View, class A>
85  forceinline bool
87  return rp < rp_lst;
88  }
89 
90  template<class View, class A>
91  forceinline int
93  return v;
94  }
95 
96  template<class View, class A>
97  forceinline void
99  bs.clear(rp->pos + static_cast<unsigned int>(v-rp->min));
100  }
101 
102  template<class View, class A>
103  forceinline bool
105  RangePos* l = rp_fst;
106  RangePos* r = rp_lst-1;
107  while (true) {
108  if (l > r) return false;
109  RangePos* m = l + (r-l)/2;
110  int max = m->min + static_cast<int>((m+1)->pos - m->pos) - 1;
111  if ((n >= m->min) && (n <= max)) {
112  bs.clear(m->pos + static_cast<unsigned int>(n-m->min));
113  return true;
114  }
115  if (l == r) return false;
116  if (n < m->min)
117  r=m-1;
118  else
119  l=m+1;
120  }
121  GECODE_NEVER;
122  return false;
123  }
124 
125  template<class View, class A>
126  forceinline bool
128  if ((n < x.min()) || (n > x.max()))
129  return false;
130  return _support(n);
131  }
132 
133  template<class View, class A>
134  forceinline bool
136  if ((n < x.min()) || (n > x.max()))
137  return false;
138  return _support(static_cast<int>(n));
139  }
140 
141  template<class View, class A>
142  forceinline void
144  // Skip all supported positions
145  while ((p < sv.x.size()) && !sv.bs.get(p))
146  p = sv.bs.next(p);
147  // Move to matching range
148  while ((rp < sv.rp_lst) && (p >= (rp+1)->pos))
149  rp++;
150  }
151 
152  template<class View, class A>
155  : rp(sv0.rp_fst), p(0), sv(sv0) {
156  find();
157  }
158 
159  template<class View, class A>
160  forceinline void
161  SupportValues<View,A>::Unsupported::operator ++(void) {
162  p++; find();
163  }
164 
165  template<class View, class A>
166  forceinline bool
167  SupportValues<View,A>::Unsupported::operator ()(void) const {
168  return rp < sv.rp_lst;
169  }
170 
171  template<class View, class A>
172  forceinline int
173  SupportValues<View,A>::Unsupported::val(void) const {
174  return static_cast<int>(rp->min+(p-rp->pos));
175  }
176 
177  template<class View, class A>
178  inline ModEvent
180  Unsupported u(*this);
181  return x.minus_v(home,u,false);
182  }
183 
184 }}
185 
186 // STATISTICS: int-prop
187