Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 namespace Gecode { namespace Int { namespace NoOverlap {
35 
36  /*
37  * Dimension with integer size
38  *
39  */
42  : s(0) {}
44  FixDim::FixDim(IntView c0, int s0)
45  : c(c0), s(s0) {}
46 
47  forceinline int
48  FixDim::ssc(void) const {
49  return c.min();
50  }
51  forceinline int
52  FixDim::lsc(void) const {
53  return c.max();
54  }
55  forceinline int
56  FixDim::sec(void) const {
57  return c.min() + s;
58  }
59  forceinline int
60  FixDim::lec(void) const {
61  return c.max() + s;
62  }
63 
65  FixDim::ssc(Space& home, int n) {
66  GECODE_ME_CHECK(c.gq(home, n));
67  return ES_OK;
68  }
70  FixDim::lec(Space& home, int n) {
71  GECODE_ME_CHECK(c.lq(home, n - s));
72  return ES_OK;
73  }
75  FixDim::nooverlap(Space& home, int n, int m) {
76  if (n <= m) {
78  GECODE_ME_CHECK(c.minus_r(home,r,false));
79  }
80  return ES_OK;
81  }
84  if (d.sec() > lsc()) {
85  // Propagate that d must be after this
86  GECODE_ES_CHECK(lec(home,d.lsc()));
87  GECODE_ES_CHECK(d.ssc(home,sec()));
88  } else {
89  nooverlap(home, d.lsc(), d.sec()-1);
90  }
91  return ES_OK;
92  }
93 
94  forceinline void
96  c.update(home,d.c);
97  s = d.s;
98  }
99 
100  forceinline void
102  c.subscribe(home,p,PC_INT_DOM);
103  }
104  forceinline void
106  c.cancel(home,p,PC_INT_DOM);
107  }
108  forceinline void
110  c.reschedule(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
176  c0.update(home,d.c0);
177  s.update(home,d.s);
178  c1.update(home,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  forceinline void
195  c0.reschedule(home,p,PC_INT_DOM);
196  s.reschedule(home,p,PC_INT_BND);
197  c1.reschedule(home,p,PC_INT_DOM);
198  }
199 
200 }}}
201 
202 // STATISTICS: int-prop
203 
int sec(void) const
Return smallest end coordinate.
Definition: dim.hpp:56
int s
Size.
Definition: no-overlap.hh:54
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
int lec(void) const
Return largest end coordinate.
Definition: dim.hpp:60
int lec(void) const
Return largest end coordinate.
Definition: dim.hpp:137
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition: dim.hpp:194
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:521
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:527
Computation spaces.
Definition: core.hpp:1742
void update(Space &home, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:567
void update(Space &home, FlexDim &d)
Update dimension during cloning.
Definition: dim.hpp:175
Dimension combining coordinate and integer size information.
Definition: no-overlap.hh:49
IntView c1
End coordinate.
Definition: no-overlap.hh:100
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to dimension.
Definition: dim.hpp:182
Gecode toplevel namespace
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
Base-class for propagators.
Definition: core.hpp:1064
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
IntView s
Size.
Definition: no-overlap.hh:98
Dimension combining coordinate and integer view size information.
Definition: no-overlap.hh:93
void update(Space &home, FixDim &d)
Update dimension during cloning.
Definition: dim.hpp:95
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
int lsc(void) const
Return largest start coordinate.
Definition: dim.hpp:52
int lsc(void) const
Return largest start coordinate.
Definition: dim.hpp:129
FixDim(void)
Default constructor.
Definition: dim.hpp:41
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:91
FlexDim(void)
Default constructor.
Definition: dim.hpp:119
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: view.hpp:532
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition: dim.hpp:109
int sec(void) const
Return smallest end coordinate.
Definition: dim.hpp:133
Gecode::IntSet d(v, 7)
IntView c
Coordinate.
Definition: no-overlap.hh:52
int ssc(void) const
Return smallest start coordinate.
Definition: dim.hpp:48
ExecStatus nooverlap(Space &home, int n, int m)
Dimension must not overlap with coordinates n to m.
Definition: dim.hpp:152
Integer view for integer variables.
Definition: view.hpp:129
void cancel(Space &home, Propagator &p)
Cancel propagator p from dimension.
Definition: dim.hpp:188
#define forceinline
Definition: config.hpp:185
Range iterator for singleton range.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:121
ExecStatus nooverlap(Space &home, int n, int m)
Dimension must not overlap with coordinates n to m.
Definition: dim.hpp:75
Gecode::FloatVal c(-8, 8)
int ssc(void) const
Return smallest start coordinate.
Definition: dim.hpp:125
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:139
void cancel(Space &home, Propagator &p)
Cancel propagator p from dimension.
Definition: dim.hpp:105
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: int.hpp:191
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
@ ES_OK
Execution is okay.
Definition: core.hpp:476
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
IntView c0
Start coordinate.
Definition: no-overlap.hh:96
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to dimension.
Definition: dim.hpp:101
ExecStatus
Definition: core.hpp:472