Generated on Sat Feb 7 2015 02:01:25 for Gecode by doxygen 1.8.9.1
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: 2011-07-13 18:55:08 +0200 (Wed, 13 Jul 2011) $ by $Author: schulte $
11  * $Revision: 12194 $
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 
113 
114  /*
115  * Dimension with integer view size
116  *
117  */
122  : c0(c00), s(s0), c1(c10) {}
123 
124  forceinline int
125  FlexDim::ssc(void) const {
126  return c0.min();
127  }
128  forceinline int
129  FlexDim::lsc(void) const {
130  return c0.max();
131  }
132  forceinline int
133  FlexDim::sec(void) const {
134  return c1.min();
135  }
136  forceinline int
137  FlexDim::lec(void) const {
138  return c1.max();
139  }
140 
142  FlexDim::ssc(Space& home, int n) {
143  GECODE_ME_CHECK(c0.gq(home, n));
144  return ES_OK;
145  }
147  FlexDim::lec(Space& home, int n) {
148  GECODE_ME_CHECK(c1.lq(home, n));
149  return ES_OK;
150  }
152  FlexDim::nooverlap(Space& home, int n, int m) {
153  if (n <= m) {
154  Iter::Ranges::Singleton r0(n-s.min()+1,m);
155  GECODE_ME_CHECK(c0.minus_r(home,r0,false));
156  Iter::Ranges::Singleton r1(n+1,s.min()+m);
157  GECODE_ME_CHECK(c1.minus_r(home,r1,false));
158  }
159  return ES_OK;
160  }
163  if (d.sec() > lsc()) {
164  // Propagate that d must be after this
165  GECODE_ES_CHECK(lec(home,d.lsc()));
166  GECODE_ES_CHECK(d.ssc(home,sec()));
167  } else {
168  nooverlap(home, d.lsc(), d.sec()-1);
169  }
170  return ES_OK;
171  }
172 
173 
174  forceinline void
175  FlexDim::update(Space& home, bool share, FlexDim& d) {
176  c0.update(home,share,d.c0);
177  s.update(home,share,d.s);
178  c1.update(home,share,d.c1);
179  }
180 
181  forceinline void
183  c0.subscribe(home,p,PC_INT_DOM);
184  s.subscribe(home,p,PC_INT_BND);
185  c1.subscribe(home,p,PC_INT_DOM);
186  }
187  forceinline void
189  c0.cancel(home,p,PC_INT_DOM);
190  s.cancel(home,p,PC_INT_BND);
191  c1.cancel(home,p,PC_INT_DOM);
192  }
193 
194 }}}
195 
196 // STATISTICS: int-prop
197 
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to dimension.
Definition: dim.hpp:182
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:459
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to dimension.
Definition: dim.hpp:105
IntView c
Coordinate.
Definition: no-overlap.hh:56
Range iterator for singleton range.
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:755
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: int.hpp:185
int ssc(void) const
Return smallest start coordinate.
Definition: dim.hpp:125
Computation spaces.
Definition: core.hpp:1362
Gecode::IntSet d(v, 7)
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:84
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:453
int lsc(void) const
Return largest start coordinate.
Definition: dim.hpp:56
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:119
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
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
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:152
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
IntView c0
Start coordinate.
Definition: no-overlap.hh:98
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:494
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
Dimension combining coordinate and integer view size information.
Definition: no-overlap.hh:95
void update(Space &home, bool share, FlexDim &d)
Update dimension during cloning.
Definition: dim.hpp:175
IntView c1
End coordinate.
Definition: no-overlap.hh:102
Dimension combining coordinate and integer size information.
Definition: no-overlap.hh:53
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
ExecStatus
Definition: core.hpp:523
int lsc(void) const
Return largest start coordinate.
Definition: dim.hpp:129
#define forceinline
Definition: config.hpp:132
int ssc(void) const
Return smallest start coordinate.
Definition: dim.hpp:52
ExecStatus ssc(Space &home, int n)
Modify smallest start coordinate.
Definition: dim.hpp:142
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:527
Gecode toplevel namespace
int sec(void) const
Return smallest end coordinate.
Definition: dim.hpp:60
ExecStatus ssc(Space &home, int n)
Modify smallest start coordinate.
Definition: dim.hpp:69
int sec(void) const
Return smallest end coordinate.
Definition: dim.hpp:133
int lec(void) const
Return largest end coordinate.
Definition: dim.hpp:137
int lec(void) const
Return largest end coordinate.
Definition: dim.hpp:64
void cancel(Space &home, Propagator &p)
Cancel propagator p from dimension.
Definition: dim.hpp:188
void cancel(Space &home, Propagator &p)
Cancel propagator p from dimension.
Definition: dim.hpp:109