this repo has no description
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
36namespace Gecode { namespace Float {
37
38 /*
39 * Constructors and initialization
40 *
41 */
42 forceinline
43 OffsetView::OffsetView(void) {}
44 forceinline
45 OffsetView::OffsetView(const FloatView& y, FloatNum d)
46 : DerivedView<FloatView>(y), c(d) {}
47
48
49 /*
50 * Value access
51 *
52 */
53 forceinline FloatNum
54 OffsetView::offset(void) const {
55 return c;
56 }
57 forceinline void
58 OffsetView::offset(FloatNum n) {
59 c = n;
60 }
61 forceinline FloatVal
62 OffsetView::domain(void) const {
63 return x.domain()+c;
64 }
65 forceinline FloatNum
66 OffsetView::min(void) const {
67 return x.min()+c;
68 }
69 forceinline FloatNum
70 OffsetView::max(void) const {
71 return x.max()+c;
72 }
73 forceinline FloatNum
74 OffsetView::med(void) const {
75 return x.med()+c;
76 }
77 forceinline FloatVal
78 OffsetView::val(void) const {
79 return x.val()+c;
80 }
81
82 forceinline FloatNum
83 OffsetView::size(void) const {
84 return x.size();
85 }
86
87
88 /*
89 * Domain tests
90 *
91 */
92 forceinline bool
93 OffsetView::zero_in(void) const {
94 return x.in(-c);
95 }
96 forceinline bool
97 OffsetView::in(FloatNum n) const {
98 return x.in(n-c);
99 }
100 forceinline bool
101 OffsetView::in(const FloatVal& n) const {
102 return x.in(n-c);
103 }
104
105
106 /*
107 * Domain update by value
108 *
109 */
110 forceinline ModEvent
111 OffsetView::lq(Space& home, int n) {
112 return x.lq(home,n-c);
113 }
114 forceinline ModEvent
115 OffsetView::lq(Space& home, FloatNum n) {
116 return x.lq(home,n-c);
117 }
118 forceinline ModEvent
119 OffsetView::lq(Space& home, FloatVal n) {
120 return x.lq(home,n-c);
121 }
122
123 forceinline ModEvent
124 OffsetView::gq(Space& home, int n) {
125 return x.gq(home,n-c);
126 }
127 forceinline ModEvent
128 OffsetView::gq(Space& home, FloatNum n) {
129 return x.gq(home,n-c);
130 }
131 forceinline ModEvent
132 OffsetView::gq(Space& home, FloatVal n) {
133 return x.gq(home,n-c);
134 }
135
136 forceinline ModEvent
137 OffsetView::eq(Space& home, int n) {
138 return x.eq(home,n-c);
139 }
140 forceinline ModEvent
141 OffsetView::eq(Space& home, FloatNum n) {
142 return x.eq(home,n-c);
143 }
144 forceinline ModEvent
145 OffsetView::eq(Space& home, const FloatVal& n) {
146 return x.eq(home,n-c);
147 }
148
149
150 /*
151 * Delta information for advisors
152 *
153 */
154 forceinline FloatNum
155 OffsetView::min(const Delta& d) const {
156 return x.min(d)+c;
157 }
158 forceinline FloatNum
159 OffsetView::max(const Delta& d) const {
160 return x.max(d)+c;
161 }
162
163 forceinline ModEventDelta
164 OffsetView::med(ModEvent me) {
165 return VarImpView<FloatVar>::med(me);
166 }
167
168
169 /*
170 * Cloning
171 *
172 */
173 forceinline void
174 OffsetView::update(Space& home, OffsetView& y) {
175 DerivedView<FloatView>::update(home,y);
176 c=y.c;
177 }
178
179 /*
180 * Ordering
181 *
182 */
183 forceinline bool
184 OffsetView::operator <(const OffsetView& y) const {
185 return ((base() < y.base())
186 || ((base() == y.base()) && (offset() < y.offset())));
187 }
188
189
190 /*
191 * View comparison
192 *
193 */
194 forceinline bool
195 operator ==(const OffsetView& x, const OffsetView& y) {
196 return (x.base() == y.base()) && (x.offset() == y.offset());
197 }
198 forceinline bool
199 operator !=(const OffsetView& x, const OffsetView& y) {
200 return !(x == y);
201 }
202
203}}
204
205// STATISTICS: float-var
206