Generated on Mon Feb 8 2021 00:00:00 for Gecode by doxygen 1.8.20
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  * 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  template<class View0, class View1, class View2>
45  (Home home, View0 y0, View1 y1, View2 y2)
47  View2,PC_SET_CLUB>(home,y0,y1,y2) {}
48 
49  template<class View0, class View1, class View2>
54  View2,PC_SET_CLUB>(home,p) {}
55 
56  template<class View0, class View1, class View2>
59  View0 x0, View1 x1, View2 x2) {
60  (void) new (home) SuperOfInter<View0,View1,View2>(home, x0, x1, x2);
61  return ES_OK;
62  }
63 
64  template<class View0, class View1, class View2>
65  Actor*
67  return new (home) SuperOfInter(home,*this);
68  }
69 
70  template<class View0, class View1, class View2>
73 
74  bool allassigned = x0.assigned() && x1.assigned() && x2.assigned();
75 
76  ModEvent me0 = View0::me(med);
77  ModEvent me1 = View1::me(med);
78  ModEvent me2 = View2::me(med);
79 
80  bool modified = false;
81 
82  do {
83  // glb(x2) >= glb(x0) ^ glb(x1)
84  if ( modified || Rel::testSetEventLB(me0,me1)) {
85  GlbRanges<View0> lb0(x0);
86  GlbRanges<View1> lb1(x1);
88  is(lb0, lb1);
89 
90  GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is));
91  }
92 
93  // lub(x0) -= glb(x1)-lub(x2)
94  // lub(x1) -= glb(x0)-lub(x2)
95  if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) {
96  modified = false;
97  GlbRanges<View1> lb12(x1);
98  LubRanges<View2> ub22(x2);
100  diff1(lb12, ub22);
101 
102  GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1));
103 
104  GlbRanges<View0> lb01(x0);
105  LubRanges<View2> ub23(x2);
107  diff2(lb01, ub23);
108 
109  GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2));
110  } else {
111  modified = false;
112  }
113 
114  // Cardinality propagation
115  if ( modified ||
116  Rel::testSetEventCard(me0,me1,me2) ||
117  Rel::testSetEventUB(me0,me1)
118  ) {
119 
120  LubRanges<View0> ub0(x0);
121  LubRanges<View1> ub1(x1);
123 
124  unsigned int m = Iter::Ranges::size(u);
125 
126  if (m < x0.cardMin() + x1.cardMin()) {
127  GECODE_ME_CHECK_MODIFIED(modified,
128  x2.cardMin( home,
129  x0.cardMin()+x1.cardMin() - m ) );
130  }
131  if (m + x2.cardMax() > x1.cardMin()) {
132  GECODE_ME_CHECK_MODIFIED(modified,
133  x0.cardMax( home,
134  m+x2.cardMax()-x1.cardMin() ) );
135  }
136  if (m + x2.cardMax() > x0.cardMin()) {
137  GECODE_ME_CHECK_MODIFIED(modified,
138  x1.cardMax( home,
139  m+x2.cardMax()-x0.cardMin() ) );
140  }
141  }
142  } while (modified);
143 
144 
145  if (shared(x0,x1,x2)) {
146  if (allassigned) {
147  return home.ES_SUBSUMED(*this);
148  } else {
149  return ES_NOFIX;
150  }
151  } else {
152  if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
153  return home.ES_SUBSUMED(*this);
154  } else {
155  return ES_FIX;
156  }
157  }
158 
159  }
160 
161 }}}
162 
163 // STATISTICS: set-prop
#define GECODE_ME_CHECK_MODIFIED(modified, me)
Check whether me is failed or modified, and forward failure.
Definition: macros.hpp:64
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
unsigned int size(I &i)
Size of all ranges of range iterator i.
bool shared(View0 v0, View1 v1, View2 v2)
Definition: common.hpp:84
Computation spaces.
Definition: core.hpp:1742
Base-class for both propagators and branchers.
Definition: core.hpp:628
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Mixed ternary propagator.
Definition: pattern.hpp:237
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:95
Gecode toplevel namespace
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:87
const Gecode::PropCond PC_SET_CLUB
Propagate when the cardinality or the least upper bound of a view changes.
Definition: var-type.hpp:227
Home class for posting propagators
Definition: core.hpp:856
Range iterator for computing intersection (binary)
Range iterator for computing set difference.
Definition: ranges-diff.hpp:43
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:359
int ModEvent
Type for modification events.
Definition: core.hpp:62
Range iterator for computing union (binary)
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:91
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:477
Range iterator for the least upper bound.
Definition: var-imp.hpp:317
static ExecStatus post(Home home, View0 x, View1 y, View2 z)
Post propagator .
#define forceinline
Definition: config.hpp:192
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
Propagator for the superset of intersection
Definition: rel-op.hh:63
SuperOfInter(Space &home, SuperOfInter &p)
Constructor for cloning p.
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
@ ES_OK
Execution is okay.
Definition: core.hpp:476
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
ExecStatus
Definition: core.hpp:472