diff options
Diffstat (limited to 'Solvers')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend index a3977653..e9c155f5 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/PolyhedronScopePropagator.xtend | |||
@@ -104,41 +104,45 @@ class PolyhedronScopePropagator extends ScopePropagator { | |||
104 | } | 104 | } |
105 | 105 | ||
106 | private def populateScopesFromPolyhedron() { | 106 | private def populateScopesFromPolyhedron() { |
107 | checkFiniteBounds(topLevelBounds) | 107 | checkBounds(topLevelBounds) |
108 | if (partialInterpretation.minNewElements > topLevelBounds.lowerBound) { | 108 | if (partialInterpretation.minNewElements > topLevelBounds.lowerBound) { |
109 | throw new IllegalArgumentException('''Lower bound of «topLevelBounds» smaller than top-level scope: «partialInterpretation.minNewElements»''') | 109 | throw new IllegalArgumentException('''Lower bound of «topLevelBounds» smaller than top-level scope: «partialInterpretation.minNewElements»''') |
110 | } else if (partialInterpretation.minNewElements != topLevelBounds.lowerBound) { | 110 | } else if (partialInterpretation.minNewElements != topLevelBounds.lowerBound) { |
111 | partialInterpretation.minNewElements = topLevelBounds.lowerBound | 111 | partialInterpretation.minNewElements = topLevelBounds.lowerBound |
112 | } | 112 | } |
113 | if (partialInterpretation.maxNewElements >= 0 && | 113 | val topLevelUpperBound = topLevelBounds.upperBound ?: -1 |
114 | partialInterpretation.maxNewElements < topLevelBounds.upperBound) { | 114 | if (partialInterpretation.maxNewElements >= 0 && topLevelUpperBound >= 0 && |
115 | partialInterpretation.maxNewElements < topLevelUpperBound) { | ||
115 | throw new IllegalArgumentException('''Upper bound of «topLevelBounds» larger than top-level scope: «partialInterpretation.maxNewElements»''') | 116 | throw new IllegalArgumentException('''Upper bound of «topLevelBounds» larger than top-level scope: «partialInterpretation.maxNewElements»''') |
116 | } else if (partialInterpretation.maxNewElements != topLevelBounds.upperBound) { | 117 | } else if (partialInterpretation.maxNewElements != topLevelUpperBound) { |
117 | partialInterpretation.maxNewElements = topLevelBounds.upperBound | 118 | partialInterpretation.maxNewElements = topLevelUpperBound |
118 | } | 119 | } |
119 | for (pair : scopeBounds.entrySet) { | 120 | for (pair : scopeBounds.entrySet) { |
120 | val scope = pair.key | 121 | val scope = pair.key |
121 | val bounds = pair.value | 122 | val bounds = pair.value |
122 | checkFiniteBounds(bounds) | 123 | checkBounds(bounds) |
123 | if (scope.minNewElements > bounds.lowerBound) { | 124 | if (scope.minNewElements > bounds.lowerBound) { |
124 | throw new IllegalArgumentException('''Lower bound of «bounds» smaller than «scope.targetTypeInterpretation» scope: «scope.minNewElements»''') | 125 | throw new IllegalArgumentException('''Lower bound of «bounds» smaller than «scope.targetTypeInterpretation» scope: «scope.minNewElements»''') |
125 | } else if (scope.minNewElements != bounds.lowerBound) { | 126 | } else if (scope.minNewElements != bounds.lowerBound) { |
126 | scope.minNewElements = bounds.lowerBound | 127 | scope.minNewElements = bounds.lowerBound |
127 | } | 128 | } |
128 | if (scope.maxNewElements >= 0 && scope.maxNewElements < bounds.upperBound) { | 129 | val upperBound = bounds.upperBound ?: -1 |
130 | if (scope.maxNewElements >= 0 && upperBound >= 0 && scope.maxNewElements < upperBound) { | ||
129 | throw new IllegalArgumentException('''Upper bound of «bounds» larger than «scope.targetTypeInterpretation» scope: «scope.maxNewElements»''') | 131 | throw new IllegalArgumentException('''Upper bound of «bounds» larger than «scope.targetTypeInterpretation» scope: «scope.maxNewElements»''') |
130 | } else if (scope.maxNewElements != bounds.upperBound) { | 132 | } else if (scope.maxNewElements != upperBound) { |
131 | scope.maxNewElements = bounds.upperBound | 133 | scope.maxNewElements = upperBound |
132 | } | 134 | } |
133 | } | 135 | } |
134 | } | 136 | } |
135 | 137 | ||
136 | private def checkFiniteBounds(LinearBoundedExpression bounds) { | 138 | private def checkBounds(LinearBoundedExpression bounds) { |
137 | if (bounds.lowerBound === null) { | 139 | if (bounds.lowerBound === null) { |
138 | throw new IllegalArgumentException("Infinite lower bound: " + bounds) | 140 | throw new IllegalArgumentException("Infinite lower bound: " + bounds) |
141 | } else if (bounds.lowerBound < 0) { | ||
142 | throw new IllegalArgumentException("Negative lower bound: " + bounds) | ||
139 | } | 143 | } |
140 | if (bounds.upperBound === null) { | 144 | if (bounds.upperBound !== null && bounds.upperBound < 0) { |
141 | throw new IllegalArgumentException("Infinite upper bound: " + bounds) | 145 | throw new IllegalArgumentException("Negative upper bound: " + bounds) |
142 | } | 146 | } |
143 | } | 147 | } |
144 | 148 | ||