diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend | 94 |
1 files changed, 89 insertions, 5 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend index 2986e344..6e1e5765 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/PatternGenerator.xtend | |||
@@ -21,6 +21,11 @@ import java.util.HashSet | |||
21 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion | 21 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion |
22 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation | 22 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation |
23 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.DefinedByDerivedFeature | 23 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.DefinedByDerivedFeature |
24 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeReference | ||
25 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference | ||
26 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference | ||
27 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference | ||
28 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringTypeReference | ||
24 | 29 | ||
25 | class PatternGenerator { | 30 | class PatternGenerator { |
26 | @Accessors(PUBLIC_GETTER) val TypeIndexer typeIndexer //= new TypeIndexer(this) | 31 | @Accessors(PUBLIC_GETTER) val TypeIndexer typeIndexer //= new TypeIndexer(this) |
@@ -126,13 +131,28 @@ class PatternGenerator { | |||
126 | relation.annotations.filter(DefinedByDerivedFeature).head.query | 131 | relation.annotations.filter(DefinedByDerivedFeature).head.query |
127 | } | 132 | } |
128 | 133 | ||
134 | private def allTypeReferences(LogicProblem problem) { | ||
135 | problem.eAllContents.filter(TypeReference).toIterable | ||
136 | } | ||
137 | protected def hasBoolean(LogicProblem problem) { | ||
138 | problem.allTypeReferences.exists[it instanceof BoolTypeReference] | ||
139 | } | ||
140 | protected def hasInteger(LogicProblem problem) { | ||
141 | problem.allTypeReferences.exists[it instanceof IntTypeReference] | ||
142 | } | ||
143 | protected def hasReal(LogicProblem problem) { | ||
144 | problem.allTypeReferences.exists[it instanceof RealTypeReference] | ||
145 | } | ||
146 | protected def hasString(LogicProblem problem) { | ||
147 | problem.allTypeReferences.exists[it instanceof StringTypeReference] | ||
148 | } | ||
149 | |||
129 | public def transformBaseProperties( | 150 | public def transformBaseProperties( |
130 | LogicProblem problem, | 151 | LogicProblem problem, |
131 | PartialInterpretation emptySolution, | 152 | PartialInterpretation emptySolution, |
132 | Map<String,PQuery> fqn2PQuery, | 153 | Map<String,PQuery> fqn2PQuery, |
133 | TypeAnalysisResult typeAnalysisResult | 154 | TypeAnalysisResult typeAnalysisResult |
134 | ) { | 155 | ) { |
135 | |||
136 | return ''' | 156 | return ''' |
137 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage" | 157 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage" |
138 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/problem" | 158 | import epackage "http://www.bme.hu/mit/inf/dslreasoner/logic/model/problem" |
@@ -146,7 +166,7 @@ class PatternGenerator { | |||
146 | } | 166 | } |
147 | 167 | ||
148 | ///////////////////////// | 168 | ///////////////////////// |
149 | // 0.1 Existance | 169 | // 0.1 Existence |
150 | ///////////////////////// | 170 | ///////////////////////// |
151 | private pattern mustExist(problem:LogicProblem, interpetation:PartialInterpretation, element:DefinedElement) { | 171 | private pattern mustExist(problem:LogicProblem, interpetation:PartialInterpretation, element:DefinedElement) { |
152 | find interpretation(problem,interpetation); | 172 | find interpretation(problem,interpetation); |
@@ -154,19 +174,52 @@ class PatternGenerator { | |||
154 | } or { | 174 | } or { |
155 | find interpretation(problem,interpetation); | 175 | find interpretation(problem,interpetation); |
156 | PartialInterpretation.newElements(interpetation,element); | 176 | PartialInterpretation.newElements(interpetation,element); |
157 | } | 177 | } or { |
178 | find interpretation(problem,interpetation); | ||
179 | PartialInterpretation.booleanelements(interpetation,element); | ||
180 | } or { | ||
181 | find interpretation(problem,interpetation); | ||
182 | PartialInterpretation.integerelements(interpetation,element); | ||
183 | } or { | ||
184 | find interpretation(problem,interpetation); | ||
185 | PartialInterpretation.realelements(interpetation,element); | ||
186 | } | ||
187 | find interpretation(problem,interpetation); | ||
188 | PartialInterpretation.stringelements(interpetation,element); | ||
189 | } | ||
158 | 190 | ||
159 | private pattern mayExist(problem:LogicProblem, interpetation:PartialInterpretation, element:DefinedElement) { | 191 | private pattern mayExist(problem:LogicProblem, interpetation:PartialInterpretation, element:DefinedElement) { |
160 | find mustExist(problem,interpetation,element); | 192 | find mustExist(problem,interpetation,element); |
161 | } or { | 193 | } or { |
162 | find interpretation(problem,interpetation); | 194 | find interpretation(problem,interpetation); |
163 | neg find closeWorld(interpetation); | 195 | neg find elementCloseWorld(interpetation); |
164 | PartialInterpretation.openWorldElementPrototypes(interpetation,element); | 196 | PartialInterpretation.openWorldElementPrototypes(interpetation,element); |
197 | } or { | ||
198 | find interpretation(problem,interpetation); | ||
199 | neg find integerCloseWorld(interpetation); | ||
200 | PartialInterpretation.newIntegers(interpetation,element) | ||
201 | } or { | ||
202 | find interpretation(problem,interpetation); | ||
203 | neg find realCloseWorld(interpetation); | ||
204 | PartialInterpretation.newReals(interpetation,element) | ||
205 | } or { | ||
206 | find interpretation(problem,interpetation); | ||
207 | neg find stringCloseWorld(interpetation); | ||
208 | PartialInterpretation.newStrings(interpetation,element) | ||
165 | } | 209 | } |
166 | 210 | ||
167 | private pattern closeWorld(interpetation:PartialInterpretation) { | 211 | private pattern elementCloseWorld(interpetation:PartialInterpretation) { |
168 | PartialInterpretation.maxNewElements(interpetation,0); | 212 | PartialInterpretation.maxNewElements(interpetation,0); |
169 | } | 213 | } |
214 | private pattern integerCloseWorld(interpetation:PartialInterpretation) { | ||
215 | PartialInterpretation.maxNewIntegers(interpetation,0); | ||
216 | } | ||
217 | private pattern realCloseWorld(interpetation:PartialInterpretation) { | ||
218 | PartialInterpretation.maxNewReals(interpetation,0); | ||
219 | } | ||
220 | private pattern stringCloseWorld(interpetation:PartialInterpretation) { | ||
221 | PartialInterpretation.maxNewStrings(interpetation,0); | ||
222 | } | ||
170 | 223 | ||
171 | //////////////////////// | 224 | //////////////////////// |
172 | // 0.2 Equivalence | 225 | // 0.2 Equivalence |
@@ -187,6 +240,37 @@ class PatternGenerator { | |||
187 | ////////// | 240 | ////////// |
188 | // 1.1 Type Indexers | 241 | // 1.1 Type Indexers |
189 | ////////// | 242 | ////////// |
243 | // 1.1.1 primitive Type Indexers | ||
244 | ////////// | ||
245 | pattern instaneofBoolean(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
246 | find interpretation(problem,interpretation); | ||
247 | PartialInterpretation.booleanelements(interpretation,element); | ||
248 | } | ||
249 | pattern instaneofInteger(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
250 | find interpretation(problem,interpretation); | ||
251 | PartialInterpretation.integerelements(interpretation,element); | ||
252 | } or { | ||
253 | find interpretation(problem,interpretation); | ||
254 | PartialInterpretation.newIntegers(interpetation,element); | ||
255 | } | ||
256 | pattern instaneofReal(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
257 | find interpretation(problem,interpretation); | ||
258 | PartialInterpretation.realements(interpretation,element); | ||
259 | } or { | ||
260 | find interpretation(problem,interpretation); | ||
261 | PartialInterpretation.newReals(interpetation,element); | ||
262 | } | ||
263 | pattern instaneofString(problem:LogicProblem, interpretation:PartialInterpretation, element:DefinedElement) { | ||
264 | find interpretation(problem,interpretation); | ||
265 | PartialInterpretation.stringelements(interpretation,element); | ||
266 | } or { | ||
267 | find interpretation(problem,interpretation); | ||
268 | PartialInterpretation.newStrings(interpetation,element); | ||
269 | } | ||
270 | |||
271 | ////////// | ||
272 | // 1.1.2 domain-specific Type Indexers | ||
273 | ////////// | ||
190 | «typeIndexer.generateInstanceOfQueries(problem,emptySolution,typeAnalysisResult)» | 274 | «typeIndexer.generateInstanceOfQueries(problem,emptySolution,typeAnalysisResult)» |
191 | 275 | ||
192 | ////////// | 276 | ////////// |