Generated on Mon Feb 8 2021 00:00:00 for Gecode by doxygen 1.8.20
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  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 namespace Gecode { namespace Set { namespace Rel {
41 
42  template<class View0, class View1>
45  : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>(home,x,y) {}
46 
47  template<class View0, class View1>
50  : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
51  (home,p) {}
52 
53  template<class View0, class View1>
55  Distinct<View0,View1>::post(Home home, View0 x, View1 y) {
56  if (same(x,y))
57  return ES_FAILED;
58  if (x.assigned()) {
59  GlbRanges<View0> xr(x);
60  IntSet xs(xr);
61  ConstSetView cv(home, xs);
63  }
64  if (y.assigned()) {
65  GlbRanges<View1> yr(y);
66  IntSet ys(yr);
67  ConstSetView cv(home, ys);
69  }
70  (void) new (home) Distinct<View0,View1>(home,x,y);
71  return ES_OK;
72  }
73 
74  template<class View0, class View1>
75  Actor*
77  return new (home) Distinct<View0,View1>(home,*this);
78  }
79 
80  template<class View0, class View1>
83  assert(x0.assigned()||x1.assigned());
84  if (x0.assigned()) {
85  GlbRanges<View0> xr(x0);
86  IntSet xs(xr);
87  ConstSetView cv(home, xs);
88  GECODE_REWRITE(*this,(DistinctDoit<View1>::post(home(*this),x1,cv)));
89  } else {
90  GlbRanges<View1> yr(x1);
91  IntSet ys(yr);
92  ConstSetView cv(home, ys);
93  GECODE_REWRITE(*this,(DistinctDoit<View0>::post(home(*this),x0,cv)));
94  }
95  }
96 
97  template<class View0>
100  (void) new (home) DistinctDoit<View0>(home,x,y);
101  return ES_OK;
102  }
103 
104  template<class View0>
105  Actor*
107  return new (home) DistinctDoit<View0>(home,*this);
108  }
109 
110  template<class View0>
111  ExecStatus
113  if (x0.assigned()) {
114  GlbRanges<View0> xi(x0);
116  if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
117  else { return home.ES_SUBSUMED(*this); }
118  }
119  assert(x0.lubSize()-x0.glbSize() >0);
120  if (x0.cardMin()>y.cardMax()) { return home.ES_SUBSUMED(*this); }
121  if (x0.cardMax()<y.cardMin()) { return home.ES_SUBSUMED(*this); }
122  //These tests are too expensive, we should only do them
123  //in the 1 unknown left case.
124  GlbRanges<View0> xi1(x0);
126  if (!Iter::Ranges::subset(xi1,yi1)) { return home.ES_SUBSUMED(*this); }
127  LubRanges<View0> xi2(x0);
129  if (!Iter::Ranges::subset(yi2,xi2)) { return home.ES_SUBSUMED(*this); }
130  // from here, we know y\subseteq lub(x) and glb(x)\subseteq y
131 
132  if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
133  GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
134  return home.ES_SUBSUMED(*this);
135  }
136  if (x0.glbSize() == y.cardMin()) {
137  GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
138  return home.ES_SUBSUMED(*this);
139  }
140  return ES_FIX;
141  }
142 
143  template<class View0>
146  : UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y) {}
147 
148  template<class View0>
151  : UnaryPropagator<View0, PC_SET_ANY>(home,p) {
152  y.update(home,p.y);
153  }
154 
155 }}}
156 
157 // STATISTICS: set-prop
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Range iterator for greatest lower bound of constant set view
Definition: const.hpp:664
Constant view.
Definition: view.hpp:186
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
Distinct(Space &home, Distinct &p)
Constructor for cloning p.
Definition: nq.hpp:49
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: nq.hpp:106
unsigned int cardMin(void) const
Return cardinality minimum.
Definition: set.hpp:78
Computation spaces.
Definition: core.hpp:1742
Base-class for both propagators and branchers.
Definition: core.hpp:628
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: nq.hpp:76
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:111
Gecode toplevel namespace
Mixed binary propagator.
Definition: pattern.hpp:204
Integer sets.
Definition: int.hh:174
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: nq.hpp:112
Home class for posting propagators
Definition: core.hpp:856
bool same(VX, VY)
Test whether two views are in fact the same.
Definition: common.hpp:57
ConstSetView y
The view that is already assigned.
Definition: rel.hh:300
unsigned int cardMax(void) const
Return cardinality maximum.
Definition: set.hpp:81
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:359
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
void update(Space &home, ConstSetView &y)
Update this view to be a clone of view y.
Definition: const.hpp:217
DistinctDoit(Space &home, DistinctDoit &)
Constructor for cloning p.
Definition: nq.hpp:150
Propagator for negated equality
Definition: rel.hh:268
Propagator for negated equality
Definition: rel.hh:296
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:477
Range iterator for the least upper bound.
Definition: var-imp.hpp:317
Range iterator for least upper bound of constant set view
Definition: const.hpp:624
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition: nq.hpp:55
#define forceinline
Definition: config.hpp:192
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: nq.hpp:82
Unary propagator.
Definition: pattern.hpp:55
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
@ ES_FAILED
Execution has resulted in failure.
Definition: core.hpp:474
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:116
@ ES_OK
Execution is okay.
Definition: core.hpp:476
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
static ExecStatus post(Home home, View0 x, ConstSetView y)
Post propagator .
Definition: nq.hpp:99
ExecStatus
Definition: core.hpp:472
const Gecode::PropCond PC_SET_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:207