Generated on Wed Sep 5 2012 18:52:00 for Gecode by doxygen 1.8.1.1
minus.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, 2003
8  *
9  * Last modified:
10  * $Date: 2011-08-09 02:04:53 +1000 (Tue, 09 Aug 2011) $ by $Author: schulte $
11  * $Revision: 12253 $
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  /*
41  * Constructors and initialization
42  *
43  */
48  : DerivedView<IntView>(y) {}
49 
50 
51  /*
52  * Value access
53  *
54  */
55  forceinline int
56  MinusView::min(void) const {
57  return -x.max();
58  }
59  forceinline int
60  MinusView::max(void) const {
61  return -x.min();
62  }
63  forceinline int
64  MinusView::val(void) const {
65  return -x.val();
66  }
67 
68  forceinline unsigned int
69  MinusView::width(void) const {
70  return x.width();
71  }
72  forceinline unsigned int
73  MinusView::size(void) const {
74  return x.size();
75  }
76  forceinline unsigned int
77  MinusView::regret_min(void) const {
78  return x.regret_max();
79  }
80  forceinline unsigned int
81  MinusView::regret_max(void) const {
82  return x.regret_min();
83  }
84 
85 
86  /*
87  * Domain tests
88  *
89  */
90  forceinline bool
91  MinusView::range(void) const {
92  return x.range();
93  }
94  forceinline bool
95  MinusView::in(int n) const {
96  return x.in(-n);
97  }
98  forceinline bool
99  MinusView::in(double n) const {
100  return x.in(-n);
101  }
102 
103 
104  /*
105  * Domain update by value
106  *
107  */
109  MinusView::lq(Space& home, int n) {
110  return x.gq(home,-n);
111  }
113  MinusView::lq(Space& home, double n) {
114  return x.gq(home,-n);
115  }
117  MinusView::le(Space& home, int n) {
118  return x.gr(home,-n);
119  }
121  MinusView::le(Space& home, double n) {
122  return x.gr(home,-n);
123  }
125  MinusView::gq(Space& home, int n) {
126  return x.lq(home,-n);
127  }
129  MinusView::gq(Space& home, double n) {
130  return x.lq(home,-n);
131  }
133  MinusView::gr(Space& home, int n) {
134  return x.le(home,-n);
135  }
137  MinusView::gr(Space& home, double n) {
138  return x.le(home,-n);
139  }
141  MinusView::nq(Space& home, int n) {
142  return x.nq(home,-n);
143  }
145  MinusView::nq(Space& home, double n) {
146  return x.nq(home,-n);
147  }
149  MinusView::eq(Space& home, int n) {
150  return x.eq(home,-n);
151  }
153  MinusView::eq(Space& home, double n) {
154  return x.eq(home,-n);
155  }
156 
157 
158  /*
159  * Iterator-based domain update
160  *
161  */
162  template<class I>
164  MinusView::narrow_r(Space& home, I& i, bool) {
165  Region r(home);
166  Iter::Ranges::Minus mi(r,i);
167  return x.narrow_r(home,mi,false);
168  }
169  template<class I>
171  MinusView::inter_r(Space& home, I& i, bool) {
172  Region r(home);
173  Iter::Ranges::Minus mi(r,i);
174  return x.inter_r(home,mi,false);
175  }
176  template<class I>
178  MinusView::minus_r(Space& home, I& i, bool) {
179  Region r(home);
180  Iter::Ranges::Minus mi(r,i);
181  return x.minus_r(home,mi,false);
182  }
183  template<class I>
185  MinusView::narrow_v(Space& home, I& i, bool) {
186  Region r(home);
187  Iter::Values::Minus mi(r,i);
188  return x.narrow_v(home,mi,false);
189  }
190  template<class I>
192  MinusView::inter_v(Space& home, I& i, bool) {
193  Region r(home);
194  Iter::Values::Minus mi(r,i);
195  return x.inter_v(home,mi,false);
196  }
197  template<class I>
199  MinusView::minus_v(Space& home, I& i, bool) {
200  Region r(home);
201  Iter::Values::Minus mi(r,i);
202  return x.minus_v(home,mi,false);
203  }
204 
205 
206  /*
207  * Propagator modification events
208  *
209  */
212  return IntView::med(me);
213  }
214 
215 
216  /*
217  * Delta information for advisors
218  *
219  */
220  forceinline int
221  MinusView::min(const Delta& d) const {
222  return -x.max(d);
223  }
224  forceinline int
225  MinusView::max(const Delta& d) const {
226  return -x.min(d);
227  }
228  forceinline bool
229  MinusView::any(const Delta& d) const {
230  return x.any(d);
231  }
232 
233 
238  template<>
240  public:
242 
243 
244  ViewRanges(void);
246  ViewRanges(const MinusView& x);
248  void init(const MinusView& x);
250 
252 
253 
254  int min(void) const;
256  int max(void) const;
258  };
259 
262 
265  : IntVarImpBwd(x.base().varimp()) {}
266 
267  forceinline void
270  }
271 
272  forceinline int
274  return -IntVarImpBwd::max();
275  }
276  forceinline int
278  return -IntVarImpBwd::min();
279  }
280 
281  inline int
282  MinusView::med(void) const {
283  if (x.range())
284  return (min()+max())/2 - ((min()+max())%2 < 0 ? 1 : 0);
285 
286  unsigned int i = x.size() / 2;
287  if (size() % 2 == 0)
288  i--;
289  ViewRanges<MinusView> r(*this);
290  while (i >= r.width()) {
291  i -= r.width();
292  ++r;
293  }
294  return r.min() + static_cast<int>(i);
295  }
296 
297 }}
298 
299 // STATISTICS: int-var
300