Generated on Mon Sep 17 2012 22:20:45 for Gecode by doxygen 1.8.1.1
channel-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-05-02 08:24:42 +1000 (Mon, 02 May 2011) $ by $Author: tack $
15  * $Revision: 11973 $
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 Int {
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));
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