Generated on Thu Jan 20 2022 00:00:00 for Gecode by doxygen 1.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  * 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.hh>
39 
40 namespace Gecode { namespace Set { namespace Channel {
41 
42  template<class View>
46  Gecode::Int::IntView> >& xs0,
48  : Propagator(home), xs(xs0), ys(ys0) {
49  for (int i=xs.size(); i--;)
50  xs[i].initCache(home,IntSet(0,ys.size()-1));
51  for (int i=ys.size(); i--;)
52  ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
54  ys.subscribe(home,*this, PC_SET_ANY);
55  }
56 
57  template<class View>
60  : Propagator(home,p) {
61  xs.update(home,p.xs);
62  ys.update(home,p.ys);
63  }
64 
65  template<class View>
69  Gecode::Int::IntView> >& xs,
71  // Sharing of ys is taken care of in the propagator:
72  // The ys are propagated to be disjoint, so shared variables
73  // result in failure.
74  int xssize = xs.size();
75  for (int i=ys.size(); i--;) {
76  GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
77  GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
78  }
79  int yssize = ys.size();
80  if (yssize > Gecode::Int::Limits::max)
81  return ES_FAILED;
82  for (int i=xs.size(); i--;) {
83  GECODE_ME_CHECK(xs[i].gq(home, 0));
84  GECODE_ME_CHECK(xs[i].le(home, static_cast<int>(yssize)));
85  }
86 
87  (void) new (home) ChannelInt(home,xs,ys);
88  return ES_OK;
89  }
90 
91  template<class View>
92  PropCost
93  ChannelInt<View>::cost(const Space&, const ModEventDelta&) const {
94  return PropCost::quadratic(PropCost::LO, xs.size()+ys.size());
95  }
96 
97  template<class View>
98  void
100  xs.reschedule(home,*this, Gecode::Int::PC_INT_DOM);
101  ys.reschedule(home,*this, PC_SET_ANY);
102  }
103 
104  template<class View>
105  forceinline size_t
107  xs.cancel(home,*this, Gecode::Int::PC_INT_DOM);
108  ys.cancel(home,*this, PC_SET_ANY);
109  (void) Propagator::dispose(home);
110  return sizeof(*this);
111  }
112 
113  template<class View>
114  Actor*
116  return new (home) ChannelInt(home,*this);
117  }
118 
119  template<class View>
120  ExecStatus
122  int assigned = 0;
123  for (int v=xs.size(); v--;) {
124  if (xs[v].assigned()) {
125  assigned++;
126  if (xs[v].modified())
127  GECODE_ME_CHECK(ys[xs[v].val()].include(home,v));
128  }
129  if (xs[v].modified()) {
132  Gecode::Int::IntView> > dv(d);
133  for (; dv(); ++dv)
134  GECODE_ME_CHECK(ys[dv.val()].exclude(home, v));
135  xs[v].cache(home);
136  }
137  }
138 
139  for (int i=ys.size(); i--;) {
140  if (ys[i].glbModified()) {
141  GlbDiffRanges<View> yilb(ys[i]);
143  for (;dv();++dv)
144  GECODE_ME_CHECK(xs[dv.val()].eq(home,i));
145  ys[i].cacheGlb(home);
146  }
147  if (ys[i].lubModified()) {
148  LubDiffRanges<View> yiub(ys[i]);
150  for (;dv();++dv)
151  GECODE_ME_CHECK(xs[dv.val()].nq(home,i));
152  ys[i].cacheLub(home);
153  }
154  }
155 
156  return (assigned==xs.size()) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
157  }
158 
159 }}}
160 
161 // STATISTICS: set-prop
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Base-class for both propagators and branchers.
Definition: core.hpp:628
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3252
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1607
Home class for posting propagators
Definition: core.hpp:856
Integer sets.
Definition: int.hh:174
static const IntSet empty
Empty set.
Definition: int.hh:283
Cached integer view.
Definition: view.hpp:1166
Integer view for integer variables.
Definition: view.hpp:129
Range iterator for cached integer views
Definition: view.hpp:1354
Value iterator from range iterator.
int val(void) const
Return current value.
Propagation cost.
Definition: core.hpp:486
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4787
@ LO
Cheap.
Definition: core.hpp:513
Base-class for propagators.
Definition: core.hpp:1064
Propagator for channelling between variable-value-dual models
Definition: channel.hh:105
static ExecStatus post(Home home, ViewArray< Gecode::Int::CachedView< Gecode::Int::IntView > > &x, ViewArray< CachedView< View > > &y)
Post propagator for .
Definition: int.hpp:67
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_LO)
Definition: int.hpp:93
ChannelInt(Space &home, ChannelInt &p)
Constructor for cloning p.
Definition: int.hpp:59
ViewArray< Gecode::Int::CachedView< Gecode::Int::IntView > > xs
IntViews, reflects which set contains element .
Definition: channel.hh:108
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int.hpp:121
virtual void reschedule(Space &home)
Schedule function.
Definition: int.hpp:99
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: int.hpp:115
ViewArray< CachedView< View > > ys
SetViews that are constrained to be disjoint.
Definition: channel.hh:110
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: int.hpp:106
Range iterator for difference of greatest lower bound and cache
Definition: view.hpp:1138
Range iterator for difference of least upper bound and cache
Definition: view.hpp:1155
Computation spaces.
Definition: core.hpp:1742
View arrays.
Definition: array.hpp:253
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition: array.hpp:1328
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition: array.hpp:1341
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1156
ExecStatus
Definition: core.hpp:472
@ ES_OK
Execution is okay.
Definition: core.hpp:476
@ ES_FAILED
Execution has resulted in failure.
Definition: core.hpp:474
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition: core.hpp:475
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
const int max
Largest allowed integer value.
Definition: int.hh:116
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition: set-op.hpp:137
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
Definition: set-op.hpp:123
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
const int min
Smallest allowed integer in integer set.
Definition: set.hh:99
const int max
Largest allowed integer in integer set.
Definition: set.hh:97
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::IntSet d(v, 7)
const int v[7]
Definition: distinct.cpp:259
#define forceinline
Definition: config.hpp:194