Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.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-29 14:58:00 +0100 (Thu, 29 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 
int val(void) const
Return assigned value (only if assigned)
Definition: int.hpp:70
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition: pair.hpp:47
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
static ExecStatus post(Home home, View0 x0, View1 x1)
Post domain consistent propagator .
Definition: eq.hpp:120
Pair(Space &home, bool share, Pair &p)
Constructor for cloning p.
Definition: pair.hpp:68
Computation spaces.
Definition: core.hpp:1362
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: int.hpp:124
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
Ternary propagator.
Definition: propagator.hpp:115
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
Integer view for integer variables.
Definition: view.hpp:129
Domain consistent pair propagator.
Definition: element.hh:297
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:448
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:133
Execution is okay.
Definition: core.hpp:527
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
Gecode toplevel namespace
Home class for posting propagators
Definition: core.hpp:717