diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronSolver.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronSolver.xtend | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronSolver.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronSolver.xtend new file mode 100644 index 00000000..9c6cb82e --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronSolver.xtend | |||
@@ -0,0 +1,123 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality | ||
2 | |||
3 | import java.util.List | ||
4 | import java.util.Map | ||
5 | import org.eclipse.xtend.lib.annotations.Accessors | ||
6 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
7 | |||
8 | interface PolyhedronSolver { | ||
9 | def PolyhedronSaturationOperator createSaturationOperator(Polyhedron polyhedron) | ||
10 | } | ||
11 | |||
12 | enum PolyhedronSaturationResult { | ||
13 | SATURATED, | ||
14 | EMPTY, | ||
15 | UNKNOWN | ||
16 | } | ||
17 | |||
18 | interface PolyhedronSaturationOperator extends AutoCloseable { | ||
19 | def Polyhedron getPolyhedron() | ||
20 | |||
21 | def PolyhedronSaturationResult saturate() | ||
22 | } | ||
23 | |||
24 | @FinalFieldsConstructor | ||
25 | @Accessors | ||
26 | class Polyhedron { | ||
27 | /** | ||
28 | * The list of dimensions (variables) for this polyhedron. | ||
29 | * | ||
30 | * This list must not be modified after the polyhedron was created. | ||
31 | * However, lower and upper bounds of the dimensions may be changed. | ||
32 | * | ||
33 | * Names of dimensions in this list are assumed to be unique. | ||
34 | */ | ||
35 | val List<Dimension> dimensions | ||
36 | |||
37 | /** | ||
38 | * The list of constraints defining this polyhedron. | ||
39 | * | ||
40 | * The list and its elements may be freely modified. | ||
41 | */ | ||
42 | val List<LinearConstraint> constraints | ||
43 | |||
44 | /** | ||
45 | * The list of constraints that should be saturated (tightened) | ||
46 | * when a {@link PolyhedronSaturationOperator} is invoked. | ||
47 | * | ||
48 | * This list may be freely modified. | ||
49 | * | ||
50 | * Place all dimensions and constraints here to saturate all the bounds. | ||
51 | */ | ||
52 | val List<LinearBoundedExpression> expressionsToSaturate | ||
53 | |||
54 | override toString() ''' | ||
55 | Dimensions: | ||
56 | «FOR dimension : dimensions» | ||
57 | «dimension» | ||
58 | «ENDFOR» | ||
59 | Constraints: | ||
60 | «FOR constraint : constraints» | ||
61 | «constraint» | ||
62 | «ENDFOR» | ||
63 | ''' | ||
64 | |||
65 | } | ||
66 | |||
67 | @Accessors | ||
68 | abstract class LinearBoundedExpression { | ||
69 | var Integer lowerBound | ||
70 | var Integer upperBound | ||
71 | |||
72 | def void tightenLowerBound(Integer tighterBound) { | ||
73 | if (lowerBound === null || (tighterBound !== null && lowerBound < tighterBound)) { | ||
74 | lowerBound = tighterBound | ||
75 | } | ||
76 | } | ||
77 | |||
78 | def void tightenUpperBound(Integer tighterBound) { | ||
79 | if (upperBound === null || (tighterBound !== null && upperBound > tighterBound)) { | ||
80 | upperBound = tighterBound | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | |||
85 | @Accessors | ||
86 | class Dimension extends LinearBoundedExpression { | ||
87 | val String name | ||
88 | |||
89 | @FinalFieldsConstructor | ||
90 | new() { | ||
91 | } | ||
92 | |||
93 | new(String name, Integer lowerBound, Integer upperBound) { | ||
94 | this(name) | ||
95 | this.lowerBound = lowerBound | ||
96 | this.upperBound = upperBound | ||
97 | } | ||
98 | |||
99 | override toString() { | ||
100 | '''«IF lowerBound !== null»«lowerBound» <= «ENDIF»«name»«IF upperBound !== null» <= «upperBound»«ENDIF»''' | ||
101 | } | ||
102 | |||
103 | } | ||
104 | |||
105 | @Accessors | ||
106 | class LinearConstraint extends LinearBoundedExpression { | ||
107 | val Map<Dimension, Integer> coefficients | ||
108 | |||
109 | @FinalFieldsConstructor | ||
110 | new() { | ||
111 | } | ||
112 | |||
113 | new(Map<Dimension, Integer> coefficients, Integer lowerBound, Integer upperBound) { | ||
114 | this(coefficients) | ||
115 | this.lowerBound = lowerBound | ||
116 | this.upperBound = upperBound | ||
117 | } | ||
118 | |||
119 | override toString() { | ||
120 | '''«IF lowerBound !== null»«lowerBound» <= «ENDIF»«FOR pair : coefficients.entrySet SEPARATOR " + "»«IF pair.value != 1»«pair.value» * «ENDIF»«pair.key.name»«ENDFOR»«IF upperBound !== null» <= «upperBound»«ENDIF»''' | ||
121 | } | ||
122 | |||
123 | } | ||