Generated on Sat Feb 7 2015 02:01:30 for Gecode by doxygen 1.8.9.1
superofinter.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: 2010-03-03 17:32:21 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $
17  * $Revision: 10364 $
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  template<class View0, class View1, class View2>
49  (Home home, View0 y0, View1 y1, View2 y2)
51  View2,PC_SET_CLUB>(home,y0,y1,y2) {}
52 
53  template<class View0, class View1, class View2>
56  (Space& home, bool share, SuperOfInter<View0,View1,View2>& p)
58  View2,PC_SET_CLUB>(home,share,p) {}
59 
60  template<class View0, class View1, class View2>
63  View0 x0, View1 x1, View2 x2) {
64  (void) new (home) SuperOfInter<View0,View1,View2>(home, x0, x1, x2);
65  return ES_OK;
66  }
67 
68  template<class View0, class View1, class View2>
69  Actor*
71  return new (home) SuperOfInter(home,share,*this);
72  }
73 
74  template<class View0, class View1, class View2>
77 
78  bool allassigned = x0.assigned() && x1.assigned() && x2.assigned();
79 
80  ModEvent me0 = View0::me(med);
81  ModEvent me1 = View1::me(med);
82  ModEvent me2 = View2::me(med);
83 
84  bool modified = false;
85 
86  do {
87  // glb(x2) >= glb(x0) ^ glb(x1)
88  if ( modified || Rel::testSetEventLB(me0,me1)) {
89  GlbRanges<View0> lb0(x0);
90  GlbRanges<View1> lb1(x1);
92  is(lb0, lb1);
93 
94  GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is));
95  }
96 
97  // lub(x0) -= glb(x1)-lub(x2)
98  // lub(x1) -= glb(x0)-lub(x2)
99  if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) {
100  modified = false;
101  GlbRanges<View1> lb12(x1);
102  LubRanges<View2> ub22(x2);
104  diff1(lb12, ub22);
105 
106  GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1));
107 
108  GlbRanges<View0> lb01(x0);
109  LubRanges<View2> ub23(x2);
111  diff2(lb01, ub23);
112 
113  GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2));
114  } else {
115  modified = false;
116  }
117 
118  // Cardinality propagation
119  if ( modified ||
120  Rel::testSetEventCard(me0,me1,me2) ||
121  Rel::testSetEventUB(me0,me1)
122  ) {
123 
124  LubRanges<View0> ub0(x0);
125  LubRanges<View1> ub1(x1);
127 
128  unsigned int m = Iter::Ranges::size(u);
129 
130  if (m < x0.cardMin() + x1.cardMin()) {
131  GECODE_ME_CHECK_MODIFIED(modified,
132  x2.cardMin( home,
133  x0.cardMin()+x1.cardMin() - m ) );
134  }
135  if (m + x2.cardMax() > x1.cardMin()) {
136  GECODE_ME_CHECK_MODIFIED(modified,
137  x0.cardMax( home,
138  m+x2.cardMax()-x1.cardMin() ) );
139  }
140  if (m + x2.cardMax() > x0.cardMin()) {
141  GECODE_ME_CHECK_MODIFIED(modified,
142  x1.cardMax( home,
143  m+x2.cardMax()-x0.cardMin() ) );
144  }
145  }
146  } while (modified);
147 
148 
149  if (shared(x0,x1,x2)) {
150  if (allassigned) {
151  return home.ES_SUBSUMED(*this);
152  } else {
153  return ES_NOFIX;
154  }
155  } else {
156  if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
157  return home.ES_SUBSUMED(*this);
158  } else {
159  return ES_FIX;
160  }
161  }
162 
163  }
164 
165 }}}
166 
167 // STATISTICS: set-prop
const Gecode::PropCond PC_SET_CLUB
Propagate when the cardinality or the least upper bound of a view changes.
Definition: var-type.hpp:227
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:83
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
int ModEvent
Type for modification events.
Definition: core.hpp:146
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
static ExecStatus post(Home home, View0 x, View1 y, View2 z)
Post propagator .
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
#define GECODE_ME_CHECK_MODIFIED(modified, me)
Check whether me is failed or modified, and forward failure.
Definition: macros.hpp:57
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
Base-class for both propagators and branchers.
Definition: core.hpp:666
SuperOfInter(Space &home, bool share, SuperOfInter &p)
Constructor for cloning p.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Range iterator for computing intersection (binary)
Mixed ternary propagator.
Definition: propagator.hpp:235
unsigned int size(I &i)
Size of all ranges of range iterator i.
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
Range iterator for computing union (binary)
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:75
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
Propagator for the superset of intersection
Definition: rel-op.hh:65
Execution is okay.
Definition: core.hpp:527
Propagation has not computed fixpoint.
Definition: core.hpp:526
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:87
Gecode toplevel namespace
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:79
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717