Generated on Fri Jan 28 2022 04:43:06 for Gecode by doxygen 1.8.13
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 
35 #include <gecode/float/rel.hh>
36 
37 namespace Gecode {
38 
39  void
41  using namespace Float;
42  Limits::check(n,"Float::dom");
44  FloatView xv(x);
45  GECODE_ME_FAIL(xv.eq(home,n));
46  }
47 
48  void
49  dom(Home home, const FloatVarArgs& x, FloatVal n) {
50  using namespace Float;
51  Limits::check(n,"Float::dom");
53  for (int i=x.size(); i--; ) {
54  FloatView xv(x[i]);
55  GECODE_ME_FAIL(xv.eq(home,n));
56  }
57  }
58 
59  void
61  using namespace Float;
62  Limits::check(min,"Float::dom");
63  Limits::check(max,"Float::dom");
65  FloatView xv(x);
66  GECODE_ME_FAIL(xv.gq(home,min));
67  GECODE_ME_FAIL(xv.lq(home,max));
68  }
69 
70  void
72  using namespace Float;
73  Limits::check(min,"Float::dom");
74  Limits::check(max,"Float::dom");
76  for (int i=x.size(); i--; ) {
77  FloatView xv(x[i]);
78  GECODE_ME_FAIL(xv.gq(home,min));
79  GECODE_ME_FAIL(xv.lq(home,max));
80  }
81  }
82 
83  void
85  using namespace Float;
86  Limits::check(n,"Float::dom");
88  switch (r.mode()) {
89  case RM_EQV:
90  GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_EQV>
91  ::post(home,x,n,r.var())));
92  break;
93  case RM_IMP:
94  GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_IMP>
95  ::post(home,x,n,r.var())));
96  break;
97  case RM_PMI:
98  GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_PMI>
99  ::post(home,x,n,r.var())));
100  break;
101  default: throw Int::UnknownReifyMode("Float::dom");
102  }
103  }
104 
105  void
107  using namespace Float;
108  if (min > max) {
109  Int::BoolView b(r.var());
110  switch (r.mode()) {
111  case RM_EQV:
112  case RM_IMP:
113  GECODE_ME_FAIL(b.zero(home));
114  break;
115  case RM_PMI:
116  break;
117  default: throw Int::UnknownReifyMode("Float::dom");
118  }
119  } else {
120  FloatVal n(min,max);
121  dom(home,x,n,r);
122  }
123  }
124 
125  void
127  using namespace Float;
128  GECODE_POST;
129  FloatView xv(x), dv(d);
130  if (xv != dv) {
131  GECODE_ME_FAIL(xv.lq(home,dv.max()));
132  GECODE_ME_FAIL(xv.gq(home,dv.min()));
133  }
134  }
135 
136  void
137  dom(Home home, const FloatVarArgs& x, const FloatVarArgs& d) {
138  using namespace Float;
139  if (x.size() != d.size())
140  throw ArgumentSizeMismatch("Float::dom");
141  for (int i=x.size(); i--; ) {
142  GECODE_POST;
143  FloatView xv(x[i]), dv(d[i]);
144  if (xv != dv) {
145  GECODE_ME_FAIL(xv.lq(home,dv.max()));
146  GECODE_ME_FAIL(xv.gq(home,dv.min()));
147  }
148  }
149  }
150 
151 }
152 
153 // STATISTICS: float-post
154 
Inverse implication for reification.
Definition: int.hh:869
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1569
ReifyMode mode(void) const
Return reification mode.
Definition: reify.hpp:56
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:49
Passing float variables.
Definition: float.hh:979
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:40
Gecode::IntSet d(r, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Reification specification.
Definition: int.hh:876
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
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:44
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
Float value type.
Definition: float.hh:334
BoolVar var(void) const
Return Boolean control variable.
Definition: reify.hpp:48
Post propagator for SetVar x
Definition: set.hh:767
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:77
Float variables.
Definition: float.hh:870
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:115
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:862
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
Home class for posting propagators
Definition: core.hpp:853
Exception: Arguments are of different size
Definition: exception.hpp:73
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
double FloatNum
Floating point number base type.
Definition: float.hh:106
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138
Equivalence for reification (default)
Definition: int.hh:855
Boolean view for Boolean variables.
Definition: view.hpp:1380