Generated on Thu Feb 14 2013 20:59:35 for Gecode by doxygen 1.8.3.1
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  * Last modified:
10  * $Date: 2011-07-14 02:16:57 +1000 (Thu, 14 Jul 2011) $ by $Author: schulte $
11  * $Revision: 12192 $
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 
38 namespace Gecode { namespace Int { namespace NoOverlap {
39 
40  /*
41  * Mandatory boxes
42  *
43  */
44  template<class Dim, int n>
45  forceinline const Dim&
47  assert((i >= 0) && (i < n));
48  return d[i];
49  }
50  template<class Dim, int n>
51  forceinline Dim&
53  assert((i >= 0) && (i < n));
54  return d[i];
55  }
56  template<class Dim, int n>
57  forceinline int
59  return n;
60  }
61 
62  template<class Dim, int n>
63  forceinline bool
65  return true;
66  }
67  template<class Dim, int n>
68  forceinline bool
70  return false;
71  }
72  template<class Dim, int n>
73  forceinline bool
75  return false;
76  }
77 
78  template<class Dim, int n>
81  return ES_FAILED;
82  }
83 
84  template<class Dim, int n>
85  forceinline bool
87  for (int i=0; i<n; i++)
88  if ((d[i].lec() <= box.d[i].ssc()) || (box.d[i].lec() <= d[i].ssc()))
89  return true;
90  return false;
91  }
92 
93  template<class Dim, int n>
94  forceinline bool
96  for (int i=0; i<n; i++)
97  if ((d[i].sec() <= box.d[i].lsc()) || (box.d[i].sec() <= d[i].lsc()))
98  return false;
99  return true;
100  }
101 
102  template<class Dim, int n>
105  for (int i=0; i<n; i++)
106  if ((d[i].sec() <= box.d[i].lsc()) ||
107  (box.d[i].sec() <= d[i].lsc())) {
108  // Does not overlap for dimension i
109  for (int j=i+1; j<n; j++)
110  if ((d[j].sec() <= box.d[j].lsc()) ||
111  (box.d[j].sec() <= d[j].lsc()))
112  return ES_OK;
113  // Does not overlap for only dimension i, hence propagate
114  d[i].nooverlap(home, box.d[i]);
115  box.d[i].nooverlap(home, d[i]);
116  return ES_OK;
117  }
118  // Overlaps in all dimensions
119  return ES_FAILED;
120  }
121 
122  template<class Dim, int n>
123  forceinline void
125  for (int i=0; i<n; i++)
126  d[i].update(home,share,b.d[i]);
127  }
128 
129  template<class Dim, int n>
130  forceinline void
132  for (int i=0; i<n; i++)
133  d[i].subscribe(home,p);
134  }
135  template<class Dim, int n>
136  forceinline void
138  for (int i=0; i<n; i++)
139  d[i].cancel(home,p);
140  }
141 
142 
143  /*
144  * Optional boxes
145  *
146  */
147  template<class Dim, int n>
148  forceinline void
150  o = o0;
151  }
152  template<class Dim, int n>
153  forceinline bool
155  return o.one();
156  }
157  template<class Dim, int n>
158  forceinline bool
160  return o.zero();
161  }
162  template<class Dim, int n>
163  forceinline bool
165  return o.none();
166  }
167 
168  template<class Dim, int n>
171  GECODE_ME_CHECK(o.zero(home));
172  return ES_OK;
173  }
174 
175  template<class Dim, int n>
176  forceinline void
178  ManBox<Dim,n>::update(home, share, b);
179  o.update(home, share, b.o);
180  }
181 
182  template<class Dim, int n>
183  forceinline void
185  ManBox<Dim,n>::subscribe(home,p);
186  o.subscribe(home, p, PC_BOOL_VAL);
187  }
188  template<class Dim, int n>
189  forceinline void
191  ManBox<Dim,n>::cancel(home,p);
192  o.cancel(home, p, PC_BOOL_VAL);
193  }
194 
195 }}}
196 
197 // STATISTICS: int-prop
198