diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend index 229656c0..173be0be 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend | |||
@@ -53,6 +53,10 @@ abstract class Interval implements Comparable<Interval> { | |||
53 | other.mayBeLessThanOrEqual(this) | 53 | other.mayBeLessThanOrEqual(this) |
54 | } | 54 | } |
55 | 55 | ||
56 | abstract def Interval min(Interval other) | ||
57 | |||
58 | abstract def Interval max(Interval other) | ||
59 | |||
56 | abstract def Interval join(Interval other) | 60 | abstract def Interval join(Interval other) |
57 | 61 | ||
58 | def operator_plus() { | 62 | def operator_plus() { |
@@ -88,6 +92,14 @@ abstract class Interval implements Comparable<Interval> { | |||
88 | false | 92 | false |
89 | } | 93 | } |
90 | 94 | ||
95 | override min(Interval other) { | ||
96 | EMPTY | ||
97 | } | ||
98 | |||
99 | override max(Interval other) { | ||
100 | EMPTY | ||
101 | } | ||
102 | |||
91 | override join(Interval other) { | 103 | override join(Interval other) { |
92 | other | 104 | other |
93 | } | 105 | } |
@@ -173,7 +185,7 @@ abstract class Interval implements Comparable<Interval> { | |||
173 | switch (other) { | 185 | switch (other) { |
174 | case EMPTY: true | 186 | case EMPTY: true |
175 | NonEmpty: lower == upper && lower == other.lower && lower == other.upper | 187 | NonEmpty: lower == upper && lower == other.lower && lower == other.upper |
176 | default: throw new IllegalArgumentException("") | 188 | default: throw new IllegalArgumentException("Unknown interval: " + other) |
177 | } | 189 | } |
178 | } | 190 | } |
179 | 191 | ||
@@ -190,7 +202,7 @@ abstract class Interval implements Comparable<Interval> { | |||
190 | switch (other) { | 202 | switch (other) { |
191 | case EMPTY: true | 203 | case EMPTY: true |
192 | NonEmpty: upper !== null && other.lower !== null && upper < other.lower | 204 | NonEmpty: upper !== null && other.lower !== null && upper < other.lower |
193 | default: throw new IllegalArgumentException("") | 205 | default: throw new IllegalArgumentException("Unknown interval: " + other) |
194 | } | 206 | } |
195 | } | 207 | } |
196 | 208 | ||
@@ -202,11 +214,41 @@ abstract class Interval implements Comparable<Interval> { | |||
202 | } | 214 | } |
203 | } | 215 | } |
204 | 216 | ||
217 | override min(Interval other) { | ||
218 | switch (other) { | ||
219 | case EMPTY: this | ||
220 | NonEmpty: min(other) | ||
221 | default: throw new IllegalArgumentException("Unknown interval: " + other) | ||
222 | } | ||
223 | } | ||
224 | |||
225 | def min(NonEmpty other) { | ||
226 | new NonEmpty( | ||
227 | lower.tryMin(other.lower), | ||
228 | if (other.upper === null) upper else upper?.min(other.upper) | ||
229 | ) | ||
230 | } | ||
231 | |||
232 | override max(Interval other) { | ||
233 | switch (other) { | ||
234 | case EMPTY: this | ||
235 | NonEmpty: max(other) | ||
236 | default: throw new IllegalArgumentException("Unknown interval: " + other) | ||
237 | } | ||
238 | } | ||
239 | |||
240 | def max(NonEmpty other) { | ||
241 | new NonEmpty( | ||
242 | if (other.lower === null) lower else lower?.min(other.lower), | ||
243 | upper.tryMax(other.upper) | ||
244 | ) | ||
245 | } | ||
246 | |||
205 | override join(Interval other) { | 247 | override join(Interval other) { |
206 | switch (other) { | 248 | switch (other) { |
207 | case EMPTY: this | 249 | case EMPTY: this |
208 | NonEmpty: new NonEmpty(lower.tryMin(other.lower), upper.tryMax(other.upper)) | 250 | NonEmpty: new NonEmpty(lower.tryMin(other.lower), upper.tryMax(other.upper)) |
209 | default: throw new IllegalArgumentException("") | 251 | default: throw new IllegalArgumentException("Unknown interval: " + other) |
210 | } | 252 | } |
211 | } | 253 | } |
212 | 254 | ||
@@ -218,7 +260,7 @@ abstract class Interval implements Comparable<Interval> { | |||
218 | switch (other) { | 260 | switch (other) { |
219 | case EMPTY: EMPTY | 261 | case EMPTY: EMPTY |
220 | NonEmpty: operator_plus(other) | 262 | NonEmpty: operator_plus(other) |
221 | default: throw new IllegalArgumentException("") | 263 | default: throw new IllegalArgumentException("Unknown interval: " + other) |
222 | } | 264 | } |
223 | } | 265 | } |
224 | 266 | ||
@@ -241,7 +283,7 @@ abstract class Interval implements Comparable<Interval> { | |||
241 | switch (other) { | 283 | switch (other) { |
242 | case EMPTY: EMPTY | 284 | case EMPTY: EMPTY |
243 | NonEmpty: operator_minus(other) | 285 | NonEmpty: operator_minus(other) |
244 | default: throw new IllegalArgumentException("") | 286 | default: throw new IllegalArgumentException("Unknown interval: " + other) |
245 | } | 287 | } |
246 | } | 288 | } |
247 | 289 | ||
@@ -369,7 +411,7 @@ abstract class Interval implements Comparable<Interval> { | |||
369 | switch (other) { | 411 | switch (other) { |
370 | case EMPTY: EMPTY | 412 | case EMPTY: EMPTY |
371 | NonEmpty: operator_divide(other) | 413 | NonEmpty: operator_divide(other) |
372 | default: throw new IllegalArgumentException("") | 414 | default: throw new IllegalArgumentException("Unknown interval: " + other) |
373 | } | 415 | } |
374 | } | 416 | } |
375 | 417 | ||