Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
box.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, 2011
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Int { namespace NoOverlap {
35
36 /*
37 * Mandatory boxes
38 *
39 */
40 template<class Dim, int n>
41 forceinline const Dim&
43 assert((i >= 0) && (i < n));
44 return d[i];
45 }
46 template<class Dim, int n>
47 forceinline Dim&
49 assert((i >= 0) && (i < n));
50 return d[i];
51 }
52 template<class Dim, int n>
53 forceinline int
55 return n;
56 }
57
58 template<class Dim, int n>
59 forceinline bool
61 return true;
62 }
63 template<class Dim, int n>
64 forceinline bool
66 return false;
67 }
68 template<class Dim, int n>
69 forceinline bool
71 return false;
72 }
73
74 template<class Dim, int n>
79
80 template<class Dim, int n>
81 forceinline bool
83 for (int i=0; i<n; i++)
84 if ((d[i].lec() <= box.d[i].ssc()) || (box.d[i].lec() <= d[i].ssc()))
85 return true;
86 return false;
87 }
88
89 template<class Dim, int n>
90 forceinline bool
92 for (int i=0; i<n; i++)
93 if ((d[i].sec() <= box.d[i].lsc()) || (box.d[i].sec() <= d[i].lsc()))
94 return false;
95 return true;
96 }
97
98 template<class Dim, int n>
101 for (int i=0; i<n; i++)
102 if ((d[i].sec() <= box.d[i].lsc()) ||
103 (box.d[i].sec() <= d[i].lsc())) {
104 // Does not overlap for dimension i
105 for (int j=i+1; j<n; j++)
106 if ((d[j].sec() <= box.d[j].lsc()) ||
107 (box.d[j].sec() <= d[j].lsc()))
108 return ES_OK;
109 // Does not overlap for only dimension i, hence propagate
110 d[i].nooverlap(home, box.d[i]);
111 box.d[i].nooverlap(home, d[i]);
112 return ES_OK;
113 }
114 // Overlaps in all dimensions
115 return ES_FAILED;
116 }
117
118 template<class Dim, int n>
119 forceinline void
121 for (int i=0; i<n; i++)
122 d[i].update(home,b.d[i]);
123 }
124
125 template<class Dim, int n>
126 forceinline void
128 for (int i=0; i<n; i++)
129 d[i].subscribe(home,p);
130 }
131 template<class Dim, int n>
132 forceinline void
134 for (int i=0; i<n; i++)
135 d[i].cancel(home,p);
136 }
137 template<class Dim, int n>
138 forceinline void
140 for (int i=0; i<n; i++)
141 d[i].reschedule(home,p);
142 }
143
144
145 /*
146 * Optional boxes
147 *
148 */
149 template<class Dim, int n>
150 forceinline void
152 o = o0;
153 }
154 template<class Dim, int n>
155 forceinline bool
157 return o.one();
158 }
159 template<class Dim, int n>
160 forceinline bool
162 return o.zero();
163 }
164 template<class Dim, int n>
165 forceinline bool
167 return o.none();
168 }
169
170 template<class Dim, int n>
173 GECODE_ME_CHECK(o.zero(home));
174 return ES_OK;
175 }
176
177 template<class Dim, int n>
178 forceinline void
181 o.update(home, b.o);
182 }
183
184 template<class Dim, int n>
185 forceinline void
188 o.subscribe(home, p, PC_BOOL_VAL);
189 }
190 template<class Dim, int n>
191 forceinline void
194 o.cancel(home, p, PC_BOOL_VAL);
195 }
196 template<class Dim, int n>
197 forceinline void
200 o.reschedule(home, p, PC_BOOL_VAL);
201 }
202
203}}}
204
205// STATISTICS: int-prop
206
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
Boolean view for Boolean variables.
Definition view.hpp:1380
bool one(void) const
Test whether view is assigned to be one.
Definition bool.hpp:224
static int dim(void)
Return number of dimensions.
Definition box.hpp:54
bool nooverlap(const ManBox< Dim, n > &b) const
Check whether this box does not any longer overlap with b.
Definition box.hpp:82
const Dim & operator[](int i) const
Access to dimension i.
Definition box.hpp:42
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition box.hpp:139
void update(Space &home, ManBox< Dim, n > &r)
Update box during cloning.
Definition box.hpp:120
bool overlap(const ManBox< Dim, n > &b) const
Check whether this box overlaps with b.
Definition box.hpp:91
bool excluded(void) const
Whether box is excluded.
Definition box.hpp:65
bool mandatory(void) const
Whether box is mandatory.
Definition box.hpp:60
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to box.
Definition box.hpp:127
bool optional(void) const
Whether box is optional.
Definition box.hpp:70
ExecStatus exclude(Space &home)
Exclude box.
Definition box.hpp:76
void cancel(Space &home, Propagator &p)
Cancel propagator p from box.
Definition box.hpp:133
void update(Space &home, OptBox< Dim, n > &r)
Update box during cloning.
Definition box.hpp:179
bool optional(void) const
Whether box is optional.
Definition box.hpp:166
bool mandatory(void) const
Whether box is mandatory.
Definition box.hpp:156
ExecStatus exclude(Space &home)
Exclude box.
Definition box.hpp:172
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition box.hpp:198
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to box.
Definition box.hpp:186
void cancel(Space &home, Propagator &p)
Cancel propagator p from box.
Definition box.hpp:192
bool excluded(void) const
Whether box is excluded.
Definition box.hpp:161
Base-class for propagators.
Definition core.hpp:1064
Computation spaces.
Definition core.hpp:1742
void update(const NoOffset &)
Integer-precision integer scale view.
Definition view.hpp:638
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition var-type.hpp:126
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
#define forceinline
Definition config.hpp:187