Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
40namespace 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>
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()) {
60 IntSet xs(xr);
61 ConstSetView cv(home, xs);
63 }
64 if (y.assigned()) {
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()) {
86 IntSet xs(xr);
87 ConstSetView cv(home, xs);
88 GECODE_REWRITE(*this,(DistinctDoit<View1>::post(home(*this),x1,cv)));
89 } else {
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>
113 if (x0.assigned()) {
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
Base-class for both propagators and branchers.
Definition core.hpp:628
Home class for posting propagators
Definition core.hpp:856
Integer sets.
Definition int.hh:174
friend class Space
Definition core.hpp:1068
Constant view.
Definition view.hpp:186
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
Range iterator for the least upper bound.
Definition var-imp.hpp:317
DistinctDoit(Space &home, DistinctDoit &)
Constructor for cloning p.
Definition nq.hpp:150
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition nq.hpp:106
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition nq.hpp:112
static ExecStatus post(Home home, View0 x, ConstSetView y)
Post propagator .
Definition nq.hpp:99
ConstSetView y
The view that is already assigned.
Definition rel.hh:300
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:76
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition nq.hpp:55
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition nq.hpp:82
UnaryPropagator(Space &home, UnaryPropagator &p)
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3570
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Standard set relation propagators.
Definition rel.hh:45
Finite integer sets.
Definition var-imp.hpp:137
const Gecode::PropCond PC_SET_VAL
Propagate when a view becomes assigned (single value)
Definition var-type.hpp:207
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition var-type.hpp:248
Gecode toplevel namespace
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1943
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
Post propagator for SetVar x
Definition set.hh:773
#define forceinline
Definition config.hpp:194