diff options
author | 2020-05-11 04:06:18 +0200 | |
---|---|---|
committer | 2020-05-11 04:06:18 +0200 | |
commit | 4c80187e223ed4b500a68a5d83446f80565e3440 (patch) | |
tree | a5c1bc9c40dc082ba087791b96992afecc1e885d /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns | |
parent | Satelite case study update for Models-Attribute paper (diff) | |
download | VIATRA-Generator-4c80187e223ed4b500a68a5d83446f80565e3440.tar.gz VIATRA-Generator-4c80187e223ed4b500a68a5d83446f80565e3440.tar.zst VIATRA-Generator-4c80187e223ed4b500a68a5d83446f80565e3440.zip |
Instead of Bigdecimals doubleValue are used in check
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns')
2 files changed, 22 insertions, 13 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PConstraintTransformer.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PConstraintTransformer.xtend index 5ca78e97..423bb204 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PConstraintTransformer.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PConstraintTransformer.xtend | |||
@@ -28,6 +28,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringTypeReference | |||
28 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference | 28 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference |
29 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference | 29 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference |
30 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference | 30 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference |
31 | import java.util.Map | ||
31 | 32 | ||
32 | class PConstraintTransformer { | 33 | class PConstraintTransformer { |
33 | val extension RelationDefinitionIndexer relationDefinitionIndexer; | 34 | val extension RelationDefinitionIndexer relationDefinitionIndexer; |
@@ -226,6 +227,7 @@ class PConstraintTransformer { | |||
226 | throw new UnsupportedOperationException('''Only check expressions are supported "«e.class.name»"!''') | 227 | throw new UnsupportedOperationException('''Only check expressions are supported "«e.class.name»"!''') |
227 | } else { | 228 | } else { |
228 | val expression = expressionExtractor.extractExpression(e.evaluator) | 229 | val expression = expressionExtractor.extractExpression(e.evaluator) |
230 | val Map<PVariable, PrimitiveTypeReference> variable2Type = e.affectedVariables.toInvertedMap[v|variableMapping.filter[it.sourcePVariable === v].head.targetLogicVariable.range as PrimitiveTypeReference] | ||
229 | if(modality.isMay) { | 231 | if(modality.isMay) { |
230 | return ''' | 232 | return ''' |
231 | «FOR variable: e.affectedVariables» | 233 | «FOR variable: e.affectedVariables» |
@@ -234,7 +236,7 @@ class PConstraintTransformer { | |||
234 | check( | 236 | check( |
235 | «FOR variable: e.affectedVariables SEPARATOR " || "»!«variable.valueSetted»«ENDFOR» | 237 | «FOR variable: e.affectedVariables SEPARATOR " || "»!«variable.valueSetted»«ENDFOR» |
236 | || | 238 | || |
237 | («expressionGenerator.translateExpression(expression,e.affectedVariables.toInvertedMap[valueVariable])») | 239 | («expressionGenerator.translateExpression(expression,e.affectedVariables.toInvertedMap[valueVariable],variable2Type)») |
238 | ); | 240 | ); |
239 | ''' | 241 | ''' |
240 | } else { // Must or Current | 242 | } else { // Must or Current |
@@ -242,7 +244,7 @@ class PConstraintTransformer { | |||
242 | «FOR variable: e.affectedVariables» | 244 | «FOR variable: e.affectedVariables» |
243 | PrimitiveElement.valueSet(«variable.canonizeName»,true); «hasValueExpression(variableMapping,variable,variable.valueVariable)» | 245 | PrimitiveElement.valueSet(«variable.canonizeName»,true); «hasValueExpression(variableMapping,variable,variable.valueVariable)» |
244 | «ENDFOR» | 246 | «ENDFOR» |
245 | check(«expressionGenerator.translateExpression(expression,e.affectedVariables.toInvertedMap[valueVariable])»); | 247 | check(«expressionGenerator.translateExpression(expression,e.affectedVariables.toInvertedMap[valueVariable],variable2Type)»); |
246 | ''' | 248 | ''' |
247 | } | 249 | } |
248 | } | 250 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend index 303c87b9..62ff92b2 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PExpressionGenerator.xtend | |||
@@ -8,6 +8,8 @@ import org.eclipse.xtext.xbase.XFeatureCall | |||
8 | import org.eclipse.xtext.xbase.XMemberFeatureCall | 8 | import org.eclipse.xtext.xbase.XMemberFeatureCall |
9 | import org.eclipse.xtext.xbase.XNumberLiteral | 9 | import org.eclipse.xtext.xbase.XNumberLiteral |
10 | import org.eclipse.xtext.xbase.XUnaryOperation | 10 | import org.eclipse.xtext.xbase.XUnaryOperation |
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference | ||
11 | 13 | ||
12 | class PExpressionGenerator { | 14 | class PExpressionGenerator { |
13 | static val N_Base = "org.eclipse.xtext.xbase.lib." | 15 | static val N_Base = "org.eclipse.xtext.xbase.lib." |
@@ -38,9 +40,9 @@ class PExpressionGenerator { | |||
38 | 40 | ||
39 | static val N_POWER2 = "java.lang.Math.pow" | 41 | static val N_POWER2 = "java.lang.Math.pow" |
40 | 42 | ||
41 | def dispatch CharSequence translateExpression(XBinaryOperation e, Map<PVariable,String> valueName) { | 43 | def dispatch CharSequence translateExpression(XBinaryOperation e, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { |
42 | val left = e.leftOperand.translateExpression(valueName) | 44 | val left = e.leftOperand.translateExpression(valueName,variable2Type) |
43 | val right = e.rightOperand.translateExpression(valueName) | 45 | val right = e.rightOperand.translateExpression(valueName,variable2Type) |
44 | val feature = e.feature.qualifiedName | 46 | val feature = e.feature.qualifiedName |
45 | if(feature.isN(N_MINUS2)) { return '''(«left»-«right»)'''} | 47 | if(feature.isN(N_MINUS2)) { return '''(«left»-«right»)'''} |
46 | else if(feature.isN(N_PLUS2)) { return '''(«left»+«right»)''' } | 48 | else if(feature.isN(N_PLUS2)) { return '''(«left»+«right»)''' } |
@@ -65,8 +67,8 @@ class PExpressionGenerator { | |||
65 | } | 67 | } |
66 | } | 68 | } |
67 | 69 | ||
68 | def dispatch CharSequence translateExpression(XUnaryOperation e, Map<PVariable,String> valueName) { | 70 | def dispatch CharSequence translateExpression(XUnaryOperation e, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { |
69 | val operand = e.operand.translateExpression(valueName) | 71 | val operand = e.operand.translateExpression(valueName,variable2Type) |
70 | val feature = e.feature.qualifiedName | 72 | val feature = e.feature.qualifiedName |
71 | if(feature.isN(N_MINUS1)) { return '''(-«operand»)'''} | 73 | if(feature.isN(N_MINUS1)) { return '''(-«operand»)'''} |
72 | else if(feature.isN(N_PLUS1)) { return '''(+«operand»)'''} | 74 | else if(feature.isN(N_PLUS1)) { return '''(+«operand»)'''} |
@@ -78,8 +80,8 @@ class PExpressionGenerator { | |||
78 | } | 80 | } |
79 | } | 81 | } |
80 | 82 | ||
81 | def dispatch CharSequence translateExpression(XMemberFeatureCall e, Map<PVariable,String> valueName) { | 83 | def dispatch CharSequence translateExpression(XMemberFeatureCall e, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { |
82 | val transformedArguments = e.actualArguments.map[translateExpression(valueName)] | 84 | val transformedArguments = e.actualArguments.map[translateExpression(valueName,variable2Type)] |
83 | val feature = e.feature.qualifiedName | 85 | val feature = e.feature.qualifiedName |
84 | if(feature == N_POWER2) { | 86 | if(feature == N_POWER2) { |
85 | return '''Math.pow(«transformedArguments.get(0)»,«transformedArguments.get(1)»)''' | 87 | return '''Math.pow(«transformedArguments.get(0)»,«transformedArguments.get(1)»)''' |
@@ -91,19 +93,24 @@ class PExpressionGenerator { | |||
91 | } | 93 | } |
92 | } | 94 | } |
93 | 95 | ||
94 | def dispatch CharSequence translateExpression(XFeatureCall e, Map<PVariable,String> valueName) { | 96 | def dispatch CharSequence translateExpression(XFeatureCall e, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { |
95 | val featureName = e.feature.qualifiedName | 97 | val featureName = e.feature.qualifiedName |
98 | val type = variable2Type.entrySet.filter[it.key.name===featureName].head.value | ||
96 | val entryWithName = valueName.entrySet.filter[it.key.name == featureName].head | 99 | val entryWithName = valueName.entrySet.filter[it.key.name == featureName].head |
97 | if(entryWithName !== null) { | 100 | if(entryWithName !== null) { |
98 | return entryWithName.value | 101 | if(type instanceof RealTypeReference) { |
102 | return '''(«entryWithName.value».doubleValue)''' | ||
103 | } else { | ||
104 | return entryWithName.value | ||
105 | } | ||
99 | } else { | 106 | } else { |
100 | throw new IllegalArgumentException('''Feature call reference to unavailable variable "«featureName»"''') | 107 | throw new IllegalArgumentException('''Feature call reference to unavailable variable "«featureName»"''') |
101 | } | 108 | } |
102 | } | 109 | } |
103 | 110 | ||
104 | def dispatch CharSequence translateExpression(XNumberLiteral l, Map<PVariable,String> valueName) '''«l.value»''' | 111 | def dispatch CharSequence translateExpression(XNumberLiteral l, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) '''«l.value»''' |
105 | 112 | ||
106 | def dispatch CharSequence translateExpression(XExpression expression, Map<PVariable,String> valueName) { | 113 | def dispatch CharSequence translateExpression(XExpression expression, Map<PVariable,String> valueName, Map<PVariable, PrimitiveTypeReference> variable2Type) { |
107 | throw new UnsupportedOperationException('''Unsupported expression in check or eval: «expression.class.name», «expression»"''') | 114 | throw new UnsupportedOperationException('''Unsupported expression in check or eval: «expression.class.name», «expression»"''') |
108 | } | 115 | } |
109 | } \ No newline at end of file | 116 | } \ No newline at end of file |