Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.1
int.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  * Gabor Szokoli <szokoli@gecode.org>
7  *
8  * Copyright:
9  * Guido Tack, 2004
10  * Christian Schulte, 2004
11  * Gabor Szokoli, 2004
12  *
13  * Last modified:
14  * $Date: 2011-11-03 11:52:07 +0100 (Thu, 03 Nov 2011) $ by $Author: tack $
15  * $Revision: 12452 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 #include <gecode/int.hh>
43 
44 namespace Gecode { namespace Set { namespace Channel {
45 
46  template<class View>
50  Gecode::Int::IntView> >& xs0,
52  : Propagator(home), xs(xs0), ys(ys0) {
53  for (int i=xs.size(); i--;)
54  xs[i].initCache(home,IntSet(0,ys.size()-1));
55  for (int i=ys.size(); i--;)
56  ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
57  xs.subscribe(home,*this, Gecode::Int::PC_INT_DOM);
58  ys.subscribe(home,*this, PC_SET_ANY);
59  }
60 
61  template<class View>
64  : Propagator(home,share,p) {
65  xs.update(home,share,p.xs);
66  ys.update(home,share,p.ys);
67  }
68 
69  template<class View>
73  Gecode::Int::IntView> >& xs,
75  // Sharing of ys is taken care of in the propagator:
76  // The ys are propagated to be disjoint, so shared variables
77  // result in failure.
78  int xssize = xs.size();
79  for (int i=ys.size(); i--;) {
80  GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
81  GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
82  }
83  int yssize = ys.size();
84  if (yssize > Gecode::Int::Limits::max)
85  return ES_FAILED;
86  for (int i=xs.size(); i--;) {
87  GECODE_ME_CHECK(xs[i].gq(home, 0));
88  GECODE_ME_CHECK(xs[i].le(home, static_cast<int>(yssize)));
89  }
90 
91  (void) new (home) ChannelInt(home,xs,ys);
92  return ES_OK;
93  }
94 
95  template<class View>
96  PropCost
97  ChannelInt<View>::cost(const Space&, const ModEventDelta&) const {
98  return PropCost::quadratic(PropCost::LO, xs.size()+ys.size());
99  }
100 
101  template<class View>
102  forceinline size_t
104  xs.cancel(home,*this, Gecode::Int::PC_INT_DOM);
105  ys.cancel(home,*this, PC_SET_ANY);
106  (void) Propagator::dispose(home);
107  return sizeof(*this);
108  }
109 
110  template<class View>
111  Actor*
112  ChannelInt<View>::copy(Space& home, bool share) {
113  return new (home) ChannelInt(home,share,*this);
114  }
115 
116  template<class View>
117  ExecStatus
119  int assigned = 0;
120  for (int v=xs.size(); v--;) {
121  if (xs[v].assigned()) {
122  assigned++;
123  if (xs[v].modified())
124  GECODE_ME_CHECK(ys[xs[v].val()].include(home,v));
125  }
126  if (xs[v].modified()) {
129  Gecode::Int::IntView> > dv(d);
130  for (; dv(); ++dv)
131  GECODE_ME_CHECK(ys[dv.val()].exclude(home, v));
132  xs[v].cache(home);
133  }
134  }
135 
136  for (int i=ys.size(); i--;) {
137  if (ys[i].glbModified()) {
138  GlbDiffRanges<View> yilb(ys[i]);
140  for (;dv();++dv)
141  GECODE_ME_CHECK(xs[dv.val()].eq(home,i));
142  ys[i].cacheGlb(home);
143  }
144  if (ys[i].lubModified()) {
145  LubDiffRanges<View> yiub(ys[i]);
147  for (;dv();++dv)
148  GECODE_ME_CHECK(xs[dv.val()].nq(home,i));
149  ys[i].cacheLub(home);
150  }
151  }
152 
153  return (assigned==xs.size()) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
154  }
155 
156 }}}
157 
158 // STATISTICS: set-prop
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4032
const int min
Smallest allowed integer in integer set.
Definition: set.hh:101
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
ChannelInt(Space &home, bool share, ChannelInt &p)
Constructor for cloning p.
Definition: int.hpp:63
Base-class for propagators.
Definition: core.hpp:755
ViewArray< Gecode::Int::CachedView< Gecode::Int::IntView > > xs
IntViews, reflects which set contains element .
Definition: channel.hh:110
const int max
Largest allowed integer in integer set.
Definition: set.hh:99
const int max
Largest allowed integer value.
Definition: int.hh:113
Computation spaces.
Definition: core.hpp:1362
Base-class for both propagators and branchers.
Definition: core.hpp:666
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition: set-op.hpp:141
Gecode::IntSet d(v, 7)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
static ExecStatus post(Home home, ViewArray< Gecode::Int::CachedView< Gecode::Int::IntView > > &x, ViewArray< CachedView< View > > &y)
Post propagator for .
Definition: int.hpp:71
Execution has resulted in failure.
Definition: core.hpp:525
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int.hpp:118
Value iterator from range iterator.
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
Range iterator for difference of greatest lower bound and cache
Definition: view.hpp:907
Integer sets.
Definition: int.hh:171
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
static const IntSet empty
Empty set.
Definition: int.hh:262
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
const int v[7]
Definition: distinct.cpp:207
Integer view for integer variables.
Definition: view.hpp:129
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:2877
Propagation cost.
Definition: core.hpp:537
ExecStatus
Definition: core.hpp:523
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
ViewArray< CachedView< View > > ys
SetViews that are constrained to be disjoint.
Definition: channel.hh:112
#define forceinline
Definition: config.hpp:132
Cached integer view.
Definition: view.hpp:1107
Execution is okay.
Definition: core.hpp:527
Propagation has not computed fixpoint.
Definition: core.hpp:526
int val(void) const
Return current value.
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_LO)
Definition: int.hpp:97
Gecode toplevel namespace
Propagator for channelling between variable-value-dual models
Definition: channel.hh:107
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
Range iterator for difference of least upper bound and cache
Definition: view.hpp:906
Range iterator for cached integer views
Definition: view.hpp:1094
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: int.hpp:112
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: int.hpp:103