Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.1
pair.cpp
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, 2009
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/element.hh>
39 
40 namespace Gecode { namespace Int { namespace Element {
41 
42  Actor*
43  Pair::copy(Space& home, bool share) {
44  return new (home) Pair(home,share,*this);
45  }
46 
48  class PairValues {
49  private:
51  IntView x;
57  int w;
58  public:
60 
61  PairValues(IntView x, IntView y, int w);
64 
66 
67  bool operator ()(void) const;
70  void operator ++(void);
72 
74 
75  int val(void) const;
78  };
79 
82  : x(x0), xv(x0), yv(y0), w(w0) {}
83  forceinline void
85  ++xv;
86  if (!xv()) {
87  xv.init(x); ++yv;
88  }
89  }
90  forceinline bool
92  return yv();
93  }
94  forceinline int
95  PairValues::val(void) const {
96  return xv.val()+w*yv.val();
97  }
98 
99 
100  ExecStatus
102  Region r(home);
103 
104  if (x0.assigned()) {
105  // Bitset for supported div and mod values
106  Support::BitSet<Region> d(r,static_cast<unsigned int>((x2.max() / w)+1));
107  for (ViewValues<IntView> i(x2); i(); ++i) {
108  d.set(static_cast<unsigned int>(i.val() / w));
109  }
111  GECODE_ME_CHECK(x1.inter_v(home,id,false));
112  } else {
113  // Bitset for supported div and mod values
115  d(r,static_cast<unsigned int>((x2.max() / w)+1)),
116  m(r,static_cast<unsigned int>(w));
117  for (ViewValues<IntView> i(x2); i(); ++i) {
118  d.set(static_cast<unsigned int>(i.val() / w));
119  m.set(static_cast<unsigned int>(i.val() % w));
120  }
122  GECODE_ME_CHECK(x0.inter_v(home,im,false));
124  GECODE_ME_CHECK(x1.inter_v(home,id,false));
125  }
126 
127  if (x0.assigned() && x1.assigned()) {
128  GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val()));
129  return home.ES_SUBSUMED(*this);
130  } else if (x1.assigned()) {
131  OffsetView x0x1w(x0,x1.val()*w);
133  ::post(home(*this),x0x1w,x2)));
134  }
135 
136  PairValues xy(x0,x1,w);
137  GECODE_ME_CHECK(x2.inter_v(home,xy,false));
138 
139  if (x2.assigned()) {
140  GECODE_ME_CHECK(x0.eq(home,x2.val() % w));
141  GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w)));
142  return home.ES_SUBSUMED(*this);
143  }
144 
145  return ES_NOFIX;
146  }
147 
148 }}}
149 
150 // STATISTICS: int-prop
151 
int val(void) const
Return assigned value (only if assigned)
Definition: int.hpp:70
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
PairValues(IntView x, IntView y, int w)
Initialize with views x and y and width w.
Definition: pair.cpp:81
Binary domain consistent equality propagator.
Definition: rel.hh:71
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition: pair.hpp:47
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
Handle to region.
Definition: region.hpp:61
Pair(Space &home, bool share, Pair &p)
Constructor for cloning p.
Definition: pair.hpp:68
Computation spaces.
Definition: core.hpp:1362
Value iterator for values in a bitset.
Gecode::IntSet d(v, 7)
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
bool operator()(void) const
Test whether iterator is still at a value or done.
Definition: pair.cpp:91
Gecode::IntArgs i(4, 1, 2, 3, 4)
int val(void) const
Return current value.
Definition: pair.cpp:95
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: pair.cpp:101
Value iterator for pair of iterators.
Definition: pair.cpp:48
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
Offset integer view.
Definition: view.hpp:422
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
void operator++(void)
Move iterator to next value (if possible)
Definition: pair.cpp:84
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: int.hpp:195
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: pair.cpp:43
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:448
Propagation has not computed fixpoint.
Definition: core.hpp:526
int val(void) const
Return current value.
Gecode toplevel namespace
void init(const View &x)
Initialize with values x.
Definition: iter.hpp:57
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173