Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
values-bitsetoffset.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  * Converted into offset version:
10  * Christopher Mears <chris.mears@monash.edu>
11  *
12  * Last modified:
13  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
14  * $Revision: 14967 $
15  *
16  * This file is part of Gecode, the generic constraint
17  * development environment:
18  * http://www.gecode.org
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  *
39  */
40 
41 namespace Gecode { namespace Iter { namespace Values {
42 
48  template<class BS>
49  class BitSetOffset {
50  protected:
52  const BS& bs;
54  int cur;
56  int limit;
58  void move(void);
59  public:
61 
62  BitSetOffset(const BS& bs);
65  BitSetOffset(const BS& bs, int n, int m);
67 
69 
70  bool operator ()(void) const;
73  void operator ++(void);
75 
77 
78  int val(void) const;
81  };
82 
83 
84  template<class BS>
87  : bs(bs0), cur(bs.next(bs0.offset())), limit(bs.offset()+bs.size()) {
88  }
89 
90  template<class BS>
92  BitSetOffset<BS>::BitSetOffset(const BS& bs0, int n, int m)
93  : bs(bs0),
94  cur(bs.next(n)),
95  limit(std::min(bs.offset()+bs.size(),m+1)) {
96  }
97 
98  template<class BS>
99  forceinline void
101  cur=bs.next(cur+1);
102  }
103  template<class BS>
104  forceinline bool
106  return cur < limit;
107  }
108 
109  template<class BS>
110  forceinline int
111  BitSetOffset<BS>::val(void) const {
112  return static_cast<int>(cur);
113  }
114 
115 }}}
116 
117 // STATISTICS: iter-any
int cur
Current value.
#define forceinline
Definition: config.hpp:173
const BS & bs
Bitset.
unsigned int size(I &i)
Size of all ranges of range iterator i.
int limit
Limit value.
int val(void) const
Return current value.
Gecode toplevel namespace
Value iterator for values in an offset bitset.
BitSetOffset(const BS &bs)
Initialize with bitset bs.
void operator++(void)
Move iterator to next value (if possible)
void move(void)
Move to next set bit.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:71
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
bool operator()(void) const
Test whether iterator is still at a value or done.