aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kris7topher@gmail.com>2019-05-10 12:05:10 -0400
committerLibravatar Kristóf Marussy <kris7topher@gmail.com>2019-05-10 12:12:37 -0400
commit3ab6f907e44d993830bad4d25a8b03811731c481 (patch)
treea1cfc14aef44888542754852472edb261680a335
parentNeutral element for sum is [0, 0] (diff)
downloadVIATRA-Generator-3ab6f907e44d993830bad4d25a8b03811731c481.tar.gz
VIATRA-Generator-3ab6f907e44d993830bad4d25a8b03811731c481.tar.zst
VIATRA-Generator-3ab6f907e44d993830bad4d25a8b03811731c481.zip
More aggregation operators
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/META-INF/MANIFEST.MF1
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/Interval.xtend54
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/IntervalAggregationMode.java24
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/aggregators/IntervalAggregatorFactory.xtend50
4 files changed, 123 insertions, 6 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/META-INF/MANIFEST.MF b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/META-INF/MANIFEST.MF
index 2bc35ae6..b2ee3981 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/META-INF/MANIFEST.MF
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/META-INF/MANIFEST.MF
@@ -5,6 +5,7 @@ Bundle-SymbolicName: hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatraquery;s
5Bundle-Version: 1.0.0.qualifier 5Bundle-Version: 1.0.0.qualifier
6Export-Package: hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra, 6Export-Package: hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra,
7 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval, 7 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval,
8 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.aggregators,
8 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns, 9 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns,
9 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.queries 10 hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.queries
10Require-Bundle: hu.bme.mit.inf.dslreasoner.logic.model;bundle-version="1.0.0", 11Require-Bundle: hu.bme.mit.inf.dslreasoner.logic.model;bundle-version="1.0.0",
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
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/IntervalAggregationMode.java b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/IntervalAggregationMode.java
index 66dcb00f..f106e305 100644
--- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/IntervalAggregationMode.java
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/IntervalAggregationMode.java
@@ -27,6 +27,30 @@ public enum IntervalAggregationMode implements BinaryOperator<Interval> {
27 return Interval.ZERO; 27 return Interval.ZERO;
28 } 28 }
29 }, 29 },
30
31 MIN("intervalMin", "Find the minimum a set of intervals") {
32 @Override
33 public IntervalRedBlackNode createNode(Interval interval) {
34 return new IntervalRedBlackNode(interval) {
35 @Override
36 public Interval op(Interval left, Interval right) {
37 return left.min(right);
38 }
39 };
40 }
41 },
42
43 MAX("intervalMax", "Find the maximum a set of intervals") {
44 @Override
45 public IntervalRedBlackNode createNode(Interval interval) {
46 return new IntervalRedBlackNode(interval) {
47 @Override
48 public Interval op(Interval left, Interval right) {
49 return left.max(right);
50 }
51 };
52 }
53 },
30 54
31 JOIN("intervalJoin", "Calculate the smallest interval containing all the intervals in a set") { 55 JOIN("intervalJoin", "Calculate the smallest interval containing all the intervals in a set") {
32 @Override 56 @Override
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/aggregators/IntervalAggregatorFactory.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/aggregators/IntervalAggregatorFactory.xtend
new file mode 100644
index 00000000..2b6059da
--- /dev/null
+++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/interval/aggregators/IntervalAggregatorFactory.xtend
@@ -0,0 +1,50 @@
1package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.aggregators
2
3import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.Interval
4import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.IntervalAggregationMode
5import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.interval.IntervalAggregationOperator
6import org.eclipse.viatra.query.runtime.matchers.psystem.aggregations.AggregatorType
7import org.eclipse.viatra.query.runtime.matchers.psystem.aggregations.BoundAggregator
8import org.eclipse.viatra.query.runtime.matchers.psystem.aggregations.IAggregatorFactory
9import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
10
11@AggregatorType(parameterTypes = #[Interval], returnTypes = #[Interval])
12abstract class IntervalAggregatorFactory implements IAggregatorFactory {
13 val IntervalAggregationMode mode
14
15 @FinalFieldsConstructor
16 protected new() {
17 }
18
19 override getAggregatorLogic(Class<?> domainClass) {
20 if (domainClass == Interval) {
21 new BoundAggregator(new IntervalAggregationOperator(mode), Interval, Interval)
22 } else {
23 throw new IllegalArgumentException("Unknown domain class: " + domainClass)
24 }
25 }
26}
27
28class intervalSum extends IntervalAggregatorFactory {
29 new() {
30 super(IntervalAggregationMode.SUM)
31 }
32}
33
34class intervalMin extends IntervalAggregatorFactory {
35 new() {
36 super(IntervalAggregationMode.MIN)
37 }
38}
39
40class intervalMax extends IntervalAggregatorFactory {
41 new() {
42 super(IntervalAggregationMode.MAX)
43 }
44}
45
46class intervalJoin extends IntervalAggregatorFactory {
47 new() {
48 super(IntervalAggregationMode.JOIN)
49 }
50}