Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
neg-bool.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 * Contributing authors:
7 * Samuel Gagnon <samuel.gagnon92@gmail.com>
8 *
9 * Copyright:
10 * Christian Schulte, 2008
11 * Samuel Gagnon, 2018
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
38namespace Gecode { namespace Int {
39
40 /*
41 * Negated Boolean views
42 *
43 */
44
45 /*
46 * Constructors and initialization
47 *
48 */
54
55
56 /*
57 * Boolean domain tests
58 *
59 */
61 NegBoolView::status(void) const {
62 return x.status();
63 }
64 forceinline bool
65 NegBoolView::zero(void) const {
66 return x.one();
67 }
68 forceinline bool
69 NegBoolView::one(void) const {
70 return x.zero();
71 }
72 forceinline bool
73 NegBoolView::none(void) const {
74 return x.none();
75 }
76
77
78 /*
79 * Boolean assignment operations
80 *
81 */
84 return x.one_none(home);
85 }
88 return x.zero_none(home);
89 }
90
93 return x.one(home);
94 }
97 return x.zero(home);
98 }
99
100 /* Domain update by value
101 *
102 */
103
105 NegBoolView::lq(Space& home, int n) {
106 return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
107 }
109 NegBoolView::lq(Space& home, long long int n) {
110 return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
111 }
113 NegBoolView::le(Space& home, int n) {
114 return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
115 }
117 NegBoolView::le(Space& home, long long int n) {
118 return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
119 }
121 NegBoolView::gq(Space& home, int n) {
122 return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
123 }
125 NegBoolView::gq(Space& home, long long int n) {
126 return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
127 }
129 NegBoolView::gr(Space& home, int n) {
130 return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
131 }
133 NegBoolView::gr(Space& home, long long int n) {
134 return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
135 }
137 NegBoolView::nq(Space& home, int n) {
138 return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
139 }
141 NegBoolView::nq(Space& home, long long int n) {
142 return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
143 }
145 NegBoolView::eq(Space& home, int n) {
146 return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
147 }
149 NegBoolView::eq(Space& home, long long int n) {
150 return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
151 }
152
153 /*
154 * Value access
155 *
156 */
157 forceinline int
158 NegBoolView::min(void) const {
159 return 1-x.max();
160 }
161 forceinline int
162 NegBoolView::max(void) const {
163 return 1-x.min();
164 }
165 forceinline int
166 NegBoolView::val(void) const {
167 return 1-x.val();
168 }
169#ifdef GECODE_HAS_CBS
170 forceinline int
171 NegBoolView::baseval(int val) const {
172 return 1-val;
173 }
174#endif
175
176
177 /*
178 * Delta information for advisors
179 *
180 */
181 forceinline int
182 NegBoolView::min(const Delta& d) const {
183 return x.max(d);
184 }
185 forceinline int
186 NegBoolView::max(const Delta& d) const {
187 return x.min(d);
188 }
189 forceinline unsigned int
190 NegBoolView::width(const Delta& d) const {
191 return x.width(d);
192 }
193 forceinline bool
194 NegBoolView::any(const Delta& d) const {
195 return x.any(d);
196 }
197 forceinline bool
199 return BoolView::one(d);
200 }
201 forceinline bool
203 return BoolView::zero(d);
204 }
205
206 /*
207 * View comparison
208 *
209 */
210 forceinline bool
212 return x.base() == y.base();
213 }
214 forceinline bool
216 return !(x == y);
217 }
218
219
224 template<>
226 public:
228
229
230 ViewRanges(void);
232 ViewRanges(const NegBoolView& x);
234 void init(const NegBoolView& x);
236 };
237
240
244
245 forceinline void
249
250}}
251
252// STATISTICS: int-var
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Boolean view for Boolean variables.
Definition view.hpp:1380
bool zero(void) const
Test whether view is assigned to be zero.
Definition bool.hpp:220
bool one(void) const
Test whether view is assigned to be one.
Definition bool.hpp:224
Negated Boolean view.
Definition view.hpp:1574
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition neg-bool.hpp:129
BoolStatus status(void) const
Return current domain status.
Definition neg-bool.hpp:61
bool zero(void) const
Test whether view is assigned to be zero.
Definition neg-bool.hpp:65
bool one(void) const
Test whether view is assigned to be one.
Definition neg-bool.hpp:69
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition neg-bool.hpp:121
bool none(void) const
Test whether view is not yet assigned.
Definition neg-bool.hpp:73
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition neg-bool.hpp:113
unsigned int width(const Delta &d) const
Return width of values just pruned.
Definition neg-bool.hpp:190
ModEvent one_none(Space &home)
Assign not yet assigned view to one.
Definition neg-bool.hpp:87
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition neg-bool.hpp:194
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition neg-bool.hpp:105
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition neg-bool.hpp:137
int max(void) const
Return maximum of domain.
Definition neg-bool.hpp:162
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition neg-bool.hpp:145
int min(void) const
Return minimum of domain.
Definition neg-bool.hpp:158
ModEvent zero_none(Space &home)
Assign not yet assigned view to zero.
Definition neg-bool.hpp:83
NegBoolView(void)
Default constructor.
Definition neg-bool.hpp:50
int val(void) const
Return assigned value (only if assigned)
Definition neg-bool.hpp:166
ViewRanges(void)
Default constructor.
Definition neg-bool.hpp:239
void init(const View &x)
Initialize with ranges for view x.
ViewRanges(void)
Default constructor.
Range iterator for singleton range.
void init(int min, int max)
Initialize with range min to max.
Singleton(void)
Default constructor.
Computation spaces.
Definition core.hpp:1744
Finite domain integers.
const Gecode::ModEvent ME_BOOL_NONE
Domain operation has not changed domain.
Definition var-type.hpp:114
const Gecode::ModEvent ME_BOOL_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:112
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:401
unsigned int BoolStatus
Type for status of a Boolean variable.
Definition var-imp.hpp:484
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:406
Range and value iterators.
Definition iter.hh:41
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
Post propagator for SetVar x
Definition set.hh:773
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:194