diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternProvider.xtend | 139 |
1 files changed, 91 insertions, 48 deletions
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 0e13a5e1..eadf0ae0 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 | |||
@@ -2,16 +2,23 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns | |||
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation | 3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation |
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | 4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDefinition | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem |
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationStatistics | 9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationStatistics |
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysis | 10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysis |
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult | 11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult |
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod | 12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod |
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationConstraints | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationMultiplicityConstraint | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.util.ParseUtil | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.util.ParseUtil |
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
13 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | 18 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace |
19 | import java.util.Collection | ||
14 | import java.util.Map | 20 | import java.util.Map |
21 | import java.util.Set | ||
15 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | 22 | import org.eclipse.viatra.query.runtime.api.IPatternMatch |
16 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | 23 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification |
17 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | 24 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher |
@@ -19,79 +26,115 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery | |||
19 | import org.eclipse.xtend.lib.annotations.Data | 26 | import org.eclipse.xtend.lib.annotations.Data |
20 | 27 | ||
21 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 28 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
22 | import java.util.Collection | ||
23 | import java.util.Set | ||
24 | 29 | ||
25 | @Data class GeneratedPatterns { | 30 | @Data |
26 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries | 31 | class GeneratedPatterns { |
27 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFQueries | 32 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> invalidWFQueries |
28 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedMulticiplicityQueries | 33 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFQueries |
29 | public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries | 34 | public Map<RelationMultiplicityConstraint, UnifinishedMultiplicityQueries> multiplicityConstraintQueries |
30 | public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries | 35 | public IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hasElementInContainmentQuery |
31 | public Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refinerelationQueries | 36 | public Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedMulticiplicityQueries |
37 | public Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineObjectQueries | ||
38 | public Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refineTypeQueries | ||
39 | public Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> refinerelationQueries | ||
40 | public Map<RelationDefinition, ModalPatternQueries> modalRelationQueries | ||
32 | public Collection<IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> allQueries | 41 | public Collection<IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> allQueries |
33 | } | 42 | } |
34 | 43 | ||
44 | @Data | ||
45 | class ModalPatternQueries { | ||
46 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> mayQuery | ||
47 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> mustQuery | ||
48 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> currentQuery | ||
49 | } | ||
50 | |||
51 | @Data | ||
52 | class UnifinishedMultiplicityQueries { | ||
53 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> unfinishedMultiplicityQuery | ||
54 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> unrepairableMultiplicityQuery | ||
55 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> remainingInverseMultiplicityQuery | ||
56 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> remainingContentsQuery | ||
57 | } | ||
58 | |||
35 | class PatternProvider { | 59 | class PatternProvider { |
36 | 60 | ||
37 | val TypeAnalysis typeAnalysis = new TypeAnalysis | 61 | val TypeAnalysis typeAnalysis = new TypeAnalysis |
38 | 62 | ||
39 | public def generateQueries( | 63 | def generateQueries(LogicProblem problem, PartialInterpretation emptySolution, ModelGenerationStatistics statistics, |
40 | LogicProblem problem, | 64 | Set<PQuery> existingQueries, ReasonerWorkspace workspace, TypeInferenceMethod typeInferenceMethod, |
41 | PartialInterpretation emptySolution, | 65 | ScopePropagatorStrategy scopePropagatorStrategy, RelationConstraints relationConstraints, boolean writeToFile) { |
42 | ModelGenerationStatistics statistics, | ||
43 | Set<PQuery> existingQueries, | ||
44 | ReasonerWorkspace workspace, | ||
45 | TypeInferenceMethod typeInferenceMethod, | ||
46 | boolean writeToFile) | ||
47 | { | ||
48 | val fqn2Query = existingQueries.toMap[it.fullyQualifiedName] | 66 | val fqn2Query = existingQueries.toMap[it.fullyQualifiedName] |
49 | val PatternGenerator patternGenerator = new PatternGenerator(typeInferenceMethod) | 67 | val PatternGenerator patternGenerator = new PatternGenerator(typeInferenceMethod, scopePropagatorStrategy) |
50 | val typeAnalysisResult = if(patternGenerator.requiresTypeAnalysis) { | 68 | val typeAnalysisResult = if (patternGenerator.requiresTypeAnalysis) { |
51 | val startTime = System.nanoTime | 69 | val startTime = System.nanoTime |
52 | val result = typeAnalysis.performTypeAnalysis(problem,emptySolution) | 70 | val result = typeAnalysis.performTypeAnalysis(problem, emptySolution) |
53 | val typeAnalysisTime = System.nanoTime - startTime | 71 | val typeAnalysisTime = System.nanoTime - startTime |
54 | statistics.PreliminaryTypeAnalisisTime = typeAnalysisTime | 72 | statistics.preliminaryTypeAnalisisTime = typeAnalysisTime |
55 | result | 73 | result |
56 | } else { | 74 | } else { |
57 | null | 75 | null |
58 | } | 76 | } |
59 | val baseIndexerFile = patternGenerator.transformBaseProperties(problem,emptySolution,fqn2Query,typeAnalysisResult) | 77 | val baseIndexerFile = patternGenerator.transformBaseProperties(problem, emptySolution, fqn2Query, |
60 | if(writeToFile) { | 78 | typeAnalysisResult, relationConstraints) |
61 | workspace.writeText('''generated3valued.vql_deactivated''',baseIndexerFile) | 79 | if (writeToFile) { |
80 | workspace.writeText('''generated3valued.vql_deactivated''', baseIndexerFile) | ||
62 | } | 81 | } |
63 | val ParseUtil parseUtil = new ParseUtil | 82 | val ParseUtil parseUtil = new ParseUtil |
64 | val generatedQueries = parseUtil.parse(baseIndexerFile) | 83 | val generatedQueries = parseUtil.parse(baseIndexerFile) |
65 | val runtimeQueries = calclulateRuntimeQueries(patternGenerator,problem,emptySolution,typeAnalysisResult,generatedQueries); | 84 | val runtimeQueries = calclulateRuntimeQueries(patternGenerator, problem, emptySolution, typeAnalysisResult, |
85 | relationConstraints, generatedQueries) | ||
66 | return runtimeQueries | 86 | return runtimeQueries |
67 | } | 87 | } |
68 | 88 | ||
69 | private def GeneratedPatterns calclulateRuntimeQueries( | 89 | private def GeneratedPatterns calclulateRuntimeQueries( |
70 | PatternGenerator patternGenerator, | 90 | PatternGenerator patternGenerator, |
71 | LogicProblem problem, | 91 | LogicProblem problem, |
72 | PartialInterpretation emptySolution, | 92 | PartialInterpretation emptySolution, |
73 | TypeAnalysisResult typeAnalysisResult, | 93 | TypeAnalysisResult typeAnalysisResult, |
74 | Map<String, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> queries | 94 | RelationConstraints relationConstraints, |
95 | Map<String, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> queries | ||
75 | ) { | 96 | ) { |
76 | val Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> | 97 | val invalidWFQueries = patternGenerator.invalidIndexer.getInvalidateByWfQueryNames(problem).mapValues [ |
77 | invalidWFQueries = patternGenerator.invalidIndexer.getInvalidateByWfQueryNames(problem).mapValues[it.lookup(queries)] | 98 | it.lookup(queries) |
78 | val Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> | 99 | ] |
79 | unfinishedWFQueries = patternGenerator.unfinishedIndexer.getUnfinishedWFQueryNames(problem).mapValues[it.lookup(queries)] | 100 | val unfinishedWFQueries = patternGenerator.unfinishedIndexer.getUnfinishedWFQueryNames(problem).mapValues [ |
80 | val Map<Relation, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> | 101 | it.lookup(queries) |
81 | unfinishedMultiplicityQueries = patternGenerator.unfinishedIndexer.getUnfinishedMultiplicityQueries(problem).mapValues[it.lookup(queries)] | 102 | ] |
82 | val Map<ObjectCreationPrecondition, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> | 103 | val multiplicityConstraintQueries = patternGenerator.unfinishedIndexer.getUnfinishedMultiplicityQueries( |
83 | refineObjectsQueries = patternGenerator.typeRefinementGenerator.getRefineObjectQueryNames(problem,emptySolution,typeAnalysisResult).mapValues[it.lookup(queries)] | 104 | relationConstraints.multiplicityConstraints).mapValues [ |
84 | val Map<? extends Type, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> | 105 | new UnifinishedMultiplicityQueries(unfinishedMultiplicityQueryName?.lookup(queries), |
85 | refineTypeQueries = patternGenerator.typeRefinementGenerator.getRefineTypeQueryNames(problem,emptySolution,typeAnalysisResult).mapValues[it.lookup(queries)] | 106 | unrepairableMultiplicityQueryName?.lookup(queries), |
86 | val Map<Pair<RelationDeclaration, Relation>, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> | 107 | remainingInverseMultiplicityQueryName?.lookup(queries), remainingContentsQueryName?.lookup(queries)) |
87 | refineRelationQueries = patternGenerator.relationRefinementGenerator.getRefineRelationQueries(problem).mapValues[it.lookup(queries)] | 108 | ] |
109 | val hasElementInContainmentQuery = patternGenerator.typeRefinementGenerator.hasElementInContainmentName.lookup( | ||
110 | queries) | ||
111 | val unfinishedMultiplicityQueries = multiplicityConstraintQueries.entrySet.filter [ | ||
112 | value.unfinishedMultiplicityQuery !== null | ||
113 | ].toMap([key.relation], [value.unfinishedMultiplicityQuery]) | ||
114 | val refineObjectsQueries = patternGenerator.typeRefinementGenerator. | ||
115 | getRefineObjectQueryNames(problem, emptySolution, typeAnalysisResult).mapValues[it.lookup(queries)] | ||
116 | val refineTypeQueries = patternGenerator.typeRefinementGenerator.getRefineTypeQueryNames(problem, emptySolution, | ||
117 | typeAnalysisResult).mapValues[it.lookup(queries)] | ||
118 | val refineRelationQueries = patternGenerator.relationRefinementGenerator.getRefineRelationQueries(problem). | ||
119 | mapValues[it.lookup(queries)] | ||
120 | val modalRelationQueries = problem.relations.filter(RelationDefinition).toMap([it], [ relationDefinition | | ||
121 | val indexer = patternGenerator.relationDefinitionIndexer | ||
122 | new ModalPatternQueries( | ||
123 | indexer.relationDefinitionName(relationDefinition, Modality.MAY).lookup(queries), | ||
124 | indexer.relationDefinitionName(relationDefinition, Modality.MUST).lookup(queries), | ||
125 | indexer.relationDefinitionName(relationDefinition, Modality.CURRENT).lookup(queries) | ||
126 | ) | ||
127 | ]) | ||
88 | return new GeneratedPatterns( | 128 | return new GeneratedPatterns( |
89 | invalidWFQueries, | 129 | invalidWFQueries, |
90 | unfinishedWFQueries, | 130 | unfinishedWFQueries, |
131 | multiplicityConstraintQueries, | ||
132 | hasElementInContainmentQuery, | ||
91 | unfinishedMultiplicityQueries, | 133 | unfinishedMultiplicityQueries, |
92 | refineObjectsQueries, | 134 | refineObjectsQueries, |
93 | refineTypeQueries, | 135 | refineTypeQueries, |
94 | refineRelationQueries, | 136 | refineRelationQueries, |
137 | modalRelationQueries, | ||
95 | queries.values | 138 | queries.values |
96 | ) | 139 | ) |
97 | } | 140 | } |