Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
partition.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 RelOp {
41
42 /*
43 * "Nary partition" propagator
44 *
45 */
46
47 template<class View0, class View1>
53
54 template<class View0, class View1>
57 const IntSet& z, View1 y)
58 : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
60 IntSetRanges rz(z);
61 unionOfDets.includeI(home, rz);
62 }
63
64 template<class View0, class View1>
71
72 template<class View0, class View1>
73 Actor*
75 return new (home) PartitionN(home,*this);
76 }
77
78 template<class View0, class View1>
80 View1 y) {
81 switch (x.size()) {
82 case 0:
83 GECODE_ME_CHECK(y.cardMax(home, 0));
84 return ES_OK;
85 case 1:
86 return Rel::Eq<View0,View1>::post(home, x[0], y);
87 default:
88 (void) new (home) PartitionN<View0,View1>(home,x,y);
89 return ES_OK;
90 }
91 }
92
93 template<class View0, class View1>
95 const IntSet& z, View1 y) {
96 (void) new (home) PartitionN<View0,View1>(home,x,z,y);
97 return ES_OK;
98 }
99
100 template<class View0, class View1>
102 return PropCost::quadratic(PropCost::LO, x.size()+1);
103 }
104
105 template<class View0, class View1>
108
109 ModEvent me0 = View0::me(med);
110 ModEvent me1 = View1::me(med);
111 bool ubevent = Rel::testSetEventUB(me0, me1);
112 bool lbevent = Rel::testSetEventLB(me0, me1);
113 bool anybevent = Rel::testSetEventAnyB(me0, me1);
114 bool cardevent = Rel::testSetEventCard(me0, me1);
115
116 bool modified = false;
117 bool oldModified = false;
118
119 do {
120 oldModified = modified;
121 modified = false;
122 if (oldModified || anybevent)
123 GECODE_ES_CHECK(partitionNXiUB(home,modified, x, y,unionOfDets));
124 if (modified || oldModified || anybevent)
125 GECODE_ES_CHECK(partitionNXiLB(home,modified, x, y,unionOfDets));
126 if (modified || oldModified || ubevent)
127 GECODE_ES_CHECK(partitionNYUB(home,modified, x, y,unionOfDets));
128 if (modified || oldModified || lbevent)
129 GECODE_ES_CHECK(partitionNYLB(home,modified, x, y,unionOfDets));
130 if (modified || oldModified || ubevent)
131 GECODE_ES_CHECK(unionNXiUB(home,modified, x, y,unionOfDets));
132 if (modified || oldModified || cardevent)
133 GECODE_ES_CHECK(partitionNCard(home,modified, x, y,unionOfDets));
134 } while (modified);
135
136 //removing assigned sets from x, accumulating the value:
137 for(int i=0;i<x.size();i++) {
138 //Do not reverse! Eats away the end of the array!
139 while (i<x.size() && x[i].assigned()) {
140 GlbRanges<View0> det(x[i]);
141 unionOfDets.includeI(home,det);
142 x.move_lst(i);
143 }
144 }
145 // When we run out of variables, make a final check and disolve:
146 if (x.size()==0) {
148 GECODE_ME_CHECK( y.intersectI(home,all1) );
150 GECODE_ME_CHECK( y.includeI(home,all2) );
151 unionOfDets.dispose(home);
152 return home.ES_SUBSUMED(*this);
153 }
154
155 return shared ? ES_NOFIX : ES_FIX;
156 }
157
158}}}
159
160// STATISTICS: set-prop
Base-class for both propagators and branchers.
Definition core.hpp:628
Home class for posting propagators
Definition core.hpp:856
Range iterator for integer sets.
Definition int.hh:292
Integer sets.
Definition int.hh:174
Propagation cost.
Definition core.hpp:486
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition core.hpp:4794
friend class Space
Definition core.hpp:1068
ModEventDelta med
A set of modification events (used during propagation)
Definition core.hpp:1077
Range iterator for integer sets.
Definition var-imp.hpp:185
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
bool shared
Whether the any views share a variable implementation.
Definition rel-op.hh:261
PartitionN(Space &home, PartitionN &p)
Constructor for cloning p.
Definition partition.hpp:66
GLBndSet unionOfDets
Union of the determined (which are dropped)
Definition rel-op.hh:263
static ExecStatus post(Home home, ViewArray< View0 > &y, View1 x)
Post propagator .
Definition partition.hpp:79
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition partition.hpp:74
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition eq.hpp:54
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_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
Standard set operation propagators.
Definition rel-op.hh:46
ExecStatus partitionNCard(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:308
ExecStatus partitionNYLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:560
ExecStatus partitionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:467
ExecStatus unionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &)
Definition common.hpp:294
ExecStatus partitionNXiLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:513
ExecStatus partitionNYUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition common.hpp:587
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:83
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:95
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:87
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition common.hpp:91
Finite integer sets.
Definition var-imp.hpp:137
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 viewarrayshared(const ViewArray< View0 > &va, const View1 &y)
Definition common.hpp:47
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
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_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1472
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:194