Generated on Thu Jul 25 2019 00:00:00 for Gecode by doxygen 1.8.15
dim.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  * Dimension with integer size
42  *
43  */
46  : s(0) {}
48  FixDim::FixDim(IntView c0, int s0)
49  : c(c0), s(s0) {}
50 
51  forceinline int
52  FixDim::ssc(void) const {
53  return c.min();
54  }
55  forceinline int
56  FixDim::lsc(void) const {
57  return c.max();
58  }
59  forceinline int
60  FixDim::sec(void) const {
61  return c.min() + s;
62  }
63  forceinline int
64  FixDim::lec(void) const {
65  return c.max() + s;
66  }
67 
69  FixDim::ssc(Space& home, int n) {
70  GECODE_ME_CHECK(c.gq(home, n));
71  return ES_OK;
72  }
74  FixDim::lec(Space& home, int n) {
75  GECODE_ME_CHECK(c.lq(home, n - s));
76  return ES_OK;
77  }
79  FixDim::nooverlap(Space& home, int n, int m) {
80  if (n <= m) {
82  GECODE_ME_CHECK(c.minus_r(home,r,false));
83  }
84  return ES_OK;
85  }
88  if (d.sec() > lsc()) {
89  // Propagate that d must be after this
90  GECODE_ES_CHECK(lec(home,d.lsc()));
91  GECODE_ES_CHECK(d.ssc(home,sec()));
92  } else {
93  nooverlap(home, d.lsc(), d.sec()-1);
94  }
95  return ES_OK;
96  }
97 
98  forceinline void
99  FixDim::update(Space& home, bool share, FixDim& d) {
100  c.update(home,share,d.c);
101  s = d.s;
102  }
103 
104  forceinline void
106  c.subscribe(home,p,PC_INT_DOM);
107  }
108  forceinline void
110  c.cancel(home,p,PC_INT_DOM);
111  }
112  forceinline void
114  c.reschedule(home,p,PC_INT_DOM);
115  }
116 
117 
118  /*
119  * Dimension with integer view size
120  *
121  */
126  : c0(c00), s(s0), c1(c10) {}
127 
128  forceinline int
129  FlexDim::ssc(void) const {
130  return c0.min();
131  }
132  forceinline int
133  FlexDim::lsc(void) const {
134  return c0.max();
135  }
136  forceinline int
137  FlexDim::sec(void) const {
138  return c1.min();
139  }
140  forceinline int
141  FlexDim::lec(void) const {
142  return c1.max();
143  }
144 
146  FlexDim::ssc(Space& home, int n) {
147  GECODE_ME_CHECK(c0.gq(home, n));
148  return ES_OK;
149  }
151  FlexDim::lec(Space& home, int n) {
152  GECODE_ME_CHECK(c1.lq(home, n));
153  return ES_OK;
154  }
156  FlexDim::nooverlap(Space& home, int n, int m) {
157  if (n <= m) {
158  Iter::Ranges::Singleton r0(n-s.min()+1,m);
159  GECODE_ME_CHECK(c0.minus_r(home,r0,false));
160  Iter::Ranges::Singleton r1(n+1,s.min()+m);
161  GECODE_ME_CHECK(c1.minus_r(home,r1,false));
162  }
163  return ES_OK;
164  }
167  if (d.sec() > lsc()) {
168  // Propagate that d must be after this
169  GECODE_ES_CHECK(lec(home,d.lsc()));
170  GECODE_ES_CHECK(d.ssc(home,sec()));
171  } else {
172  nooverlap(home, d.lsc(), d.sec()-1);
173  }
174  return ES_OK;
175  }
176 
177 
178  forceinline void
179  FlexDim::update(Space& home, bool share, FlexDim& d) {
180  c0.update(home,share,d.c0);
181  s.update(home,share,d.s);
182  c1.update(home,share,d.c1);
183  }
184 
185  forceinline void
187  c0.subscribe(home,p,PC_INT_DOM);
188  s.subscribe(home,p,PC_INT_BND);
189  c1.subscribe(home,p,PC_INT_DOM);
190  }
191  forceinline void
193  c0.cancel(home,p,PC_INT_DOM);
194  s.cancel(home,p,PC_INT_BND);
195  c1.cancel(home,p,PC_INT_DOM);
196  }
197  forceinline void
199  c0.reschedule(home,p,PC_INT_DOM);
200  s.reschedule(home,p,PC_INT_BND);
201  c1.reschedule(home,p,PC_INT_DOM);
202  }
203 
204 }}}
205 
206 // STATISTICS: int-prop
207 
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to dimension.
Definition: dim.hpp:186
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:489
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to dimension.
Definition: dim.hpp:105
Range iterator for singleton range.
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition: dim.hpp:198
int ssc(void) const
Return smallest start coordinate.
Definition: dim.hpp:52
ExecStatus nooverlap(Space &home, int n, int m)
Dimension must not overlap with coordinates n to m.
Definition: dim.hpp:79
Base-class for propagators.
Definition: core.hpp:1092
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: view.hpp:494
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: int.hpp:185
Computation spaces.
Definition: core.hpp:1748
Gecode::IntSet d(v, 7)
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:95
Gecode::FloatVal c(-8, 8)
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:483
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
FlexDim(void)
Default constructor.
Definition: dim.hpp:123
FixDim(void)
Default constructor.
Definition: dim.hpp:45
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:115
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:91
ExecStatus nooverlap(Space &home, int n, int m)
Dimension must not overlap with coordinates n to m.
Definition: dim.hpp:156
int lec(void) const
Return largest end coordinate.
Definition: dim.hpp:64
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
IntView c0
Start coordinate.
Definition: no-overlap.hh:100
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:529
int sec(void) const
Return smallest end coordinate.
Definition: dim.hpp:137
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
Dimension combining coordinate and integer view size information.
Definition: no-overlap.hh:97
void update(Space &home, bool share, FlexDim &d)
Update dimension during cloning.
Definition: dim.hpp:179
IntView c1
End coordinate.
Definition: no-overlap.hh:104
Dimension combining coordinate and integer size information.
Definition: no-overlap.hh:53
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
Integer view for integer variables.
Definition: view.hpp:129
void update(Space &home, bool share, FixDim &d)
Update dimension during cloning.
Definition: dim.hpp:99
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition: dim.hpp:113
ExecStatus
Definition: core.hpp:540
#define forceinline
Definition: config.hpp:173
int lsc(void) const
Return largest start coordinate.
Definition: dim.hpp:56
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:133
Execution is okay.
Definition: core.hpp:544
int sec(void) const
Return smallest end coordinate.
Definition: dim.hpp:60
Gecode toplevel namespace
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
int lec(void) const
Return largest end coordinate.
Definition: dim.hpp:141
int lsc(void) const
Return largest start coordinate.
Definition: dim.hpp:133
int ssc(void) const
Return smallest start coordinate.
Definition: dim.hpp:129
void cancel(Space &home, Propagator &p)
Cancel propagator p from dimension.
Definition: dim.hpp:192
void cancel(Space &home, Propagator &p)
Cancel propagator p from dimension.
Definition: dim.hpp:109