Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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$ by $Author$
17  * $Revision$
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>
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,p) {}
56 
57  template<class View0, class View1>
59  Distinct<View0,View1>::post(Home home, View0 x, View1 y) {
60  if (same(x,y))
61  return ES_FAILED;
62  if (x.assigned()) {
63  GlbRanges<View0> xr(x);
64  IntSet xs(xr);
65  ConstSetView cv(home, xs);
67  }
68  if (y.assigned()) {
69  GlbRanges<View1> yr(y);
70  IntSet ys(yr);
71  ConstSetView cv(home, ys);
73  }
74  (void) new (home) Distinct<View0,View1>(home,x,y);
75  return ES_OK;
76  }
77 
78  template<class View0, class View1>
79  Actor*
81  return new (home) Distinct<View0,View1>(home,*this);
82  }
83 
84  template<class View0, class View1>
87  assert(x0.assigned()||x1.assigned());
88  if (x0.assigned()) {
89  GlbRanges<View0> xr(x0);
90  IntSet xs(xr);
91  ConstSetView cv(home, xs);
92  GECODE_REWRITE(*this,(DistinctDoit<View1>::post(home(*this),x1,cv)));
93  } else {
94  GlbRanges<View1> yr(x1);
95  IntSet ys(yr);
96  ConstSetView cv(home, ys);
97  GECODE_REWRITE(*this,(DistinctDoit<View0>::post(home(*this),x0,cv)));
98  }
99  }
100 
101  template<class View0>
102  ExecStatus
104  (void) new (home) DistinctDoit<View0>(home,x,y);
105  return ES_OK;
106  }
107 
108  template<class View0>
109  Actor*
111  return new (home) DistinctDoit<View0>(home,*this);
112  }
113 
114  template<class View0>
115  ExecStatus
117  if (x0.assigned()) {
118  GlbRanges<View0> xi(x0);
120  if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
121  else { return home.ES_SUBSUMED(*this); }
122  }
123  assert(x0.lubSize()-x0.glbSize() >0);
124  if (x0.cardMin()>y.cardMax()) { return home.ES_SUBSUMED(*this); }
125  if (x0.cardMax()<y.cardMin()) { return home.ES_SUBSUMED(*this); }
126  //These tests are too expensive, we should only do them
127  //in the 1 unknown left case.
128  GlbRanges<View0> xi1(x0);
130  if (!Iter::Ranges::subset(xi1,yi1)) { return home.ES_SUBSUMED(*this); }
131  LubRanges<View0> xi2(x0);
133  if (!Iter::Ranges::subset(yi2,xi2)) { return home.ES_SUBSUMED(*this); }
134  // from here, we know y\subseteq lub(x) and glb(x)\subseteq y
135 
136  if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
137  GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
138  return home.ES_SUBSUMED(*this);
139  }
140  if (x0.glbSize() == y.cardMin()) {
141  GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
142  return home.ES_SUBSUMED(*this);
143  }
144  return ES_FIX;
145  }
146 
147  template<class View0>
150  : UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y) {}
151 
152  template<class View0>
155  : UnaryPropagator<View0, PC_SET_ANY>(home,p) {
156  y.update(home,p.y);
157  }
158 
159 }}}
160 
161 // STATISTICS: set-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
Range iterator for greatest lower bound of constant set view
Definition: const.hpp:668
Propagator for negated equality
Definition: rel.hh:271
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3433
Distinct(Space &home, Distinct &p)
Constructor for cloning p.
Definition: nq.hpp:53
Unary propagator.
Definition: pattern.hpp:59
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: nq.hpp:116
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
#define forceinline
Definition: config.hpp:182
Propagation has computed fixpoint.
Definition: core.hpp:469
Computation spaces.
Definition: core.hpp:1668
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
Base-class for both propagators and branchers.
Definition: core.hpp:620
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: nq.hpp:110
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:95
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: nq.hpp:80
Execution has resulted in failure.
Definition: core.hpp:466
unsigned int cardMin(void) const
Return cardinality minimum.
Definition: set.hpp:82
bool same(VX, VY)
Test whether two views are in fact the same.
Definition: common.hpp:61
Integer sets.
Definition: int.hh:174
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
void update(Space &home, ConstSetView &y)
Update this view to be a clone of view y.
Definition: const.hpp:221
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
Constant view.
Definition: view.hpp:190
Mixed binary propagator.
Definition: pattern.hpp:208
static ExecStatus post(Home home, View0 x, ConstSetView y)
Post propagator .
Definition: nq.hpp:103
ExecStatus
Definition: core.hpp:464
ConstSetView y
The view that is already assigned.
Definition: rel.hh:304
Propagator for negated equality
Definition: rel.hh:300
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: nq.hpp:86
unsigned int cardMax(void) const
Return cardinality maximum.
Definition: set.hpp:85
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
DistinctDoit(Space &home, DistinctDoit &)
Constructor for cloning p.
Definition: nq.hpp:154
int ModEventDelta
Modification event deltas.
Definition: core.hpp:91
Home class for posting propagators
Definition: core.hpp:846
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition: nq.hpp:59