diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner')
7 files changed, 56 insertions, 43 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/MultiplicityGoalConstraintCalculator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/MultiplicityGoalConstraintCalculator.xtend index 6435806d..05ce4f6e 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/MultiplicityGoalConstraintCalculator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/MultiplicityGoalConstraintCalculator.xtend | |||
@@ -10,13 +10,15 @@ class MultiplicityGoalConstraintCalculator { | |||
10 | val String targetRelationName; | 10 | val String targetRelationName; |
11 | val IQuerySpecification<?> querySpecification; | 11 | val IQuerySpecification<?> querySpecification; |
12 | var ViatraQueryMatcher<?> matcher; | 12 | var ViatraQueryMatcher<?> matcher; |
13 | val int minValue | ||
13 | val boolean containment | 14 | val boolean containment |
14 | val int cost | 15 | val int cost |
15 | 16 | ||
16 | public new(String targetRelationName, IQuerySpecification<?> querySpecification, boolean containment, int cost) { | 17 | public new(String targetRelationName, IQuerySpecification<?> querySpecification, int minValue, boolean containment, int cost) { |
17 | this.targetRelationName = targetRelationName | 18 | this.targetRelationName = targetRelationName |
18 | this.querySpecification = querySpecification | 19 | this.querySpecification = querySpecification |
19 | this.matcher = null | 20 | this.matcher = null |
21 | this.minValue = minValue | ||
20 | this.containment = containment | 22 | this.containment = containment |
21 | this.cost = cost | 23 | this.cost = cost |
22 | } | 24 | } |
@@ -25,6 +27,7 @@ class MultiplicityGoalConstraintCalculator { | |||
25 | this.targetRelationName = other.targetRelationName | 27 | this.targetRelationName = other.targetRelationName |
26 | this.querySpecification = other.querySpecification | 28 | this.querySpecification = other.querySpecification |
27 | this.matcher = null | 29 | this.matcher = null |
30 | this.minValue = other.minValue | ||
28 | this.containment = other.containment | 31 | this.containment = other.containment |
29 | this.cost = other.cost | 32 | this.cost = other.cost |
30 | } | 33 | } |
@@ -47,13 +50,17 @@ class MultiplicityGoalConstraintCalculator { | |||
47 | val allMatches = this.matcher.allMatches | 50 | val allMatches = this.matcher.allMatches |
48 | for(match : allMatches) { | 51 | for(match : allMatches) { |
49 | 52 | ||
50 | val missingMultiplicity = match.get(4) as Integer | 53 | val existingMultiplicity = match.get(4) as Integer |
51 | res += missingMultiplicity | 54 | if(existingMultiplicity < this.minValue) { |
55 | val missingMultiplicity = this.minValue-existingMultiplicity | ||
56 | res += missingMultiplicity | ||
57 | } | ||
52 | // if(missingMultiplicity!=0) { | 58 | // if(missingMultiplicity!=0) { |
53 | // println(targetRelationName+ " missing multiplicity: "+missingMultiplicity) | 59 | // println(targetRelationName+ " missing multiplicity: "+missingMultiplicity) |
54 | // } | 60 | // } |
55 | } | 61 | } |
56 | //println(targetRelationName+ " all missing multiplicities: "+res) | 62 | // if(res>0) |
63 | // println(targetRelationName+ " all missing multiplicities: "+res + "*"+cost+"="+res*cost) | ||
57 | return res*cost | 64 | return res*cost |
58 | } | 65 | } |
59 | } \ No newline at end of file | 66 | } \ No newline at end of file |
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 a4dcefbf..dd5cade1 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 | |||
@@ -196,7 +196,9 @@ class PConstraintTransformer { | |||
196 | def hasValue(PVariable v, String target, Modality m, List<VariableMapping> variableMapping) { | 196 | def hasValue(PVariable v, String target, Modality m, List<VariableMapping> variableMapping) { |
197 | val typeReference = variableMapping.filter[it.sourcePVariable === v].head.targetLogicVariable.range as PrimitiveTypeReference | 197 | val typeReference = variableMapping.filter[it.sourcePVariable === v].head.targetLogicVariable.range as PrimitiveTypeReference |
198 | if(m.isMay) { | 198 | if(m.isMay) { |
199 | '''PrimitiveElement.valueSet(«v.canonizeName»,«v.valueSetted»); «hasValueExpressionByRef(typeReference,v,v.valueVariable)» check(!«v.valueSetted»||«v.valueVariable»==«target»));''' | 199 | '''PrimitiveElement.valueSet(«v.canonizeName»,«v.valueSetted»); «hasValueExpressionByRef(typeReference,v,v.valueVariable)» |
200 | ««« check(!«v.valueSetted»||«v.valueVariable»==«target»)); | ||
201 | ''' | ||
200 | } else { // Must or current | 202 | } else { // Must or current |
201 | '''PrimitiveElement.valueSet(«v.canonizeName»,true);«hasValueExpressionByRef(typeReference,v,target)»''' | 203 | '''PrimitiveElement.valueSet(«v.canonizeName»,true);«hasValueExpressionByRef(typeReference,v,target)»''' |
202 | } | 204 | } |
@@ -233,13 +235,13 @@ class PConstraintTransformer { | |||
233 | «FOR variable: e.affectedVariables» | 235 | «FOR variable: e.affectedVariables» |
234 | PrimitiveElement.valueSet(«variable.canonizeName»,«variable.valueSetted»); «hasValueExpression(variableMapping,variable,variable.valueVariable)» | 236 | PrimitiveElement.valueSet(«variable.canonizeName»,«variable.valueSetted»); «hasValueExpression(variableMapping,variable,variable.valueVariable)» |
235 | «ENDFOR» | 237 | «ENDFOR» |
236 | check( | 238 | ««« check( |
237 | «FOR variable: e.affectedVariables SEPARATOR " || "»!«variable.valueSetted»«ENDFOR» | 239 | ««« «FOR variable: e.affectedVariables SEPARATOR " || "»!«variable.valueSetted»«ENDFOR» |
238 | ««« «IF variable2Type.values.filter(RealTypeReference).empty» | 240 | ««« «IF variable2Type.values.filter(RealTypeReference).empty» |
239 | ««« || | 241 | ««« || |
240 | ««« («expressionGenerator.translateExpression(expression,e.affectedVariables.toInvertedMap[valueVariable],variable2Type)») | 242 | ««« («expressionGenerator.translateExpression(expression,e.affectedVariables.toInvertedMap[valueVariable],variable2Type)») |
241 | ««« «ENDIF» | 243 | ««« «ENDIF» |
242 | ); | 244 | ««« ); |
243 | ''' | 245 | ''' |
244 | } else { // Must or Current | 246 | } else { // Must or Current |
245 | return ''' | 247 | return ''' |
@@ -263,7 +265,7 @@ class PConstraintTransformer { | |||
263 | «FOR variable: e.affectedVariables» | 265 | «FOR variable: e.affectedVariables» |
264 | PrimitiveElement.valueSet(«variable.canonizeName»,«variable.valueSetted»); «hasValueExpression(variableMapping,variable,variable.valueVariable)» | 266 | PrimitiveElement.valueSet(«variable.canonizeName»,«variable.valueSetted»); «hasValueExpression(variableMapping,variable,variable.valueVariable)» |
265 | «ENDFOR» | 267 | «ENDFOR» |
266 | check(«FOR variable: e.affectedVariables SEPARATOR " || "»!«variable.valueSetted»«ENDFOR»); | 268 | ««« check(«FOR variable: e.affectedVariables SEPARATOR " || "»!«variable.valueSetted»«ENDFOR»); |
267 | ''' | 269 | ''' |
268 | } | 270 | } |
269 | 271 | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend index cfea499b..f3de4ccc 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend | |||
@@ -27,8 +27,8 @@ import java.util.HashMap | |||
27 | @Data class GeneratedPatterns { | 27 | @Data class GeneratedPatterns { |
28 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries | 28 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries |
29 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFQueries | 29 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFQueries |
30 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedContainmentMulticiplicityQueries | 30 | public Map<Relation, Pair<IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>,Integer>> unfinishedContainmentMulticiplicityQueries |
31 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedNonContainmentMulticiplicityQueries | 31 | public Map<Relation, Pair<IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>,Integer>> unfinishedNonContainmentMulticiplicityQueries |
32 | public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries | 32 | public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries |
33 | public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries | 33 | public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries |
34 | public Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refinerelationQueries | 34 | public Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refinerelationQueries |
@@ -93,11 +93,13 @@ class PatternProvider { | |||
93 | val unfinishedNonContainmentMultiplicities = new HashMap | 93 | val unfinishedNonContainmentMultiplicities = new HashMap |
94 | for(entry : unfinishedMultiplicities.entrySet) { | 94 | for(entry : unfinishedMultiplicities.entrySet) { |
95 | val relation = entry.key | 95 | val relation = entry.key |
96 | val value = entry.value.lookup(queries) | 96 | val name = entry.value.key |
97 | val amount = entry.value.value | ||
98 | val query = name.lookup(queries) | ||
97 | if(problem.containmentHierarchies.head.containmentRelations.contains(relation)) { | 99 | if(problem.containmentHierarchies.head.containmentRelations.contains(relation)) { |
98 | unfinishedContainmentMultiplicities.put(relation,value) | 100 | unfinishedContainmentMultiplicities.put(relation,query->amount) |
99 | } else { | 101 | } else { |
100 | unfinishedNonContainmentMultiplicities.put(relation,value) | 102 | unfinishedNonContainmentMultiplicities.put(relation,query->amount) |
101 | } | 103 | } |
102 | } | 104 | } |
103 | // val Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> | 105 | // val Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend index f384cd50..cef707c5 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDeclarationIndexer.xtend | |||
@@ -90,13 +90,13 @@ class RelationDeclarationIndexer { | |||
90 | // There are "numberOfExistingReferences" currently existing instances of the reference from the source, | 90 | // There are "numberOfExistingReferences" currently existing instances of the reference from the source, |
91 | // the upper bound of the multiplicity should be considered. | 91 | // the upper bound of the multiplicity should be considered. |
92 | numberOfExistingReferences == count «referRelation(relation,"source","_",Modality.MUST)» | 92 | numberOfExistingReferences == count «referRelation(relation,"source","_",Modality.MUST)» |
93 | check(numberOfExistingReferences < «upperMultiplicities.get(relation)»); | 93 | numberOfExistingReferences != «upperMultiplicities.get(relation)»; |
94 | «ENDIF» | 94 | «ENDIF» |
95 | «IF inverseRelations.containsKey(relation) && upperMultiplicities.containsKey(inverseRelations.get(relation))» | 95 | «IF inverseRelations.containsKey(relation) && upperMultiplicities.containsKey(inverseRelations.get(relation))» |
96 | // There are "numberOfExistingReferences" currently existing instances of the reference to the target, | 96 | // There are "numberOfExistingReferences" currently existing instances of the reference to the target, |
97 | // the upper bound of the opposite reference multiplicity should be considered. | 97 | // the upper bound of the opposite reference multiplicity should be considered. |
98 | numberOfExistingOppositeReferences == count «base.referRelation(inverseRelations.get(relation),"target","_",Modality.MUST,fqn2PQuery)» | 98 | numberOfExistingOppositeReferences == count «base.referRelation(inverseRelations.get(relation),"target","_",Modality.MUST,fqn2PQuery)» |
99 | check(numberOfExistingOppositeReferences < «upperMultiplicities.get(inverseRelations.get(relation))»); | 99 | numberOfExistingOppositeReferences != «upperMultiplicities.get(inverseRelations.get(relation))»; |
100 | «ENDIF» | 100 | «ENDIF» |
101 | «IF containments.contains(relation)» | 101 | «IF containments.contains(relation)» |
102 | // The reference is containment, then a new reference cannot be create if: | 102 | // The reference is containment, then a new reference cannot be create if: |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnfinishedIndexer.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnfinishedIndexer.xtend index ad1c9033..1df402fa 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnfinishedIndexer.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/UnfinishedIndexer.xtend | |||
@@ -46,14 +46,14 @@ class UnfinishedIndexer { | |||
46 | val lowerMultiplicities = base.lowerMultiplicities(problem) | 46 | val lowerMultiplicities = base.lowerMultiplicities(problem) |
47 | return ''' | 47 | return ''' |
48 | «FOR lowerMultiplicity : lowerMultiplicities» | 48 | «FOR lowerMultiplicity : lowerMultiplicities» |
49 | pattern «unfinishedMultiplicityName(lowerMultiplicity)»(problem:LogicProblem, interpretation:PartialInterpretation, relationIterpretation:PartialRelationInterpretation, object:DefinedElement,missingMultiplicity) { | 49 | pattern «unfinishedMultiplicityName(lowerMultiplicity)»(problem:LogicProblem, interpretation:PartialInterpretation, relationIterpretation:PartialRelationInterpretation, object:DefinedElement,numberOfExistingReferences) { |
50 | find interpretation(problem,interpretation); | 50 | find interpretation(problem,interpretation); |
51 | PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); | 51 | PartialInterpretation.partialrelationinterpretation(interpretation,relationIterpretation); |
52 | PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"«lowerMultiplicity.relation.name»"); | 52 | PartialRelationInterpretation.interpretationOf.name(relationIterpretation,"«lowerMultiplicity.relation.name»"); |
53 | «base.typeIndexer.referInstanceOf(lowerMultiplicity.firstParamTypeOfRelation,Modality::MUST,"object")» | 53 | «base.typeIndexer.referInstanceOf(lowerMultiplicity.firstParamTypeOfRelation,Modality::MUST,"object")» |
54 | numberOfExistingReferences == count «base.referRelation(lowerMultiplicity.relation,"object","_",Modality.MUST,fqn2PQuery)» | 54 | numberOfExistingReferences == count «base.referRelation(lowerMultiplicity.relation,"object","_",Modality.MUST,fqn2PQuery)» |
55 | check(numberOfExistingReferences < «lowerMultiplicity.lower»); | 55 | ««« numberOfExistingReferences < «lowerMultiplicity.lower»; |
56 | missingMultiplicity == eval(«lowerMultiplicity.lower»-numberOfExistingReferences); | 56 | ««« missingMultiplicity == eval(«lowerMultiplicity.lower»-numberOfExistingReferences); |
57 | } | 57 | } |
58 | «ENDFOR» | 58 | «ENDFOR» |
59 | ''' | 59 | ''' |
@@ -61,8 +61,8 @@ class UnfinishedIndexer { | |||
61 | def String unfinishedMultiplicityName(LowerMultiplicityAssertion lowerMultiplicityAssertion) | 61 | def String unfinishedMultiplicityName(LowerMultiplicityAssertion lowerMultiplicityAssertion) |
62 | '''unfinishedLowerMultiplicity_«base.canonizeName(lowerMultiplicityAssertion.relation.name)»''' | 62 | '''unfinishedLowerMultiplicity_«base.canonizeName(lowerMultiplicityAssertion.relation.name)»''' |
63 | 63 | ||
64 | def public referUnfinishedMultiplicityQuery(LowerMultiplicityAssertion lowerMultiplicityAssertion) | 64 | //def public referUnfinishedMultiplicityQuery(LowerMultiplicityAssertion lowerMultiplicityAssertion) |
65 | '''find «unfinishedMultiplicityName(lowerMultiplicityAssertion)»(problem, interpretation ,object, missingMultiplicity);''' | 65 | // '''find «unfinishedMultiplicityName(lowerMultiplicityAssertion)»(problem, interpretation ,object, missingMultiplicity);''' |
66 | 66 | ||
67 | def getFirstParamTypeOfRelation(LowerMultiplicityAssertion lowerMultiplicityAssertion) { | 67 | def getFirstParamTypeOfRelation(LowerMultiplicityAssertion lowerMultiplicityAssertion) { |
68 | val parameters = lowerMultiplicityAssertion.relation.parameters | 68 | val parameters = lowerMultiplicityAssertion.relation.parameters |
@@ -78,7 +78,7 @@ class UnfinishedIndexer { | |||
78 | val lowerMultiplicities = base.lowerMultiplicities(problem) | 78 | val lowerMultiplicities = base.lowerMultiplicities(problem) |
79 | val map = new LinkedHashMap | 79 | val map = new LinkedHashMap |
80 | for(lowerMultiplicity : lowerMultiplicities) { | 80 | for(lowerMultiplicity : lowerMultiplicities) { |
81 | map.put(lowerMultiplicity.relation,unfinishedMultiplicityName(lowerMultiplicity)) | 81 | map.put(lowerMultiplicity.relation,unfinishedMultiplicityName(lowerMultiplicity)->lowerMultiplicity.lower) |
82 | } | 82 | } |
83 | return map | 83 | return map |
84 | } | 84 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/GoalConstraintProvider.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/GoalConstraintProvider.xtend index 87f7e339..0e8d341a 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/GoalConstraintProvider.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/GoalConstraintProvider.xtend | |||
@@ -19,38 +19,40 @@ import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | |||
19 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 19 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
20 | 20 | ||
21 | class GoalConstraintProvider { | 21 | class GoalConstraintProvider { |
22 | val calculateObjectCost = true | 22 | val calculateObjectCost = false |
23 | 23 | ||
24 | def public getUnfinishedMultiplicityQueries(LogicProblem p, GeneratedPatterns patterns) { | 24 | def public getUnfinishedMultiplicityQueries(LogicProblem p, GeneratedPatterns patterns) { |
25 | val res = new ArrayList() | 25 | val res = new ArrayList() |
26 | 26 | ||
27 | res.addAll(patterns.unfinishedContainmentMulticiplicityQueries,true) | 27 | res.addAll(patterns.unfinishedNonContainmentMulticiplicityQueries,false) |
28 | if(calculateObjectCost) { | 28 | if(calculateObjectCost) { |
29 | val middingObjectCost = calculateMissingObjectCost(p) | 29 | val missingObjectCost = calculateMissingObjectCost(p) |
30 | res.addAll(patterns.unfinishedNonContainmentMulticiplicityQueries,false) | 30 | res.addAll(patterns.unfinishedContainmentMulticiplicityQueries,true,missingObjectCost) |
31 | } else { | 31 | } else { |
32 | res.addAll(patterns.unfinishedNonContainmentMulticiplicityQueries,false) | 32 | res.addAll(patterns.unfinishedContainmentMulticiplicityQueries,true) |
33 | } | 33 | } |
34 | return res | 34 | return res |
35 | } | 35 | } |
36 | 36 | ||
37 | def addAll(ArrayList<MultiplicityGoalConstraintCalculator> res, Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> queries, boolean containment) { | 37 | def addAll(ArrayList<MultiplicityGoalConstraintCalculator> res, Map<Relation, Pair<IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>,Integer>> queries, boolean containment) { |
38 | for(multiplicityQuery : queries.entrySet) { | 38 | for(multiplicityQuery : queries.entrySet) { |
39 | val targetRelationName = multiplicityQuery.key.name | 39 | val targetRelationName = multiplicityQuery.key.name |
40 | val query = multiplicityQuery.value | 40 | val query = multiplicityQuery.value.key |
41 | res += new MultiplicityGoalConstraintCalculator(targetRelationName,query,containment,1); | 41 | val minValue = multiplicityQuery.value.value |
42 | res += new MultiplicityGoalConstraintCalculator(targetRelationName,query,minValue,containment,1); | ||
42 | } | 43 | } |
43 | } | 44 | } |
44 | def addAll( | 45 | def addAll( |
45 | ArrayList<MultiplicityGoalConstraintCalculator> res, | 46 | ArrayList<MultiplicityGoalConstraintCalculator> res, |
46 | Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> queries, | 47 | Map<Relation, Pair<IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>,Integer>> queries, |
47 | boolean containment, | 48 | boolean containment, |
48 | Map<Relation, Integer> cost | 49 | Map<Relation, Integer> cost |
49 | ) { | 50 | ) { |
50 | for(multiplicityQuery : queries.entrySet) { | 51 | for(multiplicityQuery : queries.entrySet) { |
51 | val targetRelationName = multiplicityQuery.key.name | 52 | val targetRelationName = multiplicityQuery.key.name |
52 | val query = multiplicityQuery.value | 53 | val query = multiplicityQuery.value.key |
53 | res += new MultiplicityGoalConstraintCalculator(targetRelationName,query,containment,multiplicityQuery.key.lookup(cost)) | 54 | val minValue = multiplicityQuery.value.value |
55 | res += new MultiplicityGoalConstraintCalculator(targetRelationName,query,minValue,containment,multiplicityQuery.key.lookup(cost)) | ||
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
@@ -80,7 +82,7 @@ class GoalConstraintProvider { | |||
80 | for(containment : containments) { | 82 | for(containment : containments) { |
81 | val key = containment | 83 | val key = containment |
82 | val value = (containment.parameters.get(1) as ComplexTypeReference).referred.count(type2NewCost) | 84 | val value = (containment.parameters.get(1) as ComplexTypeReference).referred.count(type2NewCost) |
83 | //println('''«key.name» --> «value» new''') | 85 | // println('''«key.name» --> «value» new''') |
84 | res.put(key,value) | 86 | res.put(key,value) |
85 | } | 87 | } |
86 | return res | 88 | return res |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/RefinementRuleProvider.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/RefinementRuleProvider.xtend index 16438a5a..23ea118b 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/RefinementRuleProvider.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/rules/RefinementRuleProvider.xtend | |||
@@ -413,9 +413,6 @@ class RefinementRuleProvider { | |||
413 | newElement.name = '''new «interpretation.newElements.size»''' | 413 | newElement.name = '''new «interpretation.newElements.size»''' |
414 | } | 414 | } |
415 | 415 | ||
416 | // Existence | ||
417 | interpretation.newElements+=newElement | ||
418 | |||
419 | // Types | 416 | // Types |
420 | typeInterpretation.elements += newElement | 417 | typeInterpretation.elements += newElement |
421 | if(typeInterpretation instanceof PartialComplexTypeInterpretation) { | 418 | if(typeInterpretation instanceof PartialComplexTypeInterpretation) { |
@@ -431,6 +428,9 @@ class RefinementRuleProvider { | |||
431 | // Scope propagation | 428 | // Scope propagation |
432 | scopePropagator.propagateAdditionToType(typeInterpretation) | 429 | scopePropagator.propagateAdditionToType(typeInterpretation) |
433 | 430 | ||
431 | // Existence | ||
432 | interpretation.newElements+=newElement | ||
433 | |||
434 | // Do recursive object creation | 434 | // Do recursive object creation |
435 | for(newConstructor : recursiceObjectCreations) { | 435 | for(newConstructor : recursiceObjectCreations) { |
436 | createObjectAction(nameNewElement,newConstructor,newElement,scopePropagator) | 436 | createObjectAction(nameNewElement,newConstructor,newElement,scopePropagator) |
@@ -454,9 +454,6 @@ class RefinementRuleProvider { | |||
454 | newElement.name = '''new «interpretation.newElements.size»''' | 454 | newElement.name = '''new «interpretation.newElements.size»''' |
455 | } | 455 | } |
456 | 456 | ||
457 | // Existence | ||
458 | interpretation.newElements+=newElement | ||
459 | |||
460 | // Types | 457 | // Types |
461 | typeInterpretation.elements += newElement | 458 | typeInterpretation.elements += newElement |
462 | if(typeInterpretation instanceof PartialComplexTypeInterpretation) { | 459 | if(typeInterpretation instanceof PartialComplexTypeInterpretation) { |
@@ -469,6 +466,9 @@ class RefinementRuleProvider { | |||
469 | // Scope propagation | 466 | // Scope propagation |
470 | scopePropagator.propagateAdditionToType(typeInterpretation) | 467 | scopePropagator.propagateAdditionToType(typeInterpretation) |
471 | 468 | ||
469 | // Existence | ||
470 | interpretation.newElements+=newElement | ||
471 | |||
472 | // Do recursive object creation | 472 | // Do recursive object creation |
473 | for(newConstructor : recursiceObjectCreations) { | 473 | for(newConstructor : recursiceObjectCreations) { |
474 | createObjectAction(nameNewElement,newConstructor,newElement,scopePropagator) | 474 | createObjectAction(nameNewElement,newConstructor,newElement,scopePropagator) |
@@ -490,9 +490,6 @@ class RefinementRuleProvider { | |||
490 | newElement.name = '''new «interpretation.newElements.size»''' | 490 | newElement.name = '''new «interpretation.newElements.size»''' |
491 | } | 491 | } |
492 | 492 | ||
493 | // Existence | ||
494 | interpretation.newElements+=newElement | ||
495 | |||
496 | // Types | 493 | // Types |
497 | typeInterpretation.elements += newElement | 494 | typeInterpretation.elements += newElement |
498 | if(typeInterpretation instanceof PartialComplexTypeInterpretation) { | 495 | if(typeInterpretation instanceof PartialComplexTypeInterpretation) { |
@@ -502,6 +499,9 @@ class RefinementRuleProvider { | |||
502 | // Scope propagation | 499 | // Scope propagation |
503 | scopePropagator.propagateAdditionToType(typeInterpretation) | 500 | scopePropagator.propagateAdditionToType(typeInterpretation) |
504 | 501 | ||
502 | // Existence | ||
503 | interpretation.newElements+=newElement | ||
504 | |||
505 | // Do recursive object creation | 505 | // Do recursive object creation |
506 | for(newConstructor : recursiceObjectCreations) { | 506 | for(newConstructor : recursiceObjectCreations) { |
507 | createObjectAction(nameNewElement,newConstructor,newElement,scopePropagator) | 507 | createObjectAction(nameNewElement,newConstructor,newElement,scopePropagator) |