Generated on Sat Feb 7 2015 02:01:24 for Gecode by doxygen 1.8.9.1
prop.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2011
8  *
9  * Last modified:
10  * $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
11  * $Revision: 13068 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/int/rel.hh>
39 
40 namespace Gecode { namespace Int { namespace Member {
41 
42  template<class View>
45  : NaryOnePropagator<View,PC_INT_DOM>(home,x,y),
46  vs(vs0) {}
47 
48  template<class View>
49  forceinline void
51  int n=x.size();
52  for (int i=n; i--; )
53  if (x[i].assigned()) {
54  vs.add(home, x[i].val());
55  x[i] = x[--n];
56  }
57  x.size(n);
58  }
59 
60  template<class View>
61  forceinline void
63  int n=x.size();
64  for (int i=n; i--; )
65  if ((rtest_eq_dom(x[i],y) == RT_FALSE) || vs.subset(x[i])) {
66  // x[i] is different from y or values are contained in vs
67  x[i].cancel(home, *this, PC_INT_DOM);
68  x[i] = x[--n];
69  }
70  x.size(n);
71  }
72 
73  template<class View>
74  inline ExecStatus
76  if (x.size() == 0)
77  return ES_FAILED;
78 
79  x.unique(home);
80 
81  if (x.size() == 1)
82  return Rel::EqDom<View,View>::post(home,x[0],y);
83 
84  if (x.same(home,y))
85  return ES_OK;
86 
87  // Eliminate assigned views and store them into the value set
88  ValSet vs;
89  add(home, vs, x);
90 
91  if (x.size() == 0) {
92  ValSet::Ranges vsr(vs);
93  GECODE_ME_CHECK(y.inter_r(home,vsr,false));
94  return ES_OK;
95  }
96 
97  (void) new (home) Prop<View>(home, vs, x, y);
98  return ES_OK;
99  }
100 
101  template<class View>
104  (void) new (home) Prop<View>(home, vs, x, y);
105  return ES_OK;
106  }
107 
108  template<class View>
110  Prop<View>::Prop(Space& home, bool share, Prop<View>& p)
111  : NaryOnePropagator<View,PC_INT_DOM>(home, share, p) {
112  vs.update(home, share, p.vs);
113  }
114 
115  template<class View>
116  Propagator*
117  Prop<View>::copy(Space& home, bool share) {
118  return new (home) Prop<View>(home, share, *this);
119  }
120 
121  template<class View>
122  forceinline size_t
124  vs.dispose(home);
126  return sizeof(*this);
127  }
128 
129  template<class View>
130  PropCost
131  Prop<View>::cost(const Space&, const ModEventDelta&) const {
132  return PropCost::linear(PropCost::HI, x.size()+1);
133  }
134 
135  template<class View>
136  ExecStatus
138  // Add assigned views to value set
139  if (View::me(med) == ME_INT_VAL)
140  add(home,vs,x);
141 
142  // Eliminate views from x
143  eliminate(home);
144 
145  if (x.size() == 0) {
146  // y must have values in the value set
147  ValSet::Ranges vsr(vs);
148  GECODE_ME_CHECK(y.inter_r(home,vsr,false));
149  return home.ES_SUBSUMED(*this);
150  }
151 
152  // Constrain y to union of x and value set
153  Region r(home);
154 
155  assert(x.size() > 0);
156  ValSet::Ranges vsr(vs);
157  ViewRanges<View> xsr(x[x.size()-1]);
158  Iter::Ranges::NaryUnion u(r,vsr,xsr);
159  for (int i=x.size()-1; i--; ) {
160  ViewRanges<View> xir(x[i]);
161  u |= xir;
162  }
163 
164  GECODE_ME_CHECK(y.inter_r(home,u,false));
165 
166  // Check whether all values in y are already in the value set
167  if (vs.subset(y))
168  return home.ES_SUBSUMED(*this);
169 
170  return ES_FIX;
171  }
172 
173 }}}
174 
175 // STATISTICS: int-prop
void eliminate(Term< BoolView > *t, int &n, long long int &d)
Eliminate assigned views.
Definition: bool-post.cpp:62
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition: core.hpp:4041
Binary domain consistent equality propagator.
Definition: rel.hh:71
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
virtual PropCost cost(const Space &, const ModEventDelta &med) const
Cost function.
Definition: prop.hpp:131
Base-class for propagators.
Definition: core.hpp:755
Expensive.
Definition: core.hpp:564
Membership propagator.
Definition: member.hh:58
Handle to region.
Definition: region.hpp:61
Propagation has computed fixpoint.
Definition: core.hpp:528
void unique(const Space &home)
Remove all duplicate views from array (changes element order)
Definition: array.hpp:1498
Computation spaces.
Definition: core.hpp:1362
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: prop.hpp:123
Range iterator for integer views.
Definition: view.hpp:54
static ExecStatus post(Home home, ViewArray< View > &x, View y)
Post propagator for .
Definition: prop.hpp:75
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
static void add(Space &home, ValSet &vs, ViewArray< View > &x)
Add values of assigned views in x to value set va.
Definition: prop.hpp:50
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Execution has resulted in failure.
Definition: core.hpp:525
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Iterator over ranges.
Definition: val-set.hh:82
Relation does not hold.
Definition: view.hpp:1615
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
Range iterator for union of iterators.
ValSet vs
Value set storing the values of already assigned views.
Definition: member.hh:63
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
(n+1)-ary propagator
Definition: propagator.hpp:172
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: prop.hpp:137
View arrays.
Definition: array.hpp:234
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
RelTest rtest_eq_dom(View x, View y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:68
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Propagation cost.
Definition: core.hpp:537
Prop(Home home, ValSet &vs, ViewArray< View > &x, View y)
Constructor for posting.
Definition: prop.hpp:44
ExecStatus
Definition: core.hpp:523
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
#define forceinline
Definition: config.hpp:132
bool same(const Space &home) const
Test whether array has multiple occurence of the same view.
Definition: array.hpp:1468
virtual Propagator * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: prop.hpp:117
Execution is okay.
Definition: core.hpp:527
Class for storing values of already assigned views.
Definition: val-set.hh:48
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
Gecode toplevel namespace
void update(Space &home, bool share, ValSet &vs)
Update value set during cloning.
Definition: val-set.hpp:105
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
void eliminate(Space &home)
Eliminate views from x that are not equal to y or ar subsumed by vs.
Definition: prop.hpp:62
void add(Space &home, int v)
Add value v to value set.
Definition: val-set.hpp:49