aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu
diff options
context:
space:
mode:
authorLibravatar Oszkar Semerath <semerath@mit.bme.hu>2019-07-15 17:31:00 +0200
committerLibravatar Oszkar Semerath <semerath@mit.bme.hu>2019-07-15 17:31:00 +0200
commit539618ccaedfe05d5d62971c8fd0578f5ff3d040 (patch)
tree43d07de9773db3bc6ab71021c530b205680315c4 /Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu
parentaggregated partial substitution + builder (diff)
downloadVIATRA-Generator-539618ccaedfe05d5d62971c8fd0578f5ff3d040.tar.gz
VIATRA-Generator-539618ccaedfe05d5d62971c8fd0578f5ff3d040.tar.zst
VIATRA-Generator-539618ccaedfe05d5d62971c8fd0578f5ff3d040.zip
parsing count, min, max, check and eval v1
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu')
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend40
1 files changed, 26 insertions, 14 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend
index 09bfbb39..a231af3c 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/logic/model/builder/LogicProblemBuilder.xtend
@@ -478,6 +478,7 @@ class LogicProblemBuilder{
478 def %(TermDescription left, TermDescription right) { Modulo(left,right) } 478 def %(TermDescription left, TermDescription right) { Modulo(left,right) }
479 def Modulo(TermDescription left, TermDescription right) { createMod => [leftOperand = left.toTerm rightOperand = right.toTerm]} 479 def Modulo(TermDescription left, TermDescription right) { createMod => [leftOperand = left.toTerm rightOperand = right.toTerm]}
480 480
481 def Pow(TermDescription left, TermDescription right) {createPow => [leftOperand = left.toTerm rightOperand = right.toTerm]}
481 def asTerm(boolean value) { createBoolLiteral => [x|x.value = value] } 482 def asTerm(boolean value) { createBoolLiteral => [x|x.value = value] }
482 def asTerm(int value) { createIntLiteral => [x|x.value = value] } 483 def asTerm(int value) { createIntLiteral => [x|x.value = value] }
483 def asTerm(double value) { BigDecimal.valueOf(value).asTerm } 484 def asTerm(double value) { BigDecimal.valueOf(value).asTerm }
@@ -530,27 +531,28 @@ class LogicProblemBuilder{
530 531
531 // AggregatedExpression 532 // AggregatedExpression
532 533
533 private def <T extends AggregateExpression> configureAggregateExpression(T expression, Relation referred, List<Variable> terms) { 534 private def <T extends AggregateExpression> configureAggregateExpression(T expression, Relation referred, List<Variable> terms, Variable target) {
534 if(terms.size != referred.parameters.size) { 535 if(terms.size != referred.parameters.size) {
535 throw new LogicProblemBuilderException( 536 throw new LogicProblemBuilderException(
536 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''') 537 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''')
537 } else { 538 } else {
538 expression.relation = referred 539 expression.relation = referred
540 expression.resultVariable = target
539 for(var i=0; i<referred.parameters.size;i++) { 541 for(var i=0; i<referred.parameters.size;i++) {
540 val target = terms.get(i) 542 val targetRelation = terms.get(i)
541 val substitution = createAggregatedParameterSubstitution => [it.variable = target] 543 val substitution = createAggregatedParameterSubstitution => [it.variable = targetRelation]
542 expression.parameterSubstitution += substitution 544 expression.parameterSubstitution += substitution
543 } 545 }
544 return expression 546 return expression
545 } 547 }
546 } 548 }
547 private def <T extends ProjectedAggregateExpression> configureProjectedAggregateExpression(T expression, Relation referred, List<Variable> terms, int projection) { 549 private def <T extends ProjectedAggregateExpression> configureProjectedAggregateExpression(T expression, Relation referred, List<Variable> terms, Variable target, int projection) {
548 if(projection < 0 || projection >= referred.parameters.size) { 550 if(projection < 0 || projection >= referred.parameters.size) {
549 throw new LogicProblemBuilderException( 551 throw new LogicProblemBuilderException(
550 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''') 552 '''The function called has «referred.parameters.size» parameters but it is called with «terms.size»!''')
551 } else { 553 } else {
552 val res = expression.configureAggregateExpression(referred, terms) 554 val res = expression.configureAggregateExpression(referred, terms,target)
553 if(res.parameterSubstitution.get(projection) !== null) { 555 if(res.parameterSubstitution.get(projection).variable !== null) {
554 throw new LogicProblemBuilderException( 556 throw new LogicProblemBuilderException(
555 '''Projection over set variable!''') 557 '''Projection over set variable!''')
556 } 558 }
@@ -564,10 +566,18 @@ class LogicProblemBuilder{
564 } 566 }
565 567
566 } 568 }
567 def Count(Relation referred, List<Variable> terms) { createCount.configureAggregateExpression(referred,terms) } 569 def Count(Relation referred, List<Variable> terms, Variable result) {
568 def Sum(Relation referred, List<Variable> terms, int projection) { createSum.configureProjectedAggregateExpression(referred,terms,projection) } 570 createCount.configureAggregateExpression(referred,terms,result)
569 def Min(Relation referred, List<Variable> terms, int projection) { createMin.configureProjectedAggregateExpression(referred,terms,projection) } 571 }
570 def Max(Relation referred, List<Variable> terms, int projection) { createMax.configureProjectedAggregateExpression(referred,terms,projection) } 572 def Sum(Relation referred, List<Variable> terms, int projection, Variable result) {
573 createSum.configureProjectedAggregateExpression(referred,terms,result,projection)
574 }
575 def Min(Relation referred, List<Variable> terms, int projection, Variable result) {
576 createMin.configureProjectedAggregateExpression(referred,terms,result,projection)
577 }
578 def Max(Relation referred, List<Variable> terms, int projection, Variable result) {
579 createMax.configureProjectedAggregateExpression(referred,terms,result,projection)
580 }
571 581
572 // Function calls 582 // Function calls
573 def call(Function function, TermDescription... substitutions) { 583 def call(Function function, TermDescription... substitutions) {
@@ -592,17 +602,19 @@ class LogicProblemBuilder{
592 def call(Relation relation, TermDescription... substitution) { relation.call(substitution as Iterable<? extends TermDescription>)} 602 def call(Relation relation, TermDescription... substitution) { relation.call(substitution as Iterable<? extends TermDescription>)}
593 def call(Relation relation, Iterable<? extends TermDescription> substitution) { 603 def call(Relation relation, Iterable<? extends TermDescription> substitution) {
594 val relationReference = createSymbolicValue 604 val relationReference = createSymbolicValue
605 if(relation === null) {
606 throw new LogicProblemBuilderException('''Call is referring to null!''')
607 }
595 relationReference.symbolicReference = relation 608 relationReference.symbolicReference = relation
596 //println('''«relation.name»(«substitution.size»->«relation.parameters»)''')
597 for(value : substitution) 609 for(value : substitution)
598 relationReference.parameterSubstitutions += value.toTerm 610 relationReference.parameterSubstitutions += value.toTerm
599 relationReference.checkRelationCall(relation) 611 relationReference.checkRelationCall(relation)
600 return relationReference 612 return relationReference
601 } 613 }
602 def private checkRelationCall(SymbolicValue value, Relation referredRelation) { 614 def private checkRelationCall(SymbolicValue value, Relation referredRelation) {
603// if(value === null || referredRelation === null) { 615 if(value === null || referredRelation === null) {
604// println("gebasz") 616 throw new LogicProblemBuilderException('''Call is referring to null!''')
605// } 617 }
606 if(value.parameterSubstitutions.size != referredRelation.parameters.size) { 618 if(value.parameterSubstitutions.size != referredRelation.parameters.size) {
607 throw new LogicProblemBuilderException( 619 throw new LogicProblemBuilderException(
608 '''The relation "«referredRelation.name»" called has «referredRelation.parameters.size» parameters but it is called with «value.parameterSubstitutions.size»!''') 620 '''The relation "«referredRelation.name»" called has «referredRelation.parameters.size» parameters but it is called with «value.parameterSubstitutions.size»!''')