Generated on Sat Feb 7 2015 02:01:26 for Gecode by doxygen 1.8.9.1
ranges-compl.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  * Guido Tack <tack@gecode.org>
6  *
7  * Copyright:
8  * Guido Tack, 2004
9  * Christian Schulte, 2005
10  *
11  * Last modified:
12  * $Date: 2010-07-28 17:35:33 +0200 (Wed, 28 Jul 2010) $ by $Author: schulte $
13  * $Revision: 11294 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 namespace Gecode { namespace Iter { namespace Ranges {
41 
52  template<int UMIN, int UMAX, class I>
53  class Compl : public MinMax {
54  protected:
56  I i;
58  void start(void);
59  public:
61 
62  Compl(void);
65  Compl(I& i);
67  void init(I& i);
69 
71 
72  void operator ++(void);
75  };
76 
77 
88  template<class I>
89  class ComplVal : public MinMax {
90  protected:
92  int UMIN, UMAX;
94  I i;
96  void start(void);
97  public:
99 
100  ComplVal(void);
103  ComplVal(int umin, int umax, I& i);
105  void init(int umin, int umax, I& i);
107 
109 
110  void operator ++(void);
113  };
114 
115 
116  template<int UMIN, int UMAX, class I>
117  forceinline void
119  if (i()) {
120  assert((i.min() >= UMIN) && (i.max() <= UMAX));
121  if (i.min() > UMIN) {
122  mi = UMIN;
123  ma = i.min()-1;
124  } else if (i.max() < UMAX) {
125  mi = i.max()+1;
126  ++i;
127  ma = i() ? (i.min()-1) : UMAX;
128  } else {
129  finish();
130  }
131  } else {
132  mi = UMIN;
133  ma = UMAX;
134  }
135  }
136 
137  template<int UMIN, int UMAX, class I>
140 
141  template<int UMIN, int UMAX, class I>
144  start();
145  }
146 
147  template<int UMIN, int UMAX, class I>
148  forceinline void
150  i=i0; start();
151  }
152 
153  template<int UMIN, int UMAX, class I>
154  forceinline void
156  assert(!i() || (i.max() <= UMAX));
157  if (i() && (i.max() < UMAX)) {
158  mi = i.max()+1;
159  ++i;
160  ma = i() ? (i.min()-1) : UMAX;
161  } else {
162  finish();
163  }
164  }
165 
166  template<class I>
167  forceinline void
169  if (i()) {
170  assert((i.min() >= UMIN) && (i.max() <= UMAX));
171  if (i.min() > UMIN) {
172  mi = UMIN;
173  ma = i.min()-1;
174  } else if (i.max() < UMAX) {
175  mi = i.max()+1;
176  ++i;
177  ma = i() ? (i.min()-1) : UMAX;
178  } else {
179  finish();
180  }
181  } else {
182  mi = UMIN;
183  ma = UMAX;
184  }
185  }
186 
187  template<class I>
190 
191  template<class I>
193  ComplVal<I>::ComplVal(int umin, int umax, I& i0)
194  : UMIN(umin), UMAX(umax), i(i0) {
195  start();
196  }
197 
198  template<class I>
199  forceinline void
200  ComplVal<I>::init(int umin, int umax, I& i0) {
201  UMIN=umin; UMAX=umax; i=i0; start();
202  }
203 
204  template<class I>
205  forceinline void
207  assert(!i() || (i.max() <= UMAX));
208  if (i() && (i.max() < UMAX)) {
209  mi = i.max()+1;
210  ++i;
211  ma = i() ? (i.min()-1) : UMAX;
212  } else {
213  finish();
214  }
215  }
216 
217 }}}
218 
219 // STATISTICS: iter-any
220 
void init(I &i)
Initialize with iterator i.
ComplVal(void)
Default constructor.
void start(void)
Initialize.
void operator++(void)
Move iterator to next range (if possible)
Compl(void)
Default constructor.
Base for range iterators with explicit min and max.
I i
Iterator to compute complement for.
Range iterator for computing the complement (described by template arguments)
int UMIN
Values describing the universe set.
void operator++(void)
Move iterator to next range (if possible)
Gecode::IntArgs i(4, 1, 2, 3, 4)
void init(int umin, int umax, I &i)
Initialize with iterator i.
#define forceinline
Definition: config.hpp:132
void start(void)
Initialize.
Gecode toplevel namespace
I i
Iterator to compute complement for.
Range iterator for computing the complement (described by values)