Generated on Wed Jan 24 2018 21:22:26 for Gecode by doxygen 1.8.13
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: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15137 $
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  template<class Dim, int n>
142  forceinline void
144  for (int i=0; i<n; i++)
145  d[i].reschedule(home,p);
146  }
147 
148 
149  /*
150  * Optional boxes
151  *
152  */
153  template<class Dim, int n>
154  forceinline void
156  o = o0;
157  }
158  template<class Dim, int n>
159  forceinline bool
161  return o.one();
162  }
163  template<class Dim, int n>
164  forceinline bool
166  return o.zero();
167  }
168  template<class Dim, int n>
169  forceinline bool
171  return o.none();
172  }
173 
174  template<class Dim, int n>
177  GECODE_ME_CHECK(o.zero(home));
178  return ES_OK;
179  }
180 
181  template<class Dim, int n>
182  forceinline void
184  ManBox<Dim,n>::update(home, share, b);
185  o.update(home, share, b.o);
186  }
187 
188  template<class Dim, int n>
189  forceinline void
191  ManBox<Dim,n>::subscribe(home,p);
192  o.subscribe(home, p, PC_BOOL_VAL);
193  }
194  template<class Dim, int n>
195  forceinline void
197  ManBox<Dim,n>::cancel(home,p);
198  o.cancel(home, p, PC_BOOL_VAL);
199  }
200  template<class Dim, int n>
201  forceinline void
204  o.reschedule(home, p, PC_BOOL_VAL);
205  }
206 
207 }}}
208 
209 // STATISTICS: int-prop
210 
bool excluded(void) const
Whether box is excluded.
Definition: box.hpp:69
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
bool mandatory(void) const
Whether box is mandatory.
Definition: box.hpp:160
Base-class for propagators.
Definition: core.hpp:1092
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:196
bool nooverlap(const ManBox< Dim, n > &b) const
Check whether this box does not any longer overlap with b.
Definition: box.hpp:86
Optional box class.
Definition: no-overlap.hh:195
bool overlap(const ManBox< Dim, n > &b) const
Check whether this box overlaps with b.
Definition: box.hpp:95
Computation spaces.
Definition: core.hpp:1748
Gecode::IntSet d(v, 7)
bool mandatory(void) const
Whether box is mandatory.
Definition: box.hpp:64
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition: box.hpp:143
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:542
bool excluded(void) const
Whether box is excluded.
Definition: box.hpp:165
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to box.
Definition: box.hpp:190
ExecStatus exclude(Space &home)
Exclude box.
Definition: box.hpp:176
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition: box.hpp:202
ExecStatus
Definition: core.hpp:540
bool optional(void) const
Whether box is optional.
Definition: box.hpp:74
#define forceinline
Definition: config.hpp:173
void update(Space &home, bool share, OptBox< Dim, n > &r)
Update box during cloning.
Definition: box.hpp:183
const Dim & operator[](int i) const
Access to dimension i.
Definition: box.hpp:46
Execution is okay.
Definition: core.hpp:544
BoolView o
Whether box is optional or not.
Definition: no-overlap.hh:199
Gecode toplevel namespace
Mandatory box class.
Definition: no-overlap.hh:150
bool optional(void) const
Whether box is optional.
Definition: box.hpp:170
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
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
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