Generated on Thu Jul 25 2019 00:00:00 for Gecode by doxygen 1.8.15
bool.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2004
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 #include <gecode/int.hh>
39 
40 namespace Gecode { namespace Set { namespace Channel {
41 
42  template<class View>
43  template<class A>
47  Council<A>& c, int index)
48  : Advisor(home,p,c), idx(index) {
49  if (idx == -1)
50  p.y.subscribe(home,*this);
51  else {
52  p.x[idx].subscribe(home,*this);
53  }
54  }
55 
56  template<class View>
59  IndexAdvisor& a)
60  : Advisor(home,share,a), idx(a.idx) {}
61 
62  template<class View>
63  forceinline int
65  return idx;
66  }
67 
68  template<class View>
69  template<class A>
70  forceinline void
72  ChannelBool<View>& p = static_cast<ChannelBool<View>&>(propagator());
73  if (idx == -1)
74  p.y.cancel(home,*this);
75  else {
76  p.x[idx].cancel(home,*this);
77  }
78  Advisor::dispose(home,c);
79  }
80 
81  template<class View>
85  View y0)
86  : Super(home,x0,y0), co(home), running(false) {
87  bool assigned = false;
88  for (int i=x.size(); i--;) {
89  if (x[i].zero()) {
90  assigned = true;
91  SetDelta d;
92  zeros.include(home, i, i, d);
93  } else if (x[i].one()) {
94  assigned = true;
95  SetDelta d;
96  ones.include(home, i, i, d);
97  } else {
98  (void) new (home) IndexAdvisor(home,*this,co,i);
99  }
100  }
101  if (assigned)
103  View::schedule(home, *this, y.assigned() ? ME_SET_VAL : ME_SET_BB);
104  if (y.assigned()) {
105  if (y.glbSize()==static_cast<unsigned int>(y.glbMax()-y.glbMin()+1)) {
106  new (&delta) SetDelta(y.glbMin(),y.glbMax(),1,0);
107  } else {
108  new (&delta) SetDelta(2,0,1,0);
109  }
110  }
111  (void) new (home) IndexAdvisor(home,*this,co,-1);
112  }
113 
114  template<class View>
117  : Super(home,share,p), running(false) {
118  co.update(home, share, p.co);
119  }
120 
121  template<class View>
124  View y) {
125  GECODE_ME_CHECK(y.intersect(home, 0, x.size()-1));
126  (void) new (home) ChannelBool(home,x,y);
127  return ES_OK;
128  }
129 
130  template<class View>
131  PropCost
133  return PropCost::quadratic(PropCost::LO, x.size()+1);
134  }
135 
136  template<class View>
137  void
139  x.reschedule(home,*this,Gecode::Int::PC_BOOL_VAL);
140  View::schedule(home, *this, y.assigned() ? ME_SET_VAL : ME_SET_BB);
141  }
142 
143  template<class View>
144  forceinline size_t
146  co.dispose(home);
147  (void) Super::dispose(home);
148  return sizeof(*this);
149  }
150 
151  template<class View>
152  Actor*
153  ChannelBool<View>::copy(Space& home, bool share) {
154  return new (home) ChannelBool(home,share,*this);
155  }
156 
157  template<class View>
158  ExecStatus
160  running = true;
161  if (zeros.size() > 0) {
162  BndSetRanges zi(zeros);
163  GECODE_ME_CHECK(y.excludeI(home, zi));
164  zeros.init(home);
165  }
166  if (ones.size() > 0) {
167  BndSetRanges oi(ones);
168  GECODE_ME_CHECK(y.includeI(home, oi));
169  ones.init(home);
170  }
171  running = false;
172 
173  if (delta.glbMin() != 1 || delta.glbMax() != 0) {
174  if (!delta.glbAny()) {
175  for (int i=delta.glbMin(); i<=delta.glbMax(); i++)
176  GECODE_ME_CHECK(x[i].one(home));
177  } else {
178  GlbRanges<View> glb(y);
179  for (Iter::Ranges::ToValues<GlbRanges<View> > gv(glb); gv(); ++gv) {
180  GECODE_ME_CHECK(x[gv.val()].one(home));
181  }
182  }
183  }
184  if (delta.lubMin() != 1 || delta.lubMax() != 0) {
185  if (!delta.lubAny()) {
186  for (int i=delta.lubMin(); i<=delta.lubMax(); i++)
187  GECODE_ME_CHECK(x[i].zero(home));
188  } else {
189  int cur = 0;
190  for (LubRanges<View> lub(y); lub(); ++lub) {
191  for (; cur < lub.min(); cur++) {
192  GECODE_ME_CHECK(x[cur].zero(home));
193  }
194  cur = lub.max() + 1;
195  }
196  for (; cur < x.size(); cur++) {
197  GECODE_ME_CHECK(x[cur].zero(home));
198  }
199  }
200  }
201 
202  new (&delta) SetDelta();
203 
204  return y.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
205  }
206 
207  template<class View>
208  ExecStatus
210  IndexAdvisor& a = static_cast<IndexAdvisor&>(_a);
211  const SetDelta& d = static_cast<const SetDelta&>(_d);
212 
213  ModEvent me = View::modevent(d);
214  int index = a.index();
215  if ( (running && index == -1 && me != ME_SET_VAL)
216  || (index == -1 && me == ME_SET_CARD) ) {
217  return ES_OK;
218  }
219 
220  if (index >= 0) {
221  if (x[index].zero()) {
222  SetDelta dummy;
223  zeros.include(home, index, index, dummy);
224  } else {
225  assert(x[index].one());
226  SetDelta dummy;
227  ones.include(home, index, index, dummy);
228  }
229  return home.ES_NOFIX_DISPOSE( co, a);
230  }
231 
232  if ((a.index() == -1) && Rel::testSetEventLB(me)) {
233  if (d.glbAny()) {
234  new (&delta)
235  SetDelta(2,0, delta.lubMin(), delta.lubMax());
236  } else {
237  if (delta.glbMin() == 1 && delta.glbMax() == 0) {
238  new (&delta)
239  SetDelta(d.glbMin(), d.glbMax(),
240  delta.lubMin(), delta.lubMax());
241  } else {
242  if (delta.glbMin() != 2 || delta.glbMax() != 0) {
243  if ((delta.glbMin() <= d.glbMin() && delta.glbMax() >= d.glbMin())
244  ||
245  (delta.glbMin() <= d.glbMax() && delta.glbMax() >= d.glbMax())
246  ) {
247  new (&delta)
248  SetDelta(std::min(delta.glbMin(), d.glbMin()),
249  std::max(delta.glbMax(), d.glbMax()),
250  delta.lubMin(), delta.lubMax());
251  } else {
252  new (&delta)
253  SetDelta(2, 0, delta.lubMin(), delta.lubMax());
254  }
255  }
256  }
257  }
258  }
259  if ((a.index() == -1) && Rel::testSetEventUB(me)) {
260  if (d.lubAny()) {
261  new (&delta)
262  SetDelta(delta.glbMin(), delta.glbMax(), 2,0);
263  } else {
264  if (delta.lubMin() == 1 && delta.lubMax() == 0) {
265  new (&delta)
266  SetDelta(delta.glbMin(), delta.glbMax(),
267  d.lubMin(), d.lubMax());
268  } else {
269  if (delta.lubMin() != 2 || delta.lubMax() != 0) {
270  if ((delta.lubMin() <= d.lubMin() && delta.lubMax() >= d.lubMin())
271  ||
272  (delta.lubMin() <= d.lubMax() && delta.lubMax() >= d.lubMax())
273  ) {
274  new (&delta)
275  SetDelta(delta.lubMin(), delta.lubMax(),
276  std::min(delta.lubMin(), d.lubMin()),
277  std::max(delta.lubMax(), d.lubMax())
278  );
279  } else {
280  new (&delta)
281  SetDelta(delta.glbMin(), delta.glbMax(), 2, 0);
282  }
283  }
284  }
285  }
286  }
287  if (y.assigned())
288  return home.ES_NOFIX_DISPOSE( co, a);
289  else
290  return ES_NOFIX;
291  }
292 
293 }}}
294 
295 // STATISTICS: set-prop
Council of advisors
Definition: core.hpp:232
bool running
Flag whether propagation is currently running.
Definition: channel.hh:197
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4832
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition: linear.cpp:50
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:123
const Gecode::ModEvent ME_SET_BB
Domain operation has changed both greatest lower and least upper bound.
Definition: var-type.hpp:172
int ModEvent
Type for modification events.
Definition: core.hpp:142
Council< IndexAdvisor > co
Council for managing advisors.
Definition: channel.hh:189
void dispose(Space &home, Council< A > &c)
Delete advisor.
Definition: bool.hpp:71
Base-class for advisors.
Definition: core.hpp:1294
GLBndSet zeros
Accumulated zero Booleans.
Definition: channel.hh:193
ExecStatus ES_NOFIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed and its propagator must be run
Definition: core.hpp:3938
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_LO)
Definition: bool.hpp:132
static ExecStatus post(Home home, ViewArray< Gecode::Int::BoolView > &x, View y)
Post propagator for .
Definition: bool.hpp:123
Propagation has computed fixpoint.
Definition: core.hpp:545
Computation spaces.
Definition: core.hpp:1748
Base-class for both propagators and branchers.
Definition: core.hpp:696
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: bool.hpp:159
Gecode::IntSet d(v, 7)
IndexAdvisor(Space &home, ChannelBool< View > &p, Council< A > &c, int index)
Constructor for creation.
Definition: bool.hpp:45
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::FloatVal c(-8, 8)
Single _a(2, 3)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Gecode::IntArgs i(4, 1, 2, 3, 4)
Multi _d(Gecode::IntArgs(3, 3, 2, 1))
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: bool.hpp:145
Value iterator from range iterator.
Range iterator for integer sets.
Definition: var-imp.hpp:189
Advisor storing a single index
Definition: channel.hh:170
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Give advice to propagator.
Definition: bool.hpp:209
virtual void reschedule(Space &home)
Schedule function.
Definition: bool.hpp:138
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:75
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
Generic domain change information to be supplied to advisors.
Definition: core.hpp:281
int index(void) const
Access index.
Definition: bool.hpp:64
void dispose(Space &home, Council< A > &c)
Dispose the advisor.
Definition: core.hpp:3915
Propagation cost.
Definition: core.hpp:554
ExecStatus
Definition: core.hpp:540
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: bool.hpp:153
#define forceinline
Definition: config.hpp:173
Post propagator for SetVar x
Definition: set.hh:784
Execution is okay.
Definition: core.hpp:544
Propagation has not computed fixpoint.
Definition: core.hpp:543
GLBndSet ones
Accumulated one Booleans.
Definition: channel.hh:195
Propagator for channelling between set variable and its characteristic function
Definition: channel.hh:152
Gecode toplevel namespace
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition: view.hpp:509
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:79
SetDelta delta
Accumulated delta information.
Definition: channel.hh:191
const Gecode::ModEvent ME_SET_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:142
const Gecode::ModEvent ME_SET_CARD
Domain operation has changed the variable cardinality.
Definition: var-type.hpp:148
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
Home class for posting propagators
Definition: core.hpp:922
ChannelBool(Space &home, bool share, ChannelBool &p)
Constructor for cloning p.
Definition: bool.hpp:116
bool include(Space &home, int i, int j, SetDelta &d)
Include the set in this set.
Definition: integerset.hpp:283
void dummy(Space &)
A dummy function for branching.
Definition: nogoods.cpp:55
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126
const Gecode::ModEvent ME_BOOL_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:116
Finite set delta information for advisors.
Definition: var-imp.hpp:56