Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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$ by $Author$
15  * $Revision$
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));
58  ys.subscribe(home,*this, PC_SET_ANY);
59  }
60 
61  template<class View>
64  : Propagator(home,p) {
65  xs.update(home,p.xs);
66  ys.update(home,p.ys);
67  }
68 
69  template<class View>
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  void
105  ys.reschedule(home,*this, PC_SET_ANY);
106  }
107 
108  template<class View>
109  forceinline size_t
111  xs.cancel(home,*this, Gecode::Int::PC_INT_DOM);
112  ys.cancel(home,*this, PC_SET_ANY);
113  (void) Propagator::dispose(home);
114  return sizeof(*this);
115  }
116 
117  template<class View>
118  Actor*
120  return new (home) ChannelInt(home,*this);
121  }
122 
123  template<class View>
124  ExecStatus
126  int assigned = 0;
127  for (int v=xs.size(); v--;) {
128  if (xs[v].assigned()) {
129  assigned++;
130  if (xs[v].modified())
131  GECODE_ME_CHECK(ys[xs[v].val()].include(home,v));
132  }
133  if (xs[v].modified()) {
136  Gecode::Int::IntView> > dv(d);
137  for (; dv(); ++dv)
138  GECODE_ME_CHECK(ys[dv.val()].exclude(home, v));
139  xs[v].cache(home);
140  }
141  }
142 
143  for (int i=ys.size(); i--;) {
144  if (ys[i].glbModified()) {
145  GlbDiffRanges<View> yilb(ys[i]);
147  for (;dv();++dv)
148  GECODE_ME_CHECK(xs[dv.val()].eq(home,i));
149  ys[i].cacheGlb(home);
150  }
151  if (ys[i].lubModified()) {
152  LubDiffRanges<View> yiub(ys[i]);
154  for (;dv();++dv)
155  GECODE_ME_CHECK(xs[dv.val()].nq(home,i));
156  ys[i].cacheLub(home);
157  }
158  }
159 
160  return (assigned==xs.size()) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
161  }
162 
163 }}}
164 
165 // STATISTICS: set-prop
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: array.hpp:1417
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4634
const int min
Smallest allowed integer in integer set.
Definition: set.hh:103
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition: array.hpp:1375
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3433
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_LO)
Definition: int.hpp:97
Base-class for propagators.
Definition: core.hpp:1016
ViewArray< Gecode::Int::CachedView< Gecode::Int::IntView > > xs
IntViews, reflects which set contains element .
Definition: channel.hh:112
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition: array.hpp:1388
#define forceinline
Definition: config.hpp:182
const int max
Largest allowed integer in integer set.
Definition: set.hh:101
const int max
Largest allowed integer value.
Definition: int.hh:116
Computation spaces.
Definition: core.hpp:1668
int val(void) const
Return current value.
Base-class for both propagators and branchers.
Definition: core.hpp:620
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:466
ChannelInt(Space &home, ChannelInt &p)
Constructor for cloning p.
Definition: int.hpp:63
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int.hpp:125
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:909
Integer sets.
Definition: int.hh:174
View arrays.
Definition: array.hpp:228
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition: array.hpp:1396
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
static const IntSet empty
Empty set.
Definition: int.hh:263
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:263
Integer view for integer variables.
Definition: view.hpp:129
virtual void reschedule(Space &home)
Schedule function.
Definition: int.hpp:103
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3172
Propagation cost.
Definition: core.hpp:478
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: int.hpp:119
ExecStatus
Definition: core.hpp:464
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:114
Cached integer view.
Definition: view.hpp:1119
Execution is okay.
Definition: core.hpp:468
Propagation has not computed fixpoint.
Definition: core.hpp:467
Gecode toplevel namespace
Propagator for channelling between variable-value-dual models
Definition: channel.hh:109
int ModEventDelta
Modification event deltas.
Definition: core.hpp:91
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1203
Home class for posting propagators
Definition: core.hpp:846
Range iterator for difference of least upper bound and cache
Definition: view.hpp:908
Range iterator for cached integer views
Definition: view.hpp:1106
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: int.hpp:110