Generated on Mon Sep 17 2012 22:20:38 for Gecode by doxygen 1.8.1.1
pair.hpp
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: 2009-10-30 00:58:00 +1100 (Fri, 30 Oct 2009) $ by $Author: schulte $
11  * $Revision: 10000 $
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/rel.hh>
39 
40 namespace Gecode { namespace Int { namespace Element {
41 
43  Pair::Pair(Home home, IntView x0, IntView x1, IntView x2, int w0)
44  : TernaryPropagator<IntView,PC_INT_DOM>(home,x0,x1,x2), w(w0) {}
45 
46  inline ExecStatus
48  int w, int h) {
49  GECODE_ME_CHECK(x0.gq(home,0)); GECODE_ME_CHECK(x0.le(home,w));
50  GECODE_ME_CHECK(x1.gq(home,0)); GECODE_ME_CHECK(x1.le(home,h));
51  GECODE_ME_CHECK(x2.gq(home,0)); GECODE_ME_CHECK(x2.le(home,w*h));
52  if (x0.assigned() && x1.assigned()) {
53  GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val()));
54  } else if (x1.assigned()) {
55  OffsetView x0x1w(x0,x1.val()*w);
56  return Rel::EqDom<OffsetView,IntView>::post(home,x0x1w,x2);
57  } else if (x2.assigned()) {
58  GECODE_ME_CHECK(x0.eq(home,x2.val() % w));
59  GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w)));
60  } else {
61  assert(!shared(x0,x2) && !shared(x1,x2));
62  (void) new (home) Pair(home,x0,x1,x2,w);
63  }
64  return ES_OK;
65  }
66 
68  Pair::Pair(Space& home, bool share, Pair& p)
69  : TernaryPropagator<IntView,PC_INT_DOM>(home,share,p), w(p.w) {}
70 
71 }}}
72 
73 // STATISTICS: int-prop
74