diff options
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend index 3e8b3366..b8c52af4 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/Constraint2Logic.xtend | |||
@@ -30,10 +30,20 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeCo | |||
30 | 30 | ||
31 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 31 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint | 32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint |
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint | ||
34 | import org.eclipse.viatra.query.runtime.matchers.aggregators.DoubleSumOperator | ||
35 | import org.eclipse.viatra.query.runtime.matchers.aggregators.IntegerSumOperator | ||
36 | import org.eclipse.viatra.query.runtime.matchers.aggregators.LongSumOperator | ||
37 | import org.eclipse.viatra.query.runtime.matchers.aggregators.ExtremumOperator | ||
38 | import org.eclipse.viatra.query.runtime.matchers.aggregators.ExtremumOperator.Extreme | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation | ||
33 | 41 | ||
34 | class Constraint2Logic { | 42 | class Constraint2Logic { |
35 | val extension LogicProblemBuilder builder = new LogicProblemBuilder | 43 | val extension LogicProblemBuilder builder = new LogicProblemBuilder |
36 | val Ecore2Logic ecore2Logic | 44 | val Ecore2Logic ecore2Logic |
45 | val ExpressionEvaluation2Logic expressionEvaliation2Logic = new ExpressionEvaluation2Logic | ||
46 | val expressionExtractor = new XExpressionExtractor | ||
37 | 47 | ||
38 | new(Ecore2Logic ecore2Logic) { | 48 | new(Ecore2Logic ecore2Logic) { |
39 | this.ecore2Logic = ecore2Logic | 49 | this.ecore2Logic = ecore2Logic |
@@ -269,6 +279,69 @@ class Constraint2Logic { | |||
269 | } else throw new IllegalArgumentException('''unknown tuple: «tuple»''') | 279 | } else throw new IllegalArgumentException('''unknown tuple: «tuple»''') |
270 | } | 280 | } |
271 | 281 | ||
282 | def dispatch Term transformConstraint(AggregatorConstraint constraint, | ||
283 | TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, | ||
284 | Viatra2LogicTrace viatra2LogicTrace, | ||
285 | Map<PVariable, Variable> variable2Variable, | ||
286 | Viatra2LogicConfiguration config) | ||
287 | { | ||
288 | val logicReferred = constraint.referredQuery.lookup(viatra2LogicTrace.query2Relation) | ||
289 | val parameterSubstitution = new LinkedList | ||
290 | for(index : 0..<constraint.actualParametersTuple.size) { | ||
291 | val term = (constraint.actualParametersTuple.get(index) as PVariable).lookup(variable2Variable) | ||
292 | parameterSubstitution += term | ||
293 | } | ||
294 | val aggregatorIndex = constraint.aggregatedColumn | ||
295 | val logicResultVariable = constraint.resultVariable.lookup(variable2Variable) | ||
296 | val type = constraint.aggregator.operator | ||
297 | if(type === null) { | ||
298 | return Count(logicReferred,parameterSubstitution,logicResultVariable) | ||
299 | } else if(type instanceof IntegerSumOperator || type instanceof DoubleSumOperator || type instanceof LongSumOperator){ | ||
300 | return Sum(logicReferred,parameterSubstitution,aggregatorIndex,logicResultVariable) | ||
301 | } else if(type instanceof ExtremumOperator) { | ||
302 | if(type.name == Extreme.MIN.name.toLowerCase) { | ||
303 | return Min(logicReferred,parameterSubstitution,aggregatorIndex,logicResultVariable) | ||
304 | } else if(type.name == Extreme.MAX.name.toLowerCase){ | ||
305 | return Max(logicReferred,parameterSubstitution,aggregatorIndex,logicResultVariable) | ||
306 | } else { | ||
307 | throw new UnsupportedOperationException('''Unkown Extremum aggregator type: «type.name»''') | ||
308 | } | ||
309 | } else { | ||
310 | throw new UnsupportedOperationException('''Unkown aggregator type: «type.name»''') | ||
311 | } | ||
312 | } | ||
313 | |||
314 | def dispatch Term transformConstraint(PatternMatchCounter constraint, | ||
315 | TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, | ||
316 | Viatra2LogicTrace viatra2LogicTrace, | ||
317 | Map<PVariable, Variable> variable2Variable, | ||
318 | Viatra2LogicConfiguration config) | ||
319 | { | ||
320 | val logicReferred = constraint.referredQuery.lookup(viatra2LogicTrace.query2Relation) | ||
321 | val parameterSubstitution = new LinkedList | ||
322 | for(index : 0..<constraint.actualParametersTuple.size) { | ||
323 | val term = (constraint.actualParametersTuple.get(index) as PVariable).lookup(variable2Variable) | ||
324 | parameterSubstitution += term | ||
325 | } | ||
326 | val logicResultVariable = constraint.resultVariable.lookup(variable2Variable) | ||
327 | return Count(logicReferred,parameterSubstitution,logicResultVariable) | ||
328 | } | ||
329 | |||
330 | def dispatch Term transformConstraint(ExpressionEvaluation constraint, | ||
331 | TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, | ||
332 | Viatra2LogicTrace viatra2LogicTrace, | ||
333 | Map<PVariable, Variable> variable2Variable, | ||
334 | Viatra2LogicConfiguration config) | ||
335 | { | ||
336 | val outputVariable = constraint.outputVariable | ||
337 | val expression = expressionExtractor.extractExpression(constraint.evaluator) | ||
338 | if(outputVariable === null) { | ||
339 | return expressionEvaliation2Logic.transformCheck(expression,variable2Variable) | ||
340 | } else { | ||
341 | return expressionEvaliation2Logic.transformEval(outputVariable,expression,variable2Variable) | ||
342 | } | ||
343 | } | ||
344 | |||
272 | def dispatch Term transformConstraint(PConstraint constraint, | 345 | def dispatch Term transformConstraint(PConstraint constraint, |
273 | TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, | 346 | TracedOutput<LogicProblem, Ecore2Logic_Trace> ecore2LogicTrace, |
274 | Viatra2LogicTrace viatra2LogicTrace, | 347 | Viatra2LogicTrace viatra2LogicTrace, |