Generated on Mon Feb 8 2021 00:00:00 for Gecode by doxygen 1.8.20
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 namespace Gecode { namespace Int {
35 
36  template<class View, class A>
37  forceinline void
39  rp = rp_fst; v = rp->min;
40  max = rp->min + static_cast<int>((rp+1)->pos - rp->pos) - 1;
41  }
42 
43  template<class View, class A>
44  inline
46  : a(a0), x(x0), bs(a,x.size(),true) {
47  unsigned int n = 0;
48  for (ViewRanges<View> r(x); r(); ++r)
49  n++;
50  rp_fst = a.template alloc<RangePos>(n+1);
51  rp_lst = rp_fst + n;
52  unsigned int p = 0;
53  int i = 0;
54  for (ViewRanges<View> r(x); r(); ++r) {
55  rp_fst[i].min = r.min();
56  rp_fst[i].pos = p;
57  p += r.width(); i++;
58  }
59  rp_fst[i].pos=p;
60  reset();
61  }
62 
63  template<class View, class A>
66  bs.dispose(a);
67  a.free(rp_fst,static_cast<unsigned long int>(rp_lst-rp_fst+1));
68  }
69 
70  template<class View, class A>
71  forceinline void
73  if (++v > max)
74  if (++rp < rp_lst) {
75  v = rp->min;
76  max = rp->min + static_cast<int>((rp+1)->pos - rp->pos) - 1;
77  }
78  }
79 
80  template<class View, class A>
81  forceinline bool
83  return rp < rp_lst;
84  }
85 
86  template<class View, class A>
87  forceinline int
89  return v;
90  }
91 
92  template<class View, class A>
93  forceinline void
95  bs.clear(rp->pos + static_cast<unsigned int>(v-rp->min));
96  }
97 
98  template<class View, class A>
99  forceinline bool
101  RangePos* l = rp_fst;
102  RangePos* r = rp_lst-1;
103  while (true) {
104  if (l > r) return false;
105  RangePos* m = l + (r-l)/2;
106  int max = m->min + static_cast<int>((m+1)->pos - m->pos) - 1;
107  if ((n >= m->min) && (n <= max)) {
108  bs.clear(m->pos + static_cast<unsigned int>(n-m->min));
109  return true;
110  }
111  if (l == r) return false;
112  if (n < m->min)
113  r=m-1;
114  else
115  l=m+1;
116  }
117  GECODE_NEVER;
118  return false;
119  }
120 
121  template<class View, class A>
122  forceinline bool
124  if ((n < x.min()) || (n > x.max()))
125  return false;
126  return _support(n);
127  }
128 
129  template<class View, class A>
130  forceinline bool
132  if ((n < x.min()) || (n > x.max()))
133  return false;
134  return _support(static_cast<int>(n));
135  }
136 
137  template<class View, class A>
138  forceinline void
140  // Skip all supported positions
141  while ((p < sv.x.size()) && !sv.bs.get(p))
142  p = sv.bs.next(p);
143  // Move to matching range
144  while ((rp < sv.rp_lst) && (p >= (rp+1)->pos))
145  rp++;
146  }
147 
148  template<class View, class A>
151  : rp(sv0.rp_fst), p(0), sv(sv0) {
152  find();
153  }
154 
155  template<class View, class A>
156  forceinline void
157  SupportValues<View,A>::Unsupported::operator ++(void) {
158  p++; find();
159  }
160 
161  template<class View, class A>
162  forceinline bool
163  SupportValues<View,A>::Unsupported::operator ()(void) const {
164  return rp < sv.rp_lst;
165  }
166 
167  template<class View, class A>
168  forceinline int
169  SupportValues<View,A>::Unsupported::val(void) const {
170  return static_cast<int>(rp->min+(p-rp->pos));
171  }
172 
173  template<class View, class A>
174  inline ModEvent
176  Unsupported u(*this);
177  return x.minus_v(home,u,false);
178  }
179 
180 }}
181 
182 // STATISTICS: int-prop
183 
SupportValues(A &a, View x)
Initialize for view x.
Post propagator for SetVar x
Definition: set.hh:767
int val(void) const
Return current value.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:49
unsigned int size(I &i)
Size of all ranges of range iterator i.
Support value iterator and recorder
Computation spaces.
Definition: core.hpp:1742
void operator++(void)
Move iterator to next value (if possible)
Gecode toplevel namespace
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Range iterator for integer views.
Definition: view.hpp:54
void support(void)
Mark current (iterator) value as supported.
~SupportValues(void)
Destructor.
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
bool operator()(void) const
Test whether iterator is still at a value or done.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
void reset(void)
Reset iterator.
int ModEvent
Type for modification events.
Definition: core.hpp:62
const int v[7]
Definition: distinct.cpp:259
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
ModEvent tell(Space &home)
Remove all unsupported values.
#define forceinline
Definition: config.hpp:192
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:41
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232