Generated on Sat Feb 7 2015 02:01:25 for Gecode by doxygen 1.8.9.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-13 18:16:57 +0200 (Wed, 13 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 
bool mandatory(void) const
Whether box is mandatory.
Definition: box.hpp:64
const Dim & operator[](int i) const
Access to dimension i.
Definition: box.hpp:46
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:84
bool overlap(const ManBox< Dim, n > &b) const
Check whether this box overlaps with b.
Definition: box.hpp:95
Base-class for propagators.
Definition: core.hpp:755
bool excluded(void) const
Whether box is excluded.
Definition: box.hpp:69
static int dim(void)
Return number of dimensions.
Definition: box.hpp:58
void cancel(Space &home, Propagator &p)
Cancel propagator p from box.
Definition: box.hpp:190
Optional box class.
Definition: no-overlap.hh:189
Computation spaces.
Definition: core.hpp:1362
Gecode::IntSet d(v, 7)
bool optional(void) const
Whether box is optional.
Definition: box.hpp:74
void update(Space &home, bool share, ManBox< Dim, n > &r)
Update box during cloning.
Definition: box.hpp:124
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to box.
Definition: box.hpp:131
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Execution has resulted in failure.
Definition: core.hpp:525
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:74
bool optional(void) const
Whether box is optional.
Definition: box.hpp:164
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to box.
Definition: box.hpp:184
ExecStatus exclude(Space &home)
Exclude box.
Definition: box.hpp:170
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
void update(Space &home, bool share, OptBox< Dim, n > &r)
Update box during cloning.
Definition: box.hpp:177
Execution is okay.
Definition: core.hpp:527
bool nooverlap(const ManBox< Dim, n > &b) const
Check whether this box does not any longer overlap with b.
Definition: box.hpp:86
BoolView o
Whether box is optional or not.
Definition: no-overlap.hh:193
bool excluded(void) const
Whether box is excluded.
Definition: box.hpp:159
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Mandatory box class.
Definition: no-overlap.hh:146
ExecStatus exclude(Space &home)
Exclude box.
Definition: box.hpp:80
void cancel(Space &home, Propagator &p)
Cancel propagator p from box.
Definition: box.hpp:137
bool mandatory(void) const
Whether box is mandatory.
Definition: box.hpp:154
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126
Boolean view for Boolean variables.
Definition: view.hpp:1315