this repo has no description
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 */
49 forceinline
50 NegBoolView::NegBoolView(void) {}
51 forceinline
52 NegBoolView::NegBoolView(const BoolView& y)
53 : DerivedView<BoolView>(y) {}
54
55
56 /*
57 * Boolean domain tests
58 *
59 */
60 forceinline BoolStatus
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 */
82 forceinline ModEvent
83 NegBoolView::zero_none(Space& home) {
84 return x.one_none(home);
85 }
86 forceinline ModEvent
87 NegBoolView::one_none(Space& home) {
88 return x.zero_none(home);
89 }
90
91 forceinline ModEvent
92 NegBoolView::zero(Space& home) {
93 return x.one(home);
94 }
95 forceinline ModEvent
96 NegBoolView::one(Space& home) {
97 return x.zero(home);
98 }
99
100 /* Domain update by value
101 *
102 */
103
104 forceinline ModEvent
105 NegBoolView::lq(Space& home, int n) {
106 return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
107 }
108 forceinline ModEvent
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 }
112 forceinline ModEvent
113 NegBoolView::le(Space& home, int n) {
114 return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
115 }
116 forceinline ModEvent
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 }
120 forceinline ModEvent
121 NegBoolView::gq(Space& home, int n) {
122 return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
123 }
124 forceinline ModEvent
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 }
128 forceinline ModEvent
129 NegBoolView::gr(Space& home, int n) {
130 return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
131 }
132 forceinline ModEvent
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 }
136 forceinline ModEvent
137 NegBoolView::nq(Space& home, int n) {
138 return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
139 }
140 forceinline ModEvent
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 }
144 forceinline ModEvent
145 NegBoolView::eq(Space& home, int n) {
146 return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
147 }
148 forceinline ModEvent
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
198 NegBoolView::zero(const Delta& d) {
199 return BoolView::one(d);
200 }
201 forceinline bool
202 NegBoolView::one(const Delta& d) {
203 return BoolView::zero(d);
204 }
205
206 /*
207 * View comparison
208 *
209 */
210 forceinline bool
211 operator ==(const NegBoolView& x, const NegBoolView& y) {
212 return x.base() == y.base();
213 }
214 forceinline bool
215 operator !=(const NegBoolView& x, const NegBoolView& y) {
216 return !(x == y);
217 }
218
219
220 /**
221 * \brief %Range iterator for negated Boolean variable views
222 * \ingroup TaskActorIntView
223 */
224 template<>
225 class ViewRanges<NegBoolView> : public Iter::Ranges::Singleton {
226 public:
227 /// \name Constructors and initialization
228 //@{
229 /// Default constructor
230 ViewRanges(void);
231 /// Initialize with ranges for view \a x
232 ViewRanges(const NegBoolView& x);
233 /// Initialize with ranges for view \a x
234 void init(const NegBoolView& x);
235 //@}
236 };
237
238 forceinline
239 ViewRanges<NegBoolView>::ViewRanges(void) {}
240
241 forceinline
242 ViewRanges<NegBoolView>::ViewRanges(const NegBoolView& x)
243 : Iter::Ranges::Singleton(x.min(),x.max()) {}
244
245 forceinline void
246 ViewRanges<NegBoolView>::init(const NegBoolView& x) {
247 Iter::Ranges::Singleton::init(x.min(),x.max());
248 }
249
250}}
251
252// STATISTICS: int-var