Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
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 
40 namespace Gecode { namespace Set { namespace RelOp {
41 
42  /*
43  * "Nary partition" propagator
44  *
45  */
46 
47  template<class View0, class View1>
50  : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
52  }
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>
67  : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,p),
68  shared(p.shared) {
69  unionOfDets.update(home,p.unionOfDets);
70  }
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>
106  ExecStatus
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) {
147  BndSetRanges all1(unionOfDets);
148  GECODE_ME_CHECK( y.intersectI(home,all1) );
149  BndSetRanges all2(unionOfDets);
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
View1 y
Single view.
Definition: pattern.hpp:277
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
ExecStatus partitionNXiLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:513
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
bool includeI(Space &home, I &i)
Include the set represented by i in this set.
Definition: integerset.hpp:296
ExecStatus partitionNCard(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:308
ViewArray< View0 > x
Array of views.
Definition: pattern.hpp:275
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
@ LO
Cheap.
Definition: core.hpp:513
bool shared(View0 v0, View1 v1, View2 v2)
Definition: common.hpp:84
bool viewarrayshared(const ViewArray< View0 > &va, const View1 &y)
Definition: common.hpp:47
Computation spaces.
Definition: core.hpp:1742
Base-class for both propagators and branchers.
Definition: core.hpp:628
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4787
ExecStatus partitionNYUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:587
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:111
Mixed (n+1)-ary propagator.
Definition: pattern.hpp:272
Range iterator for integer sets.
Definition: int.hh:292
bool shared
Whether the any views share a variable implementation.
Definition: rel-op.hh:261
Propagator for nary partition
Definition: rel-op.hh:256
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:95
Gecode toplevel namespace
static ExecStatus post(Home home, ViewArray< View0 > &y, View1 x)
Post propagator .
Definition: partition.hpp:79
Integer sets.
Definition: int.hh:174
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:87
ExecStatus partitionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:467
#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: partition.hpp:107
Home class for posting propagators
Definition: core.hpp:856
void update(Space &home, BndSet &x)
Update this set to be a clone of set x.
Definition: integerset.hpp:140
GLBndSet unionOfDets
Union of the determined (which are dropped)
Definition: rel-op.hh:263
unsigned int cardMax(void) const
Return cardinality maximum.
Definition: set.hpp:81
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:359
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: partition.hpp:74
int ModEvent
Type for modification events.
Definition: core.hpp:62
Propagation cost.
Definition: core.hpp:486
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition: array.hpp:1466
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:91
ExecStatus partitionNYLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:560
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:477
Range iterator for integer sets.
Definition: var-imp.hpp:185
#define forceinline
Definition: config.hpp:185
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:83
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition: core.hpp:475
Gecode::IntArgs i({1, 2, 3, 4})
@ 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, View1 y)
Post propagator .
Definition: eq.hpp:54
ExecStatus unionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &)
Definition: common.hpp:294
PartitionN(Space &home, PartitionN &p)
Constructor for cloning p.
Definition: partition.hpp:66
ExecStatus
Definition: core.hpp:472
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: partition.hpp:101