Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
re-prop.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2011
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <gecode/int/rel.hh>
35
36namespace Gecode { namespace Int { namespace Member {
37
38 template<class View, ReifyMode rm>
41 BoolView b0)
42 : Prop<View>(home,vs,x,y), b(b0) {
43 b.subscribe(home,*this,PC_BOOL_VAL);
44 }
45
46 template<class View, ReifyMode rm>
47 inline ExecStatus
49 if (x.size() == 0) {
50 if (rm != RM_PMI)
51 GECODE_ME_CHECK(b.zero(home));
52 return ES_OK;
53 }
54
55 x.unique();
56
57 if (x.size() == 1)
59
60 if (x.same(y)) {
61 if (rm != RM_IMP)
62 GECODE_ME_CHECK(b.one(home));
63 return ES_OK;
64 }
65
66 // Eliminate assigned views and store them into the value set
67 ValSet vs;
68 add(home, vs, x);
69
70 switch (vs.compare(y)) {
72 if (rm != RM_IMP)
73 GECODE_ME_CHECK(b.one(home));
74 return ES_OK;
76 if (x.size() == 0) {
77 if (rm != RM_PMI)
78 GECODE_ME_CHECK(b.zero(home));
79 return ES_OK;
80 }
81 break;
83 break;
84 default:
86 }
87
88 (void) new (home) ReProp<View,rm>(home, vs, x, y, b);
89 return ES_OK;
90 }
91
92 template<class View, ReifyMode rm>
95 : Prop<View>(home, p) {
96 b.update(home, p.b);
97 }
98
99 template<class View, ReifyMode rm>
102 return new (home) ReProp<View,rm>(home, *this);
103 }
104
105 template<class View, ReifyMode rm>
106 forceinline size_t
108 b.cancel(home, *this, PC_BOOL_VAL);
109 (void) Prop<View>::dispose(home);
110 return sizeof(*this);
111 }
112
113 template<class View, ReifyMode rm>
116 // Add assigned views to value set
117 if (View::me(med) == ME_INT_VAL)
118 add(home,vs,x);
119
120 if (b.one()) {
121 if (rm == RM_PMI)
122 return home.ES_SUBSUMED(*this);
123 ValSet vsc(vs);
124 vs.flush();
125 GECODE_REWRITE(*this,Prop<View>::post(home(*this),vsc,x,y));
126 }
127
128 if (b.zero()) {
129 if (rm != RM_IMP) {
130 ValSet::Ranges vsr(vs);
131 GECODE_ME_CHECK(y.minus_r(home,vsr,false));
132 for (int i=0; i<x.size(); i++)
134 }
135 return home.ES_SUBSUMED(*this);
136 }
137
138 // Eliminate views from x
139 eliminate(home);
140
141 switch (vs.compare(y)) {
143 if (rm != RM_IMP)
144 GECODE_ME_CHECK(b.one(home));
145 return home.ES_SUBSUMED(*this);
147 if (x.size() == 0) {
148 if (rm != RM_PMI)
149 GECODE_ME_CHECK(b.zero(home));
150 return home.ES_SUBSUMED(*this);
151 }
152 break;
154 break;
155 default:
157 }
158
159 // Check whether y is in union of x and value set
160 if (x.size() > 0) {
161 Region r;
162
163 ValSet::Ranges vsr(vs);
164 ViewRanges<View> xsr(x[0]);
165 Iter::Ranges::NaryUnion u(r,vsr,xsr);
166 for (int i=1; i<x.size(); i++) {
167 ViewRanges<View> xir(x[i]);
168 u |= xir;
169 }
170
172
173 if (Iter::Ranges::disjoint(u,yr)) {
174 if (rm != RM_PMI)
175 GECODE_ME_CHECK(b.zero(home));
176 return home.ES_SUBSUMED(*this);
177 }
178 }
179
180 return ES_FIX;
181 }
182
183}}}
184
185// STATISTICS: int-prop
Home class for posting propagators
Definition core.hpp:856
Boolean view for Boolean variables.
Definition view.hpp:1380
static void add(Space &home, ValSet &vs, ViewArray< View > &x)
Add values of assigned views in x to value set va.
Definition prop.hpp:46
Prop(Home home, ValSet &vs, ViewArray< View > &x, View y)
Constructor for posting.
Definition prop.hpp:40
ValSet vs
Value set storing the values of already assigned views.
Definition member.hh:59
void eliminate(Space &home)
Eliminate views from x that are not equal to y or ar subsumed by vs.
Definition prop.hpp:58
static ExecStatus post(Home home, ViewArray< View > &x, View y)
Post propagator for .
Definition prop.hpp:71
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition prop.hpp:119
virtual Propagator * copy(Space &home)
Copy propagator during cloning.
Definition re-prop.hpp:101
ReProp(Home home, ValSet &vs, ViewArray< View > &x, View y, BoolView b)
Constructor for posting.
Definition re-prop.hpp:40
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition re-prop.hpp:115
BoolView b
Boolean control variable.
Definition member.hh:98
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition re-prop.hpp:107
static ExecStatus post(Home home, ViewArray< View > &x, View y, BoolView b)
Post propagator for .
Definition re-prop.hpp:48
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition nq.hpp:49
static ExecStatus post(Home home, View x0, View x1, CtrlView b)
Post domain consistent propagator .
Definition eq.hpp:494
Iterator over ranges.
Definition val-set.hh:78
Class for storing values of already assigned views.
Definition val-set.hh:44
Range iterator for integer views.
Definition view.hpp:54
Range iterator for union of iterators.
Base-class for propagators.
Definition core.hpp:1066
friend class Space
Definition core.hpp:1068
ModEventDelta med
A set of modification events (used during propagation)
Definition core.hpp:1077
Handle to region.
Definition region.hpp:55
View arrays.
Definition array.hpp:253
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
@ RM_IMP
Implication for reification.
Definition int.hh:877
@ RM_PMI
Inverse implication for reification.
Definition int.hh:884
Membership propagators.
Finite domain integers.
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition var-type.hpp:126
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition var-type.hpp:56
@ CS_NONE
Neither of the above.
@ CS_SUBSET
First is subset of second iterator.
@ CS_DISJOINT
Intersection is empty.
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
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
#define forceinline
Definition config.hpp:194
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56