Generated on Sat Feb 7 2015 02:01:30 for Gecode by doxygen 1.8.9.1
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  * Last modified:
16  * $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
17  * $Revision: 13068 $
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 namespace Gecode { namespace Set { namespace RelOp {
45 
46  /*
47  * "Nary partition" propagator
48  *
49  */
50 
51  template<class View0, class View1>
54  : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
55  shared = x.shared(home) || viewarrayshared(home,x,y);
56  }
57 
58  template<class View0, class View1>
61  const IntSet& z, View1 y)
62  : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
63  shared = x.shared(home) || viewarrayshared(home,x,y);
64  IntSetRanges rz(z);
65  unionOfDets.includeI(home, rz);
66  }
67 
68  template<class View0, class View1>
71  : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,share,p),
72  shared(p.shared) {
74  }
75 
76  template<class View0, class View1>
77  Actor*
78  PartitionN<View0,View1>::copy(Space& home, bool share) {
79  return new (home) PartitionN(home,share,*this);
80  }
81 
82  template<class View0, class View1>
84  View1 y) {
85  switch (x.size()) {
86  case 0:
87  GECODE_ME_CHECK(y.cardMax(home, 0));
88  return ES_OK;
89  case 1:
90  return Rel::Eq<View0,View1>::post(home, x[0], y);
91  default:
92  (void) new (home) PartitionN<View0,View1>(home,x,y);
93  return ES_OK;
94  }
95  }
96 
97  template<class View0, class View1>
99  const IntSet& z, View1 y) {
100  (void) new (home) PartitionN<View0,View1>(home,x,z,y);
101  return ES_OK;
102  }
103 
104  template<class View0, class View1>
106  return PropCost::quadratic(PropCost::LO, x.size()+1);
107  }
108 
109  template<class View0, class View1>
110  ExecStatus
112 
113  ModEvent me0 = View0::me(med);
114  ModEvent me1 = View1::me(med);
115  bool ubevent = Rel::testSetEventUB(me0, me1);
116  bool lbevent = Rel::testSetEventLB(me0, me1);
117  bool anybevent = Rel::testSetEventAnyB(me0, me1);
118  bool cardevent = Rel::testSetEventCard(me0, me1);
119 
120  bool modified = false;
121  bool oldModified = false;
122 
123  do {
124  oldModified = modified;
125  modified = false;
126  if (oldModified || anybevent)
127  GECODE_ES_CHECK(partitionNXiUB(home,modified, x, y,unionOfDets));
128  if (modified || oldModified || anybevent)
129  GECODE_ES_CHECK(partitionNXiLB(home,modified, x, y,unionOfDets));
130  if (modified || oldModified || ubevent)
131  GECODE_ES_CHECK(partitionNYUB(home,modified, x, y,unionOfDets));
132  if (modified || oldModified || lbevent)
133  GECODE_ES_CHECK(partitionNYLB(home,modified, x, y,unionOfDets));
134  if (modified || oldModified || ubevent)
135  GECODE_ES_CHECK(unionNXiUB(home,modified, x, y,unionOfDets));
136  if (modified || oldModified || cardevent)
137  GECODE_ES_CHECK(partitionNCard(home,modified, x, y,unionOfDets));
138  } while (modified);
139 
140  //removing assigned sets from x, accumulating the value:
141  for(int i=0;i<x.size();i++){
142  //Do not reverse! Eats away the end of the array!
143  while (i<x.size() && x[i].assigned()) {
144  GlbRanges<View0> det(x[i]);
145  unionOfDets.includeI(home,det);
146  x.move_lst(i);
147  }
148  }
149  // When we run out of variables, make a final check and disolve:
150  if (x.size()==0) {
151  BndSetRanges all1(unionOfDets);
152  GECODE_ME_CHECK( y.intersectI(home,all1) );
153  BndSetRanges all2(unionOfDets);
154  GECODE_ME_CHECK( y.includeI(home,all2) );
155  unionOfDets.dispose(home);
156  return home.ES_SUBSUMED(*this);
157  }
158 
159  return shared ? ES_NOFIX : ES_FIX;
160  }
161 
162 }}}
163 
164 // STATISTICS: set-prop
ExecStatus partitionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:472
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:83
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low linear)
Definition: partition.hpp:105
ExecStatus partitionNYLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:565
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4032
Range iterator for integer sets.
Definition: int.hh:271
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
ExecStatus unionNXiUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &)
Definition: common.hpp:299
Mixed (n+1)-ary propagator.
Definition: propagator.hpp:268
int ModEvent
Type for modification events.
Definition: core.hpp:146
ExecStatus partitionNXiLB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:518
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: partition.hpp:78
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
PartitionN(Space &home, bool share, PartitionN &p)
Constructor for cloning p.
Definition: partition.hpp:70
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: partition.hpp:111
Base-class for both propagators and branchers.
Definition: core.hpp:666
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:84
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
bool shared(const Space &home) const
Test whether array contains shared views.
Definition: array.hpp:1511
Propagator for nary partition
Definition: rel-op.hh:257
Range iterator for integer sets.
Definition: var-imp.hpp:189
ExecStatus partitionNYUB(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:592
Integer sets.
Definition: int.hh:171
void update(Space &home, BndSet &x)
Update this set to be a clone of set x.
Definition: integerset.hpp:144
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
bool includeI(Space &home, I &i)
Include the set represented by i in this set.
Definition: integerset.hpp:300
GLBndSet unionOfDets
Union of the determined (which are dropped)
Definition: rel-op.hh:265
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
bool shared(View0 v0, View1 v1, View2 v2)
Definition: common.hpp:89
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:75
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Propagation cost.
Definition: core.hpp:537
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
ExecStatus partitionNCard(Space &home, bool &modified, ViewArray< View0 > &x, View1 &y, GLBndSet &unionOfDets)
Definition: common.hpp:313
Execution is okay.
Definition: core.hpp:527
Propagation has not computed fixpoint.
Definition: core.hpp:526
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
bool shared
Whether the any views share a variable implementation.
Definition: rel-op.hh:263
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:87
Gecode toplevel namespace
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:79
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
static ExecStatus post(Home home, View0, View1)
Post propagator .
Definition: eq.hpp:58
static ExecStatus post(Home home, ViewArray< View0 > &y, View1 x)
Post propagator .
Definition: partition.hpp:83
bool viewarrayshared(const Space &home, const ViewArray< View0 > &va, const View1 &y)
Definition: common.hpp:51