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 * 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&
42 ManBox<Dim,n>::operator [](int i) const {
43 assert((i >= 0) && (i < n));
44 return d[i];
45 }
46 template<class Dim, int n>
47 forceinline Dim&
48 ManBox<Dim,n>::operator [](int i) {
49 assert((i >= 0) && (i < n));
50 return d[i];
51 }
52 template<class Dim, int n>
53 forceinline int
54 ManBox<Dim,n>::dim(void) {
55 return n;
56 }
57
58 template<class Dim, int n>
59 forceinline bool
60 ManBox<Dim,n>::mandatory(void) const {
61 return true;
62 }
63 template<class Dim, int n>
64 forceinline bool
65 ManBox<Dim,n>::excluded(void) const {
66 return false;
67 }
68 template<class Dim, int n>
69 forceinline bool
70 ManBox<Dim,n>::optional(void) const {
71 return false;
72 }
73
74 template<class Dim, int n>
75 forceinline ExecStatus
76 ManBox<Dim,n>::exclude(Space&) {
77 return ES_FAILED;
78 }
79
80 template<class Dim, int n>
81 forceinline bool
82 ManBox<Dim,n>::nooverlap(const ManBox<Dim,n>& box) const {
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
91 ManBox<Dim,n>::overlap(const ManBox<Dim,n>& box) const {
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>
99 forceinline ExecStatus
100 ManBox<Dim,n>::nooverlap(Space& home, ManBox<Dim,n>& box) {
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
120 ManBox<Dim,n>::update(Space& home, ManBox<Dim,n>& b) {
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
127 ManBox<Dim,n>::subscribe(Space& home, Propagator& p) {
128 for (int i=0; i<n; i++)
129 d[i].subscribe(home,p);
130 }
131 template<class Dim, int n>
132 forceinline void
133 ManBox<Dim,n>::cancel(Space& home, Propagator& p) {
134 for (int i=0; i<n; i++)
135 d[i].cancel(home,p);
136 }
137 template<class Dim, int n>
138 forceinline void
139 ManBox<Dim,n>::reschedule(Space& home, Propagator& p) {
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
151 OptBox<Dim,n>::optional(BoolView o0) {
152 o = o0;
153 }
154 template<class Dim, int n>
155 forceinline bool
156 OptBox<Dim,n>::mandatory(void) const {
157 return o.one();
158 }
159 template<class Dim, int n>
160 forceinline bool
161 OptBox<Dim,n>::excluded(void) const {
162 return o.zero();
163 }
164 template<class Dim, int n>
165 forceinline bool
166 OptBox<Dim,n>::optional(void) const {
167 return o.none();
168 }
169
170 template<class Dim, int n>
171 forceinline ExecStatus
172 OptBox<Dim,n>::exclude(Space& home) {
173 GECODE_ME_CHECK(o.zero(home));
174 return ES_OK;
175 }
176
177 template<class Dim, int n>
178 forceinline void
179 OptBox<Dim,n>::update(Space& home, OptBox<Dim,n>& b) {
180 ManBox<Dim,n>::update(home, b);
181 o.update(home, b.o);
182 }
183
184 template<class Dim, int n>
185 forceinline void
186 OptBox<Dim,n>::subscribe(Space& home, Propagator& p) {
187 ManBox<Dim,n>::subscribe(home,p);
188 o.subscribe(home, p, PC_BOOL_VAL);
189 }
190 template<class Dim, int n>
191 forceinline void
192 OptBox<Dim,n>::cancel(Space& home, Propagator& p) {
193 ManBox<Dim,n>::cancel(home,p);
194 o.cancel(home, p, PC_BOOL_VAL);
195 }
196 template<class Dim, int n>
197 forceinline void
198 OptBox<Dim,n>::reschedule(Space& home, Propagator& p) {
199 ManBox<Dim,n>::reschedule(home,p);
200 o.reschedule(home, p, PC_BOOL_VAL);
201 }
202
203}}}
204
205// STATISTICS: int-prop
206