diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2019-05-09 00:49:19 -0400 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2019-05-09 00:49:19 -0400 |
commit | 1999ab4733071c6a4c9989c137eb44ec62b09847 (patch) | |
tree | fb4c06a88689e80d4a021bf5ad995a377ed765a6 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src | |
parent | Implement interval arithmetic without exponentiation (diff) | |
download | VIATRA-Generator-1999ab4733071c6a4c9989c137eb44ec62b09847.tar.gz VIATRA-Generator-1999ab4733071c6a4c9989c137eb44ec62b09847.tar.zst VIATRA-Generator-1999ab4733071c6a4c9989c137eb44ec62b09847.zip |
Interval comparison
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend | 101 |
1 files changed, 97 insertions, 4 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 cf22315b..93749767 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 | |||
@@ -13,7 +13,47 @@ abstract class Interval { | |||
13 | private new() { | 13 | private new() { |
14 | } | 14 | } |
15 | 15 | ||
16 | abstract def boolean isZero() | 16 | abstract def boolean mustEqual(Interval other) |
17 | |||
18 | abstract def boolean mayEqual(Interval other) | ||
19 | |||
20 | def mustNotEqual(Interval other) { | ||
21 | !mayEqual(other) | ||
22 | } | ||
23 | |||
24 | def mayNotEqual(Interval other) { | ||
25 | !mustEqual(other) | ||
26 | } | ||
27 | |||
28 | abstract def boolean mustBeLessThan(Interval other) | ||
29 | |||
30 | abstract def boolean mayBeLessThan(Interval other) | ||
31 | |||
32 | def mustBeLessThanOrEqual(Interval other) { | ||
33 | !mayBeGreaterThan(other) | ||
34 | } | ||
35 | |||
36 | def mayBeLessThanOrEqual(Interval other) { | ||
37 | !mustBeGreaterThan(other) | ||
38 | } | ||
39 | |||
40 | def mustBeGreaterThan(Interval other) { | ||
41 | other.mustBeLessThan(this) | ||
42 | } | ||
43 | |||
44 | def mayBeGreaterThan(Interval other) { | ||
45 | other.mayBeLessThan(this) | ||
46 | } | ||
47 | |||
48 | def mustBeGreaterThanOrEqual(Interval other) { | ||
49 | other.mustBeLessThanOrEqual(this) | ||
50 | } | ||
51 | |||
52 | def mayBeGreaterThanOrEqual(Interval other) { | ||
53 | other.mayBeLessThanOrEqual(this) | ||
54 | } | ||
55 | |||
56 | abstract def Interval join(Interval other) | ||
17 | 57 | ||
18 | def operator_plus() { | 58 | def operator_plus() { |
19 | this | 59 | this |
@@ -30,9 +70,25 @@ abstract class Interval { | |||
30 | abstract def Interval operator_divide(Interval other) | 70 | abstract def Interval operator_divide(Interval other) |
31 | 71 | ||
32 | public static val EMPTY = new Interval { | 72 | public static val EMPTY = new Interval { |
33 | override isZero() { | 73 | override mustEqual(Interval other) { |
74 | true | ||
75 | } | ||
76 | |||
77 | override mayEqual(Interval other) { | ||
34 | false | 78 | false |
35 | } | 79 | } |
80 | |||
81 | override mustBeLessThan(Interval other) { | ||
82 | true | ||
83 | } | ||
84 | |||
85 | override mayBeLessThan(Interval other) { | ||
86 | false | ||
87 | } | ||
88 | |||
89 | override join(Interval other) { | ||
90 | other | ||
91 | } | ||
36 | 92 | ||
37 | override operator_minus() { | 93 | override operator_minus() { |
38 | EMPTY | 94 | EMPTY |
@@ -98,8 +154,45 @@ abstract class Interval { | |||
98 | this.upper = upper | 154 | this.upper = upper |
99 | } | 155 | } |
100 | 156 | ||
101 | override isZero() { | 157 | override mustEqual(Interval other) { |
102 | upper == BigDecimal.ZERO && lower == BigDecimal.ZERO | 158 | switch (other) { |
159 | case EMPTY: true | ||
160 | NonEmpty: lower == upper && lower == other.lower && lower == other.upper | ||
161 | default: throw new IllegalArgumentException("") | ||
162 | } | ||
163 | } | ||
164 | |||
165 | override mayEqual(Interval other) { | ||
166 | if (other instanceof NonEmpty) { | ||
167 | (lower === null || other.upper === null || lower <= other.upper) && | ||
168 | (other.lower === null || upper === null || other.lower <= upper) | ||
169 | } else { | ||
170 | false | ||
171 | } | ||
172 | } | ||
173 | |||
174 | override mustBeLessThan(Interval other) { | ||
175 | switch (other) { | ||
176 | case EMPTY: true | ||
177 | NonEmpty: upper !== null && other.lower !== null && upper < other.lower | ||
178 | default: throw new IllegalArgumentException("") | ||
179 | } | ||
180 | } | ||
181 | |||
182 | override mayBeLessThan(Interval other) { | ||
183 | if (other instanceof NonEmpty) { | ||
184 | lower === null || other.upper === null || lower < other.upper | ||
185 | } else { | ||
186 | false | ||
187 | } | ||
188 | } | ||
189 | |||
190 | override join(Interval other) { | ||
191 | switch (other) { | ||
192 | case EMPTY: this | ||
193 | NonEmpty: new NonEmpty(lower.tryMin(other.lower), upper.tryMin(other.upper)) | ||
194 | default: throw new IllegalArgumentException("") | ||
195 | } | ||
103 | } | 196 | } |
104 | 197 | ||
105 | override operator_minus() { | 198 | override operator_minus() { |