Generated on Thu Jul 25 2019 00:00:00 for Gecode by doxygen 1.8.15
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: 2016-05-23 22:18:23 +0200 (Mon, 23 May 2016) $ by $Author: schulte $
11  * $Revision: 15073 $
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");
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");
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");
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");
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");
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  GECODE_POST;
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  GECODE_POST;
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 
Inverse implication for reification.
Definition: int.hh:850
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:53
Passing float variables.
Definition: float.hh:981
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:643
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:161
Reification specification.
Definition: int.hh:857
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
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:71
Float value type.
Definition: float.hh:338
Post propagator for SetVar x
Definition: set.hh:784
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:81
Float variables.
Definition: float.hh:874
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:119
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:843
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:44
Home class for posting propagators
Definition: core.hpp:922
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:107
double FloatNum
Floating point number base type.
Definition: float.hh:110
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Equivalence for reification (default)
Definition: int.hh:836
Boolean view for Boolean variables.
Definition: view.hpp:1315