Generated on Sat Feb 7 2015 02:01:17 for Gecode by doxygen 1.8.9.1
nq.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  * Christian Schulte <schulte@gecode.org>
6  *
7  * Contributing authors:
8  * Gabor Szokoli <szokoli@gecode.org>
9  *
10  * Copyright:
11  * Guido Tack, 2004
12  * Christian Schulte, 2004
13  * Gabor Szokoli, 2004
14  *
15  * Last modified:
16  * $Date: 2010-06-07 14:18:14 +0200 (Mon, 07 Jun 2010) $ by $Author: tack $
17  * $Revision: 11048 $
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 namespace Gecode { namespace Set { namespace Rel {
45 
46  template<class View0, class View1>
48  Distinct<View0,View1>::Distinct(Home home, View0 x, View1 y)
49  : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>(home,x,y) {}
50 
51  template<class View0, class View1>
54  : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
55  (home,share,p) {}
56 
57  template<class View0, class View1>
59  Distinct<View0,View1>::post(Home home, View0 x, View1 y) {
60  if (x.assigned()) {
61  GlbRanges<View0> xr(x);
62  IntSet xs(xr);
63  ConstSetView cv(home, xs);
65  }
66  if (y.assigned()) {
67  GlbRanges<View1> yr(y);
68  IntSet ys(yr);
69  ConstSetView cv(home, ys);
71  }
72  (void) new (home) Distinct<View0,View1>(home,x,y);
73  return ES_OK;
74  }
75 
76  template<class View0, class View1>
77  Actor*
78  Distinct<View0,View1>::copy(Space& home, bool share) {
79  return new (home) Distinct<View0,View1>(home,share,*this);
80  }
81 
82  template<class View0, class View1>
85  assert(x0.assigned()||x1.assigned());
86  if (x0.assigned()) {
87  GlbRanges<View0> xr(x0);
88  IntSet xs(xr);
89  ConstSetView cv(home, xs);
90  GECODE_REWRITE(*this,(DistinctDoit<View1>::post(home(*this),x1,cv)));
91  } else {
92  GlbRanges<View1> yr(x1);
93  IntSet ys(yr);
94  ConstSetView cv(home, ys);
95  GECODE_REWRITE(*this,(DistinctDoit<View0>::post(home(*this),x0,cv)));
96  }
97  }
98 
99  template<class View0>
100  ExecStatus
102  (void) new (home) DistinctDoit<View0>(home,x,y);
103  return ES_OK;
104  }
105 
106  template<class View0>
107  Actor*
108  DistinctDoit<View0>::copy(Space& home, bool share) {
109  return new (home) DistinctDoit<View0>(home,share,*this);
110  }
111 
112  template<class View0>
113  ExecStatus
115  if (x0.assigned()) {
116  GlbRanges<View0> xi(x0);
118  if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
119  else { return home.ES_SUBSUMED(*this); }
120  }
121  assert(x0.lubSize()-x0.glbSize() >0);
122  if (x0.cardMin()>y.cardMax()) { return home.ES_SUBSUMED(*this); }
123  if (x0.cardMax()<y.cardMin()) { return home.ES_SUBSUMED(*this); }
124  //These tests are too expensive, we should only do them
125  //in the 1 unknown left case.
126  GlbRanges<View0> xi1(x0);
128  if (!Iter::Ranges::subset(xi1,yi1)){ return home.ES_SUBSUMED(*this); }
129  LubRanges<View0> xi2(x0);
131  if (!Iter::Ranges::subset(yi2,xi2)){ return home.ES_SUBSUMED(*this); }
132  // from here, we know y\subseteq lub(x) and glb(x)\subseteq y
133 
134  if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
135  GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
136  return home.ES_SUBSUMED(*this);
137  }
138  if (x0.glbSize() == y.cardMin()) {
139  GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
140  return home.ES_SUBSUMED(*this);
141  }
142  return ES_FIX;
143  }
144 
145  template<class View0>
148  : UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y) {}
149 
150  template<class View0>
154  : UnaryPropagator<View0, PC_SET_ANY>(home,share,p) {
155  y.update(home,share,p.y);
156  }
157 
158 }}}
159 
160 // STATISTICS: set-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
Range iterator for greatest lower bound of constant set view
Definition: const.hpp:668
Propagator for negated equality
Definition: rel.hh:261
void update(Space &home, bool share, ConstSetView &y)
Update this view to be a clone of view y.
Definition: const.hpp:221
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
Unary propagator.
Definition: propagator.hpp:59
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: nq.hpp:114
Range iterator for least upper bound of constant set view
Definition: const.hpp:628
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
Base-class for both propagators and branchers.
Definition: core.hpp:666
DistinctDoit(Space &home, bool share, DistinctDoit &)
Constructor for cloning p.
Definition: nq.hpp:152
Distinct(Space &home, bool share, Distinct &p)
Constructor for cloning p.
Definition: nq.hpp:53
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:84
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Execution has resulted in failure.
Definition: core.hpp:525
Integer sets.
Definition: int.hh:171
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: nq.hpp:108
Constant view.
Definition: view.hpp:190
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Mixed binary propagator.
Definition: propagator.hpp:203
ExecStatus
Definition: core.hpp:523
static ExecStatus post(Home home, View0, ConstSetView)
Post propagator .
Definition: nq.hpp:101
ConstSetView y
The view that is already assigned.
Definition: rel.hh:294
#define forceinline
Definition: config.hpp:132
Propagator for negated equality
Definition: rel.hh:290
Execution is okay.
Definition: core.hpp:527
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: nq.hpp:78
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: nq.hpp:84
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Gecode toplevel namespace
const Gecode::PropCond PC_SET_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:207
static ExecStatus post(Home home, View0, View1)
Post propagator .
Definition: nq.hpp:59
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717