Generated on Sat Feb 7 2015 02:01:15 for Gecode by doxygen 1.8.9.1
dom.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, 2013
8  *
9  * Last modified:
10  * $Date: 2013-03-05 13:52:08 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
11  * $Revision: 13434 $
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 
39 #include <gecode/float/rel.hh>
40 
41 namespace Gecode {
42 
43  void
45  using namespace Float;
46  Limits::check(n,"Float::dom");
47  if (home.failed()) return;
48  FloatView xv(x);
49  GECODE_ME_FAIL(xv.eq(home,n));
50  }
51 
52  void
53  dom(Home home, const FloatVarArgs& x, FloatVal n) {
54  using namespace Float;
55  Limits::check(n,"Float::dom");
56  if (home.failed()) return;
57  for (int i=x.size(); i--; ) {
58  FloatView xv(x[i]);
59  GECODE_ME_FAIL(xv.eq(home,n));
60  }
61  }
62 
63  void
65  using namespace Float;
66  Limits::check(min,"Float::dom");
67  Limits::check(max,"Float::dom");
68  if (home.failed()) return;
69  FloatView xv(x);
70  GECODE_ME_FAIL(xv.gq(home,min));
71  GECODE_ME_FAIL(xv.lq(home,max));
72  }
73 
74  void
76  using namespace Float;
77  Limits::check(min,"Float::dom");
78  Limits::check(max,"Float::dom");
79  if (home.failed()) return;
80  for (int i=x.size(); i--; ) {
81  FloatView xv(x[i]);
82  GECODE_ME_FAIL(xv.gq(home,min));
83  GECODE_ME_FAIL(xv.lq(home,max));
84  }
85  }
86 
87  void
89  using namespace Float;
90  Limits::check(n,"Float::dom");
91  if (home.failed()) return;
92  switch (r.mode()) {
93  case RM_EQV:
94  GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_EQV>
95  ::post(home,x,n,r.var())));
96  break;
97  case RM_IMP:
98  GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_IMP>
99  ::post(home,x,n,r.var())));
100  break;
101  case RM_PMI:
102  GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_PMI>
103  ::post(home,x,n,r.var())));
104  break;
105  default: throw Int::UnknownReifyMode("Float::dom");
106  }
107  }
108 
109  void
111  using namespace Float;
112  if (min > max) {
113  Int::BoolView b(r.var());
114  switch (r.mode()) {
115  case RM_EQV:
116  case RM_IMP:
117  GECODE_ME_FAIL(b.zero(home));
118  break;
119  case RM_PMI:
120  break;
121  default: throw Int::UnknownReifyMode("Float::dom");
122  }
123  } else {
124  FloatVal n(min,max);
125  dom(home,x,n,r);
126  }
127  }
128 
129  void
131  using namespace Float;
132  if (home.failed()) return;
133  FloatView xv(x), dv(d);
134  if (!same(xv,dv)) {
135  GECODE_ME_FAIL(xv.lq(home,dv.max()));
136  GECODE_ME_FAIL(xv.gq(home,dv.min()));
137  }
138  }
139 
140  void
141  dom(Home home, const FloatVarArgs& x, const FloatVarArgs& d) {
142  using namespace Float;
143  if (x.size() != d.size())
144  throw ArgumentSizeMismatch("Float::dom");
145  for (int i=x.size(); i--; ) {
146  if (home.failed()) return;
147  FloatView xv(x[i]), dv(d[i]);
148  if (!same(xv,dv)) {
149  GECODE_ME_FAIL(xv.lq(home,dv.max()));
150  GECODE_ME_FAIL(xv.gq(home,dv.min()));
151  }
152  }
153  }
154 
155 }
156 
157 // STATISTICS: float-post
158 
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
Inverse implication for reification.
Definition: int.hh:847
ReifyMode mode(void) const
Return reification mode.
Definition: reify.hpp:60
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
BoolVar var(void) const
Return Boolean control variable.
Definition: reify.hpp:52
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
Passing float variables.
Definition: float.hh:966
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Gecode::IntSet d(r, 4)
bool same(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether two views are the same.
Definition: view.hpp:603
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Reification specification.
Definition: int.hh:854
void check(const FloatVal &n, const char *l)
Check whether float n is a valid number, otherwise throw out of limits exception with information l...
Definition: limits.hpp:48
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Float value type.
Definition: float.hh:321
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:70
Float variables.
Definition: float.hh:857
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:119
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
Home class for posting propagators
Definition: core.hpp:717
Exception: Arguments are of different size
Definition: exception.hpp:77
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
double FloatNum
Floating point number base type.
Definition: float.hh:108
const int r[4][2]
Definition: dom.cpp:126
Equivalence for reification (default)
Definition: int.hh:833
Boolean view for Boolean variables.
Definition: view.hpp:1315