Generated on Tue Mar 24 2020 14:04:04 for Gecode by doxygen 1.8.17
scale.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  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6  *
7  * Copyright:
8  * Christian Schulte, 2002
9  * Vincent Barichard, 2012
10  *
11  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 namespace Gecode { namespace Float {
37 
38  /*
39  * Constructors and initialization
40  *
41  */
46  : DerivedView<FloatView>(y), a(d) {}
47 
48 
49  /*
50  * Value access
51  *
52  */
54  ScaleView::scale(void) const {
55  return a;
56  }
58  ScaleView::domain(void) const {
59  return x.domain()*a;
60  }
62  ScaleView::min(void) const {
63  FloatVal c = x.min(); c *= a; return c.min();
64  }
66  ScaleView::max(void) const {
67  FloatVal c = x.max(); c *= a; return c.max();
68  }
70  ScaleView::med(void) const {
71  FloatVal c = x.med(); c *= a; return (c.min()+c.max())/2;
72  }
74  ScaleView::val(void) const {
75  FloatVal c = x.val(); c *= a; return c;
76  }
77 
79  ScaleView::size(void) const {
80  FloatVal c = x.size(); c *= a; return c.max();
81  }
82 
83 
84  /*
85  * Domain tests
86  *
87  */
88  forceinline bool
89  ScaleView::zero_in(void) const {
90  return x.zero_in();
91  }
92  forceinline bool
94  return x.in(n/a);
95  }
96  forceinline bool
97  ScaleView::in(const FloatVal& n) const {
98  return x.in(n/a);
99  }
100 
101 
102  /*
103  * Domain update by value
104  *
105  */
107  ScaleView::lq(Space& home, int n) {
108  FloatVal c = n; c /= a;
109  return x.lq(home,c.max());
110  }
113  FloatVal c = n; c /= a;
114  return x.lq(home,c.max());
115  }
118  FloatVal c = n; c /= a;
119  return x.lq(home,c.max());
120  }
121 
123  ScaleView::gq(Space& home, int n) {
124  FloatVal c = n; c /= a;
125  return x.gq(home,c.min());
126  }
129  FloatVal c = n; c /= a;
130  return x.gq(home,c.min());
131  }
134  FloatVal c = n; c /= a;
135  return x.gq(home,c.min());
136  }
137 
139  ScaleView::eq(Space& home, int n) {
140  FloatVal c = n; c /= a;
141  return x.eq(home,c);
142  }
145  FloatVal c = n; c /= a;
146  return x.eq(home,c);
147  }
149  ScaleView::eq(Space& home, const FloatVal& n) {
150  FloatVal c = n; c /= a;
151  return x.eq(home,c);
152  }
153 
154 
155  /*
156  * Delta information for advisors
157  *
158  */
160  ScaleView::min(const Delta& d) const {
161  FloatVal c = x.min(d); c *= a; return c.min();
162  }
164  ScaleView::max(const Delta& d) const {
165  FloatVal c = x.max(d); c *= a; return c.max();
166  }
167 
171  }
172 
173 
174  /*
175  * Cloning
176  *
177  */
178  forceinline void
181  a=y.a;
182  }
183 
184  /*
185  * Ordering
186  *
187  */
188  forceinline bool
190  return ((base() < y.base())
191  || ((base() == y.base()) && (scale() < y.scale())));
192  }
193 
194 
195  /*
196  * View comparison
197  *
198  */
199  forceinline bool
200  operator ==(const ScaleView& x, const ScaleView& y) {
201  return (x.base() == y.base()) && (x.scale() == y.scale());
202  }
203  forceinline bool
204  operator !=(const ScaleView& x, const ScaleView& y) {
205  return !(x == y);
206  }
207 
208 }}
209 
210 // STATISTICS: float-var
211 
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:386
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:398
void update(Space &home, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition: view.hpp:681
bool in(FloatNum n) const
Test whether n is contained in domain.
Definition: scale.hpp:93
ScaleView(void)
Default constructor.
Definition: scale.hpp:43
Scale float view.
Definition: view.hpp:395
FloatVal a
Scale factor.
Definition: view.hpp:399
FloatVal val(void) const
Return assigned value.
Definition: scale.hpp:74
Computation spaces.
Definition: core.hpp:1742
void update(Space &home, ScaleView &y)
Definition: scale.hpp:179
Base-class for derived views.
Definition: view.hpp:230
Gecode toplevel namespace
bool operator!=(const MinusView &x, const MinusView &y)
Definition: minus.hpp:169
Float view for float variables.
Definition: view.hpp:52
Generic domain change information to be supplied to advisors.
Definition: core.hpp:204
FloatVal domain(void) const
Return domain.
Definition: scale.hpp:58
FloatNum min(void) const
Return minimum of domain.
Definition: scale.hpp:62
FloatNum max(void) const
Return maximum of domain.
Definition: scale.hpp:66
double FloatNum
Floating point number base type.
Definition: float.hh:106
bool operator==(const MinusView &x, const MinusView &y)
Definition: minus.hpp:165
FloatNum size(void) const
Return size of domain (distance between maximum and minimum)
Definition: scale.hpp:79
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: scale.hpp:139
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
bool zero_in(void) const
Test whether 0 is contained in domain.
Definition: scale.hpp:89
int ModEvent
Type for modification events.
Definition: core.hpp:62
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:639
FloatView x
View from which this view is derived.
Definition: view.hpp:238
Float value type.
Definition: float.hh:334
FloatView base(void) const
Return view from which this view is derived.
Definition: view.hpp:605
Gecode::IntSet d(v, 7)
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: scale.hpp:107
bool operator<(const ScaleView &y) const
Whether this view comes before view y (arbitray order)
Definition: scale.hpp:189
#define forceinline
Definition: config.hpp:185
static ModEventDelta med(ModEvent me)
Translate modification event me to modification event delta for view.
Definition: view.hpp:557
Gecode::FloatVal c(-8, 8)
FloatNum med(void) const
Return median of domain (closest representation)
Definition: scale.hpp:70
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
FloatVal scale(void) const
Return scale factor of scale view.
Definition: scale.hpp:54
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: scale.hpp:123