diff options
author | 2020-05-07 19:22:16 +0200 | |
---|---|---|
committer | 2020-05-07 19:22:16 +0200 | |
commit | a2ba6b5addbc82a635af4f90195581c08f9913c0 (patch) | |
tree | 00f60f337c3e3ead27b91e94b57c6958888bea8c /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns | |
parent | viatra parsing fixes (diff) | |
download | VIATRA-Generator-a2ba6b5addbc82a635af4f90195581c08f9913c0.tar.gz VIATRA-Generator-a2ba6b5addbc82a635af4f90195581c08f9913c0.tar.zst VIATRA-Generator-a2ba6b5addbc82a635af4f90195581c08f9913c0.zip |
multiple object additions fixes
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, 26 insertions, 12 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 608ab994..5ca78e97 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 | |||
@@ -143,7 +143,13 @@ class PConstraintTransformer { | |||
143 | return referPattern(pcall.referredQuery,params,modality,true,true) | 143 | return referPattern(pcall.referredQuery,params,modality,true,true) |
144 | } | 144 | } |
145 | dispatch def transformConstraint(ExportedParameter e, Modality modality, List<VariableMapping> variableMapping) { | 145 | dispatch def transformConstraint(ExportedParameter e, Modality modality, List<VariableMapping> variableMapping) { |
146 | return '''// «e.parameterName» is exported''' | 146 | val v1 = '''var_«e.parameterName»''' |
147 | val v2 = e.parameterVariable.canonizeName | ||
148 | if(v1.compareTo(v2) == 0) { | ||
149 | return '''// «v1» exported''' | ||
150 | } else { | ||
151 | return '''«v1» == «v2»;''' | ||
152 | } | ||
147 | } | 153 | } |
148 | dispatch def transformConstraint(ConstantValue c, Modality modality, List<VariableMapping> variableMapping) { | 154 | dispatch def transformConstraint(ConstantValue c, Modality modality, List<VariableMapping> variableMapping) { |
149 | val target = c.supplierKey | 155 | val target = c.supplierKey |
@@ -189,24 +195,29 @@ class PConstraintTransformer { | |||
189 | def hasValue(PVariable v, String target, Modality m, List<VariableMapping> variableMapping) { | 195 | def hasValue(PVariable v, String target, Modality m, List<VariableMapping> variableMapping) { |
190 | val typeReference = variableMapping.filter[it.sourcePVariable === v].head.targetLogicVariable.range as PrimitiveTypeReference | 196 | val typeReference = variableMapping.filter[it.sourcePVariable === v].head.targetLogicVariable.range as PrimitiveTypeReference |
191 | if(m.isMay) { | 197 | if(m.isMay) { |
192 | '''PrimitiveElement.valueSet(«v.canonizeName»,«v.valueSetted»); «hasValueExpression(typeReference,v,v.valueVariable)» check(!«v.valueSetted»||«v.valueVariable»==«target»));''' | 198 | '''PrimitiveElement.valueSet(«v.canonizeName»,«v.valueSetted»); «hasValueExpressionByRef(typeReference,v,v.valueVariable)» check(!«v.valueSetted»||«v.valueVariable»==«target»));''' |
193 | } else { // Must or current | 199 | } else { // Must or current |
194 | '''PrimitiveElement.valueSet(«v.canonizeName»,true);«hasValueExpression(typeReference,v,target)»''' | 200 | '''PrimitiveElement.valueSet(«v.canonizeName»,true);«hasValueExpressionByRef(typeReference,v,target)»''' |
195 | } | 201 | } |
196 | } | 202 | } |
197 | 203 | ||
198 | private def hasValueExpression(List<VariableMapping> variableMapping, PVariable v, String target) { | 204 | private def hasValueExpression(List<VariableMapping> variableMapping, PVariable v, String target) { |
199 | hasValueExpression( | 205 | val mapping = variableMapping.filter[ |
200 | variableMapping.filter[it.sourcePVariable === v].head.targetLogicVariable.range, | 206 | val v2 = (it.sourcePVariable as PVariable) |
207 | v2 === v | ||
208 | ].head | ||
209 | val range = mapping.targetLogicVariable.range | ||
210 | hasValueExpressionByRef( | ||
211 | range, | ||
201 | v, | 212 | v, |
202 | target | 213 | target |
203 | ) | 214 | ) |
204 | } | 215 | } |
205 | private def dispatch hasValueExpression(BoolTypeReference typeReference, PVariable v, String target) '''BooleanElement.value(«v.canonizeName»,«target»);''' | 216 | private def dispatch hasValueExpressionByRef(BoolTypeReference typeReference, PVariable v, String target) '''BooleanElement.value(«v.canonizeName»,«target»);''' |
206 | private def dispatch hasValueExpression(IntTypeReference typeReference, PVariable v, String target) '''IntegerElement.value(«v.canonizeName»,«target»);''' | 217 | private def dispatch hasValueExpressionByRef(IntTypeReference typeReference, PVariable v, String target) '''IntegerElement.value(«v.canonizeName»,«target»);''' |
207 | private def dispatch hasValueExpression(RealTypeReference typeReference, PVariable v, String target) '''RealElement.value(«v.canonizeName»,«target»);''' | 218 | private def dispatch hasValueExpressionByRef(RealTypeReference typeReference, PVariable v, String target) '''RealElement.value(«v.canonizeName»,«target»);''' |
208 | private def dispatch hasValueExpression(StringTypeReference typeReference, PVariable v, String target) '''StringElement.value(«v.canonizeName»,«target»);''' | 219 | private def dispatch hasValueExpressionByRef(StringTypeReference typeReference, PVariable v, String target) '''StringElement.value(«v.canonizeName»,«target»);''' |
209 | private def dispatch hasValueExpression(TypeReference typeReference, PVariable v, String target) { | 220 | private def dispatch hasValueExpressionByRef(TypeReference typeReference, PVariable v, String target) { |
210 | throw new UnsupportedOperationException('''Unsupported primitive type reference: «typeReference.class»''') | 221 | throw new UnsupportedOperationException('''Unsupported primitive type reference: «typeReference.class»''') |
211 | } | 222 | } |
212 | 223 | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend index bd6e3e6e..37950834 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend | |||
@@ -10,6 +10,7 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.Binary | |||
10 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery | 10 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery |
11 | 11 | ||
12 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 12 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
13 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction | ||
13 | 14 | ||
14 | class RelationDefinitionIndexer { | 15 | class RelationDefinitionIndexer { |
15 | public val PatternGenerator base; | 16 | public val PatternGenerator base; |
@@ -23,7 +24,8 @@ class RelationDefinitionIndexer { | |||
23 | def generateRelationDefinitions( | 24 | def generateRelationDefinitions( |
24 | LogicProblem problem, | 25 | LogicProblem problem, |
25 | Iterable<RelationDefinition> relations, | 26 | Iterable<RelationDefinition> relations, |
26 | Map<String,PQuery> fqn2PQuery) { | 27 | Map<String,PQuery> fqn2PQuery) |
28 | { | ||
27 | val relation2PQuery = relations.toInvertedMap[ | 29 | val relation2PQuery = relations.toInvertedMap[ |
28 | annotations.filter(TransfomedViatraQuery).head.patternFullyQualifiedName.lookup(fqn2PQuery) | 30 | annotations.filter(TransfomedViatraQuery).head.patternFullyQualifiedName.lookup(fqn2PQuery) |
29 | ] | 31 | ] |
@@ -67,11 +69,12 @@ class RelationDefinitionIndexer { | |||
67 | 69 | ||
68 | private def transformPattern(RelationDefinition relation, PQuery p, Modality modality) { | 70 | private def transformPattern(RelationDefinition relation, PQuery p, Modality modality) { |
69 | try { | 71 | try { |
72 | val bodies = (relation.annotations.filter(TransfomedViatraQuery).head.optimizedDisjunction as PDisjunction).bodies | ||
70 | return ''' | 73 | return ''' |
71 | private pattern «relationDefinitionName(relation,modality)»( | 74 | private pattern «relationDefinitionName(relation,modality)»( |
72 | problem:LogicProblem, interpretation:PartialInterpretation, | 75 | problem:LogicProblem, interpretation:PartialInterpretation, |
73 | «FOR param : p.parameters SEPARATOR ', '»var_«param.name»«ENDFOR») | 76 | «FOR param : p.parameters SEPARATOR ', '»var_«param.name»«ENDFOR») |
74 | «FOR body : p.disjunctBodies.bodies SEPARATOR "or"»{ | 77 | «FOR body : bodies SEPARATOR "or"»{ |
75 | find interpretation(problem,interpretation); | 78 | find interpretation(problem,interpretation); |
76 | «FOR constraint : body.constraints» | 79 | «FOR constraint : body.constraints» |
77 | «this.constraintTransformer.transformConstraint(constraint,modality,relation.annotations.filter(TransfomedViatraQuery).head.variableTrace)» | 80 | «this.constraintTransformer.transformConstraint(constraint,modality,relation.annotations.filter(TransfomedViatraQuery).head.variableTrace)» |