diff options
author | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2020-11-04 01:33:58 -0500 |
---|---|---|
committer | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2020-11-04 01:33:58 -0500 |
commit | a20af4d0dbf5eab84ee271d426528aabb5a8ac3b (patch) | |
tree | a9ab772ee313125aaf3a941d66e131b408d949ba /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme | |
parent | changes in settings of measurements (diff) | |
parent | merge with current master, comment numerical solver related logging (diff) | |
download | VIATRA-Generator-a20af4d0dbf5eab84ee271d426528aabb5a8ac3b.tar.gz VIATRA-Generator-a20af4d0dbf5eab84ee271d426528aabb5a8ac3b.tar.zst VIATRA-Generator-a20af4d0dbf5eab84ee271d426528aabb5a8ac3b.zip |
fix merging issue
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme')
12 files changed, 853 insertions, 589 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend index 8aaaacb5..cb5b587f 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend | |||
@@ -1,5 +1,6 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic |
2 | 2 | ||
3 | import com.google.common.collect.ImmutableList | ||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | 4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic |
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | 5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | 6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput |
@@ -12,18 +13,18 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.Par | |||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.Problem2PartialInterpretationTrace | 13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.Problem2PartialInterpretationTrace |
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | 14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation |
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory | 15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory |
16 | import java.math.BigDecimal | ||
15 | import java.util.HashMap | 17 | import java.util.HashMap |
18 | import java.util.HashSet | ||
16 | import java.util.List | 19 | import java.util.List |
17 | import java.util.Map | 20 | import java.util.Map |
21 | import java.util.Set | ||
18 | import org.eclipse.emf.common.util.Enumerator | 22 | import org.eclipse.emf.common.util.Enumerator |
23 | import org.eclipse.emf.ecore.EAttribute | ||
19 | import org.eclipse.emf.ecore.EObject | 24 | import org.eclipse.emf.ecore.EObject |
20 | import org.eclipse.emf.ecore.resource.Resource | 25 | import org.eclipse.emf.ecore.resource.Resource |
21 | 26 | ||
22 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 27 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
23 | import java.util.HashSet | ||
24 | import java.util.Set | ||
25 | import java.math.BigDecimal | ||
26 | import org.eclipse.emf.ecore.EAttribute | ||
27 | 28 | ||
28 | class InstanceModel2PartialInterpretation { | 29 | class InstanceModel2PartialInterpretation { |
29 | val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE | 30 | val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE |
@@ -36,7 +37,19 @@ class InstanceModel2PartialInterpretation { | |||
36 | Resource resource, | 37 | Resource resource, |
37 | boolean withID) | 38 | boolean withID) |
38 | { | 39 | { |
39 | val objects = resource.allContents.toList | 40 | val objectsBuilder = ImmutableList.builder |
41 | val treeIterator = resource.allContents | ||
42 | val referencesUsed = ecore2Logic.allReferencesInScope(metamodelTranslationResult.trace).toSet | ||
43 | while (treeIterator.hasNext) { | ||
44 | val object = treeIterator.next | ||
45 | val containingReference = object.eContainmentFeature | ||
46 | if (containingReference === null || referencesUsed.contains(containingReference)) { | ||
47 | objectsBuilder.add(object) | ||
48 | } else { | ||
49 | treeIterator.prune | ||
50 | } | ||
51 | } | ||
52 | val objects = objectsBuilder.build | ||
40 | return transform(metamodelTranslationResult,objects,withID) | 53 | return transform(metamodelTranslationResult,objects,withID) |
41 | } | 54 | } |
42 | 55 | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend index f7a1ce4f..20ff58f2 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend | |||
@@ -2,19 +2,24 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage | |||
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | 3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput |
4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | 4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.And | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolLiteral | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement |
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory | 9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory |
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | 11 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration |
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDefinition | ||
13 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral | ||
14 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 15 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | 16 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration |
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | 17 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition |
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | 18 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem |
12 | import hu.bme.mit.inf.dslreasoner.logic.model.patterns.SupertypeStar | 19 | import hu.bme.mit.inf.dslreasoner.logic.model.patterns.SupertypeStar |
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion | 20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion |
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement | 21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement |
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement | 22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement |
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.NaryRelationLink | ||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation | 23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation |
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | 24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation |
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation | 25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation |
@@ -22,10 +27,10 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRealInterpretation | 27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRealInterpretation |
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | 28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation |
24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialStringInterpretation | 29 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialStringInterpretation |
30 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory | 31 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory |
26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement | 32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement |
27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement | 33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement |
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.UnaryElementRelationLink | ||
29 | import java.math.BigDecimal | 34 | import java.math.BigDecimal |
30 | import java.util.HashMap | 35 | import java.util.HashMap |
31 | import java.util.Map | 36 | import java.util.Map |
@@ -35,13 +40,6 @@ import org.eclipse.viatra.query.runtime.emf.EMFScope | |||
35 | import org.eclipse.xtend.lib.annotations.Data | 40 | import org.eclipse.xtend.lib.annotations.Data |
36 | 41 | ||
37 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 42 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
38 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue | ||
39 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.And | ||
40 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolLiteral | ||
41 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral | ||
42 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral | ||
43 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral | ||
44 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
45 | 43 | ||
46 | @Data class Problem2PartialInterpretationTrace { | 44 | @Data class Problem2PartialInterpretationTrace { |
47 | Map<TypeDeclaration, PartialComplexTypeInterpretation> type2Interpretation | 45 | Map<TypeDeclaration, PartialComplexTypeInterpretation> type2Interpretation |
@@ -193,7 +191,7 @@ class PartialInterpretationInitialiser { | |||
193 | interpretation.minNewElements = minNewElements | 191 | interpretation.minNewElements = minNewElements |
194 | interpretation.maxNewElements = maxNewElements | 192 | interpretation.maxNewElements = maxNewElements |
195 | // elements from problem are included | 193 | // elements from problem are included |
196 | if(maxNewElements>0) { | 194 | if(maxNewElements != 0) { |
197 | val newElements = createDefinedElement => [it.name = "New Objects"] | 195 | val newElements = createDefinedElement => [it.name = "New Objects"] |
198 | interpretation.openWorldElements += newElements | 196 | interpretation.openWorldElements += newElements |
199 | } | 197 | } |
@@ -212,12 +210,8 @@ class PartialInterpretationInitialiser { | |||
212 | def private initialiseTypeScope(PartialTypeInterpratation interpretation, Integer min, Integer max) { | 210 | def private initialiseTypeScope(PartialTypeInterpratation interpretation, Integer min, Integer max) { |
213 | val res = createScope | 211 | val res = createScope |
214 | res.targetTypeInterpretation = interpretation | 212 | res.targetTypeInterpretation = interpretation |
215 | if(min !== null) { | 213 | res.minNewElements = min ?: 0 |
216 | res.minNewElements = min | 214 | res.maxNewElements = max ?: -1 |
217 | } | ||
218 | if(max !== null) { | ||
219 | res.maxNewElements = max | ||
220 | } | ||
221 | return res | 215 | return res |
222 | } | 216 | } |
223 | 217 | ||
@@ -233,7 +227,11 @@ class PartialInterpretationInitialiser { | |||
233 | 227 | ||
234 | def private Map<RelationDeclaration, PartialRelationInterpretation> initRelations(PartialInterpretation interpretation, PrimitiveValueTrace trace) { | 228 | def private Map<RelationDeclaration, PartialRelationInterpretation> initRelations(PartialInterpretation interpretation, PrimitiveValueTrace trace) { |
235 | val Map<RelationDeclaration, PartialRelationInterpretation> relation2Interpretation = new HashMap | 229 | val Map<RelationDeclaration, PartialRelationInterpretation> relation2Interpretation = new HashMap |
236 | for(relation : interpretation.problem.relations.filter(RelationDeclaration)) { | 230 | val definedRelationDeclarations = interpretation.problem.relations.filter(RelationDefinition).map[defines] |
231 | val undefinedRelationDeclarations = interpretation.problem.relations.filter(RelationDeclaration).filter[ | ||
232 | declared | !definedRelationDeclarations.exists[defined | defined === declared] | ||
233 | ] | ||
234 | for(relation : undefinedRelationDeclarations) { | ||
237 | val partialInterpretation = relation.initialisePartialRelationInterpretation | 235 | val partialInterpretation = relation.initialisePartialRelationInterpretation |
238 | interpretation.partialrelationinterpretation += partialInterpretation | 236 | interpretation.partialrelationinterpretation += partialInterpretation |
239 | relation2Interpretation.put(relation,partialInterpretation) | 237 | relation2Interpretation.put(relation,partialInterpretation) |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend index 41482b28..685a1f5a 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend | |||
@@ -4,10 +4,21 @@ import java.util.HashMap | |||
4 | import java.util.Map | 4 | import java.util.Map |
5 | import java.util.Set | 5 | import java.util.Set |
6 | import org.eclipse.xtend.lib.annotations.Data | 6 | import org.eclipse.xtend.lib.annotations.Data |
7 | import org.eclipse.xtend2.lib.StringConcatenationClient | ||
7 | 8 | ||
8 | @Data abstract class AbstractNodeDescriptor { | 9 | @Data abstract class AbstractNodeDescriptor { |
9 | long dataHash | 10 | int dataHash |
10 | 11 | ||
12 | protected def StringConcatenationClient prettyPrint() { | ||
13 | '''(«dataHash»)[«class.simpleName»]''' | ||
14 | } | ||
15 | |||
16 | override toString() { | ||
17 | ''' | ||
18 | «prettyPrint» | ||
19 | ''' | ||
20 | } | ||
21 | |||
11 | // @Pure | 22 | // @Pure |
12 | // @Override | 23 | // @Override |
13 | // override public boolean equals(Object obj) { | 24 | // override public boolean equals(Object obj) { |
@@ -24,34 +35,45 @@ import org.eclipse.xtend.lib.annotations.Data | |||
24 | // } | 35 | // } |
25 | } | 36 | } |
26 | 37 | ||
27 | @Data class LocalNodeDescriptor extends AbstractNodeDescriptor{ | 38 | @Data class LocalNodeDescriptor extends AbstractNodeDescriptor { |
28 | Set<String> types | 39 | Set<String> types |
29 | String id; | 40 | String id; |
41 | |||
30 | new(String id, Set<String> types) { | 42 | new(String id, Set<String> types) { |
31 | super(calcualteDataHash(id,types)) | 43 | super(calcualteDataHash(id, types)) |
32 | this.types = types | 44 | this.types = types |
33 | this.id = id | 45 | this.id = id |
34 | } | 46 | } |
35 | 47 | ||
36 | def private static calcualteDataHash(String id, Set<String> types) { | 48 | def private static calcualteDataHash(String id, Set<String> types) { |
37 | val int prime = 31; | 49 | val int prime = 31; |
38 | var result = 0 | 50 | var result = 0 |
39 | if(id !== null) | 51 | if (id !== null) |
40 | result = id.hashCode(); | 52 | result = id.hashCode(); |
41 | if(types !== null) { | 53 | if (types !== null) { |
42 | result = prime * result + types.hashCode | 54 | result = prime * result + types.hashCode |
43 | } | 55 | } |
44 | return result | 56 | return result |
45 | } | 57 | } |
46 | 58 | ||
47 | override hashCode() { | 59 | override hashCode() { |
48 | return this.dataHash.hashCode | 60 | return this.dataHash |
49 | } | 61 | } |
50 | 62 | ||
63 | override equals(Object other) { | ||
64 | other.class == LocalNodeDescriptor && (other as AbstractNodeDescriptor).hashCode == hashCode | ||
65 | } | ||
66 | |||
67 | override protected prettyPrint() { | ||
68 | '''(«dataHash»)[«IF id !== null»id = "«id»"«IF types === null || !types.empty», «ENDIF»«ENDIF»«IF types === null»TYPES = null«ELSE»«FOR type : types SEPARATOR ", "»«type»«ENDFOR»«ENDIF»]''' | ||
69 | } | ||
70 | |||
51 | override toString() { | 71 | override toString() { |
52 | return class.name + this.dataHash | 72 | ''' |
73 | «prettyPrint» | ||
74 | ''' | ||
53 | } | 75 | } |
54 | 76 | ||
55 | // @Pure | 77 | // @Pure |
56 | // @Override | 78 | // @Override |
57 | // override public boolean equals(Object obj) { | 79 | // override public boolean equals(Object obj) { |
@@ -66,7 +88,6 @@ import org.eclipse.xtend.lib.annotations.Data | |||
66 | // return false; | 88 | // return false; |
67 | // return true; | 89 | // return true; |
68 | // } | 90 | // } |
69 | |||
70 | // @Pure | 91 | // @Pure |
71 | // override public boolean equals(Object obj) { | 92 | // override public boolean equals(Object obj) { |
72 | // if (this === obj) | 93 | // if (this === obj) |
@@ -97,118 +118,91 @@ import org.eclipse.xtend.lib.annotations.Data | |||
97 | String type | 118 | String type |
98 | } | 119 | } |
99 | 120 | ||
100 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor{ | 121 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor { |
101 | 122 | NodeRep previousRepresentation | |
102 | NodeRep previousRepresentation | 123 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges |
103 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges | 124 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges |
104 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges | 125 | |
105 | 126 | new(NodeRep previousRepresentation, Map<IncomingRelation<NodeRep>, Integer> incomingEdges, | |
106 | new( | 127 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { |
107 | NodeRep previousRepresentation, | 128 | super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges)) |
108 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges, | 129 | this.previousRepresentation = previousRepresentation |
109 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges) | 130 | this.incomingEdges = incomingEdges |
110 | { | 131 | this.outgoingEdges = outgoingEdges |
111 | super(calculateDataHash(previousRepresentation,incomingEdges,outgoingEdges)) | ||
112 | this.previousRepresentation = previousRepresentation | ||
113 | this.incomingEdges = new HashMap(incomingEdges) | ||
114 | this.outgoingEdges = new HashMap(outgoingEdges) | ||
115 | } | ||
116 | |||
117 | static def private <NodeRep> int calculateDataHash( | ||
118 | NodeRep previousRepresentation, | ||
119 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges, | ||
120 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges) | ||
121 | { | ||
122 | val int prime = 31; | ||
123 | var int result = previousRepresentation.hashCode; | ||
124 | if(incomingEdges !== null) | ||
125 | result = prime * result + incomingEdges.hashCode(); | ||
126 | if(outgoingEdges !== null) | ||
127 | result = prime * result + outgoingEdges.hashCode(); | ||
128 | return result; | ||
129 | } | ||
130 | |||
131 | override hashCode() { | ||
132 | return this.dataHash.hashCode | ||
133 | } | 132 | } |
134 | 133 | ||
135 | override toString() { | 134 | static def private <NodeRep> int calculateDataHash(NodeRep previousRepresentation, |
136 | return class.name + dataHash | 135 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges, Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { |
137 | // return '''[«previousRepresentation»,(«FOR | 136 | val int prime = 31; |
138 | // in: incomingEdges.entrySet»(«in.key.type.name»=«in.key.from»,«in.value»)«ENDFOR»),(«FOR | 137 | var int result = previousRepresentation.hashCode; |
139 | // out: outgoingEdges.entrySet»(«out.key.type.name»=«out.key.to»,«out.value»)«ENDFOR»),«FOR | 138 | if (incomingEdges !== null) |
140 | // att: attributeValues»(«att.type.name»=«att.value»)«ENDFOR»]''' | 139 | result = prime * result + hashIncomingNeighborhood(incomingEdges) |
140 | if (outgoingEdges !== null) | ||
141 | result = prime * result + hashOutgoingNeighborhood(outgoingEdges) | ||
142 | return result; | ||
141 | } | 143 | } |
142 | |||
143 | // @Pure | ||
144 | // @Override | ||
145 | // override public boolean equals(Object obj) { | ||
146 | // if (this === obj) | ||
147 | // return true; | ||
148 | // if (obj === null) | ||
149 | // return false; | ||
150 | // if (getClass() != obj.getClass()) | ||
151 | // return false; | ||
152 | // val AbstractNodeDescriptor other = obj as AbstractNodeDescriptor; | ||
153 | // if (other.dataHash != this.dataHash) | ||
154 | // return false; | ||
155 | // return true; | ||
156 | // } | ||
157 | |||
158 | // @Pure | ||
159 | // override public boolean equals(Object obj) { | ||
160 | // if (this === obj) | ||
161 | // return true; | ||
162 | // if (obj === null) | ||
163 | // return false; | ||
164 | // if (getClass() != obj.getClass()) | ||
165 | // return false; | ||
166 | // if (!super.equals(obj)) | ||
167 | // return false; | ||
168 | // val FurtherNodeDescriptor<?> other = obj as FurtherNodeDescriptor<?>; | ||
169 | // if (this.previousRepresentation === null) { | ||
170 | // if (other.previousRepresentation != null) | ||
171 | // return false; | ||
172 | // | ||
173 | // } | ||
174 | //// } else if (!this.previousRepresentation.equals(other.previousRepresentation)) | ||
175 | //// return false; | ||
176 | // if (this.incomingEdges === null) { | ||
177 | // if (other.incomingEdges != null) | ||
178 | // return false; | ||
179 | // } else if (!this.incomingEdges.equals(other.incomingEdges)) | ||
180 | // return false; | ||
181 | // if (this.outgoingEdges === null) { | ||
182 | // if (other.outgoingEdges != null) | ||
183 | // return false; | ||
184 | // } else if (!this.outgoingEdges.equals(other.outgoingEdges)) | ||
185 | // return false; | ||
186 | // if (this.attributeValues === null) { | ||
187 | // if (other.attributeValues != null) | ||
188 | // return false; | ||
189 | // } else if (!this.attributeValues.equals(other.attributeValues)) | ||
190 | // return false; | ||
191 | // return true; | ||
192 | // } | ||
193 | } | ||
194 | 144 | ||
195 | /* | 145 | override hashCode() { |
196 | @Data | 146 | return this.dataHash |
197 | class ModelDescriptor { | 147 | } |
198 | int dataHash | 148 | |
199 | int unknownElements | 149 | override equals(Object other) { |
200 | Map<? extends AbstractNodeDescriptor,Integer> knownElements | 150 | other.class == FurtherNodeDescriptor && (other as AbstractNodeDescriptor).hashCode == hashCode |
151 | } | ||
152 | |||
153 | override prettyPrint() { | ||
154 | ''' | ||
155 | («dataHash»)[ | ||
156 | PREV = «previousRepresentation?.prettyPrint» | ||
157 | «IF incomingEdges === null» | ||
158 | IN null | ||
159 | «ELSE» | ||
160 | «FOR edge : incomingEdges.entrySet» | ||
161 | IN «edge.value» «edge.key.type» = «edge.key.from.prettyPrint» | ||
162 | «ENDFOR» | ||
163 | «ENDIF» | ||
164 | «IF outgoingEdges === null» | ||
165 | OUT null | ||
166 | «ELSE» | ||
167 | «FOR edge : outgoingEdges.entrySet» | ||
168 | OUT «edge.value» «edge.key.type» = «edge.key.to.prettyPrint» | ||
169 | «ENDFOR» | ||
170 | «ENDIF» | ||
171 | ]''' | ||
172 | } | ||
173 | |||
174 | private def StringConcatenationClient prettyPrint(NodeRep rep) { | ||
175 | if (rep instanceof AbstractNodeDescriptor) { | ||
176 | rep.prettyPrint | ||
177 | } else { | ||
178 | '''«rep»''' | ||
179 | } | ||
180 | } | ||
201 | 181 | ||
202 | public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) { | 182 | private static def <NodeRep> hashIncomingNeighborhood(Map<IncomingRelation<NodeRep>, Integer> neighborhood) { |
203 | this.dataHash = calculateDataHash(knownElements,unknownElements) | 183 | val int prime = 31 |
204 | this.unknownElements = unknownElements | 184 | var int hash = 0 |
205 | this.knownElements = knownElements | 185 | for (entry : neighborhood.entrySet) { |
186 | val relation = entry.key | ||
187 | hash += (prime * relation.from.hashCode + relation.type.hashCode).bitwiseXor(entry.value.hashCode) | ||
188 | } | ||
189 | hash | ||
206 | } | 190 | } |
207 | 191 | ||
208 | def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) | 192 | private static def <NodeRep> hashOutgoingNeighborhood(Map<OutgoingRelation<NodeRep>, Integer> neighborhood) { |
209 | { | 193 | val int prime = 31 |
210 | val int prime = 31; | 194 | var int hash = 0 |
211 | return knownElements.hashCode * prime + unknownElements.hashCode | 195 | for (entry : neighborhood.entrySet) { |
196 | val relation = entry.key | ||
197 | hash += (prime * relation.to.hashCode + relation.type.hashCode).bitwiseXor(entry.value.hashCode) | ||
198 | } | ||
199 | hash | ||
200 | } | ||
201 | |||
202 | override toString() { | ||
203 | ''' | ||
204 | «prettyPrint» | ||
205 | ''' | ||
212 | } | 206 | } |
213 | } | 207 | } |
214 | */ \ No newline at end of file | 208 | |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/NeighbourhoodOptions.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/NeighbourhoodOptions.xtend new file mode 100644 index 00000000..c6e03f75 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/NeighbourhoodOptions.xtend | |||
@@ -0,0 +1,22 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | ||
5 | import java.util.Set | ||
6 | import org.eclipse.xtend.lib.annotations.Data | ||
7 | |||
8 | @Data | ||
9 | class NeighbourhoodOptions { | ||
10 | public static val FixPointRange = -1 | ||
11 | public static val GraphWidthRange = -2 | ||
12 | public static val FullParallels = Integer.MAX_VALUE | ||
13 | public static val MaxNumbers = Integer.MAX_VALUE | ||
14 | |||
15 | public static val DEFAULT = new NeighbourhoodOptions(FixPointRange, FullParallels, MaxNumbers, null, null) | ||
16 | |||
17 | val int range | ||
18 | val int parallels | ||
19 | val int maxNumber | ||
20 | val Set<TypeDeclaration> relevantTypes | ||
21 | val Set<RelationDeclaration> relevantRelations | ||
22 | } | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend index d474877d..5da202eb 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend | |||
@@ -1,25 +1,33 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood |
2 | 2 | ||
3 | import java.util.Map | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | 3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement |
4 | import java.util.Map | ||
5 | import org.eclipse.collections.api.factory.Maps | ||
5 | 6 | ||
6 | class PartialInterpretation2Hash extends PartialInterpretation2NeighbourhoodRepresentation<Integer, Integer>{ | 7 | class PartialInterpretation2Hash extends PartialInterpretation2NeighbourhoodRepresentation<Integer, Integer>{ |
7 | 8 | ||
8 | protected new() { | 9 | new() { |
9 | super(false, true) | 10 | super(false, true) |
10 | } | 11 | } |
11 | 12 | ||
12 | override protected createLocalRepresentation(Map<DefinedElement, LocalNodeDescriptor> node2Representation, Map<LocalNodeDescriptor, Integer> representation2Amount) { | 13 | override protected createLocalRepresentation(Map<DefinedElement, LocalNodeDescriptor> node2Representation, Map<LocalNodeDescriptor, Integer> representation2Amount) { |
13 | return new NeighbourhoodWithTraces( | 14 | return new NeighbourhoodWithTraces( |
14 | representation2Amount.hashCode,node2Representation.mapValues[it.hashCode], | 15 | representation2Amount.hashCode,node2Representation.hashValues, |
15 | null) | 16 | null) |
16 | } | 17 | } |
17 | 18 | ||
18 | override protected createFurtherRepresentation(Map<FurtherNodeDescriptor<Integer>, Integer> nodeDescriptors, Map<DefinedElement, FurtherNodeDescriptor<Integer>> node2Representation, NeighbourhoodWithTraces<Integer, Integer> previous, boolean deepRepresentation) { | 19 | override protected createFurtherRepresentation(Map<FurtherNodeDescriptor<Integer>, Integer> nodeDescriptors, Map<DefinedElement, FurtherNodeDescriptor<Integer>> node2Representation, NeighbourhoodWithTraces<Integer, Integer> previous, boolean deepRepresentation) { |
19 | return new NeighbourhoodWithTraces( | 20 | return new NeighbourhoodWithTraces( |
20 | nodeDescriptors.hashCode, | 21 | nodeDescriptors.hashCode, |
21 | node2Representation.mapValues[it.hashCode], | 22 | node2Representation.hashValues, |
22 | if(deepRepresentation) {previous} else {null}) | 23 | if(deepRepresentation) {previous} else {null}) |
23 | } | 24 | } |
24 | 25 | ||
26 | private def <T> hashValues(Map<DefinedElement, T> map) { | ||
27 | val hashedMap = Maps.mutable.ofInitialCapacity(map.size) | ||
28 | for (entry : map.entrySet) { | ||
29 | hashedMap.put(entry.key, entry.value.hashCode) | ||
30 | } | ||
31 | hashedMap | ||
32 | } | ||
25 | } | 33 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2NeighbourhoodRepresentation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2NeighbourhoodRepresentation.xtend index 6dc40705..93eab816 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2NeighbourhoodRepresentation.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2NeighbourhoodRepresentation.xtend | |||
@@ -4,32 +4,34 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | |||
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.TypeDeclaration | 5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration |
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | 6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink |
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
8 | import java.util.HashMap | 9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation |
9 | import java.util.HashSet | 10 | import java.util.ArrayList |
10 | import java.util.LinkedList | ||
11 | import java.util.List | 11 | import java.util.List |
12 | import java.util.Map | 12 | import java.util.Map |
13 | import java.util.Set | 13 | import java.util.Set |
14 | import org.eclipse.collections.api.factory.Maps | ||
15 | import org.eclipse.collections.impl.factory.Sets | ||
14 | 16 | ||
15 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 17 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation | ||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | ||
18 | 18 | ||
19 | abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresentation,NodeRepresentation> { | 19 | abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresentation, NodeRepresentation> { |
20 | private val boolean deepRepresentation | 20 | val boolean deepRepresentation |
21 | private val boolean mergeSimilarNeighbourhood | 21 | val boolean mergeSimilarNeighbourhood |
22 | 22 | ||
23 | protected new(boolean deeprepresentation, boolean mergeSimilarNeighbourhood) { | 23 | protected new(boolean deeprepresentation, boolean mergeSimilarNeighbourhood) { |
24 | this.deepRepresentation = deeprepresentation | 24 | this.deepRepresentation = deeprepresentation |
25 | this.mergeSimilarNeighbourhood = mergeSimilarNeighbourhood | 25 | this.mergeSimilarNeighbourhood = mergeSimilarNeighbourhood |
26 | } | 26 | } |
27 | 27 | ||
28 | public static val FixPointRage = -1 | 28 | public static val FixPointRange = NeighbourhoodOptions.FixPointRange |
29 | public static val GraphWidthRange = -2 | 29 | public static val GraphWidthRange = NeighbourhoodOptions.GraphWidthRange |
30 | public static val FullParallels = Integer.MAX_VALUE | 30 | public static val FullParallels = NeighbourhoodOptions.FullParallels |
31 | public static val MaxNumbers = Integer.MAX_VALUE | 31 | public static val MaxNumbers = NeighbourhoodOptions.MaxNumbers |
32 | 32 | ||
33 | static val FOCUSED_ELEMENT_NAME = "<<THIS>>" | ||
34 | |||
33 | /** | 35 | /** |
34 | * Creates a neighbourhood representation with traces | 36 | * Creates a neighbourhood representation with traces |
35 | * @param model The model to be represented. | 37 | * @param model The model to be represented. |
@@ -37,10 +39,15 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
37 | * @param parallels The maximal number of parallel references to be differentiated. | 39 | * @param parallels The maximal number of parallel references to be differentiated. |
38 | * @param maxNumber The maximal number of elements in a equivalence class that chan be differentiated. | 40 | * @param maxNumber The maximal number of elements in a equivalence class that chan be differentiated. |
39 | */ | 41 | */ |
40 | def public createRepresentation(PartialInterpretation model, int range, int parallels, int maxNumber) { | 42 | def createRepresentation(PartialInterpretation model, int range, int parallels, int maxNumber) { |
41 | return createRepresentation(model,range,parallels,maxNumber,null,null) | 43 | return createRepresentation(model, range, parallels, maxNumber, null, null) |
44 | } | ||
45 | |||
46 | def createRepresentation(PartialInterpretation model, NeighbourhoodOptions options) { | ||
47 | createRepresentation(model, options.range, options.parallels, options.maxNumber, options.relevantTypes, | ||
48 | options.relevantRelations) | ||
42 | } | 49 | } |
43 | 50 | ||
44 | /** | 51 | /** |
45 | * Creates a neighbourhood representation with traces | 52 | * Creates a neighbourhood representation with traces |
46 | * @param model The model to be represented. | 53 | * @param model The model to be represented. |
@@ -48,72 +55,87 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
48 | * @param parallels The maximal number of parallel references to be differentiated. | 55 | * @param parallels The maximal number of parallel references to be differentiated. |
49 | * @param maxNumber The maximal number of elements in a equivalence class that chan be differentiated. | 56 | * @param maxNumber The maximal number of elements in a equivalence class that chan be differentiated. |
50 | */ | 57 | */ |
51 | def public createRepresentation( | 58 | def createRepresentation(PartialInterpretation model, int range, int parallels, int maxNumber, |
52 | PartialInterpretation model, | 59 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations) { |
53 | int range, int parallels, int maxNumber, | 60 | createRepresentationWithFocus(model, range, parallels, maxNumber, relevantTypes, relevantRelations, null) |
54 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations) | 61 | } |
55 | { | 62 | |
56 | val Map<DefinedElement, Set<String>> types = new HashMap | 63 | def createRepresentationWithFocus(PartialInterpretation model, NeighbourhoodOptions options, |
57 | fillTypes(model,types,relevantTypes) | 64 | DefinedElement focusedElement) { |
58 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = new HashMap; | 65 | createRepresentationWithFocus(model, options.range, options.parallels, options.maxNumber, options.relevantTypes, |
59 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = new HashMap; | 66 | options.relevantRelations, focusedElement) |
60 | fillReferences(model,IncomingRelations,OutgoingRelations,relevantRelations) | 67 | } |
61 | 68 | ||
62 | val res = doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,range,parallels,maxNumber); | 69 | def createRepresentationWithFocus(PartialInterpretation model, int range, int parallels, int maxNumber, |
63 | 70 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations, DefinedElement focusedElement) { | |
71 | val initialSize = model.elements.size | ||
72 | val Map<DefinedElement, Set<String>> types = Maps.mutable.ofInitialCapacity(initialSize) | ||
73 | fillTypes(model, types, relevantTypes) | ||
74 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = Maps.mutable.ofInitialCapacity(initialSize); | ||
75 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = Maps.mutable.ofInitialCapacity(initialSize); | ||
76 | fillReferences(model, IncomingRelations, OutgoingRelations, relevantRelations) | ||
77 | |||
78 | val res = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, range, parallels, | ||
79 | maxNumber, focusedElement); | ||
80 | |||
64 | return res; | 81 | return res; |
65 | } | 82 | } |
66 | 83 | ||
67 | def private isRelevant(TypeDeclaration t, Set<TypeDeclaration> relevantTypes) { | 84 | def private isRelevant(TypeDeclaration t, Set<TypeDeclaration> relevantTypes) { |
68 | if(relevantTypes === null) { | 85 | if (relevantTypes === null) { |
69 | return true | 86 | return true |
70 | } else { | 87 | } else { |
71 | return relevantTypes.contains(t) | 88 | return relevantTypes.contains(t) |
72 | } | 89 | } |
73 | } | 90 | } |
91 | |||
74 | def private isRelevant(RelationDeclaration r, Set<RelationDeclaration> relevantRelations) { | 92 | def private isRelevant(RelationDeclaration r, Set<RelationDeclaration> relevantRelations) { |
75 | if(relevantRelations === null) { | 93 | if (relevantRelations === null) { |
76 | return true | 94 | return true |
77 | } else { | 95 | } else { |
78 | return relevantRelations.contains(r) | 96 | return relevantRelations.contains(r) |
79 | } | 97 | } |
80 | } | 98 | } |
99 | |||
81 | /** | 100 | /** |
82 | * Gets the largest | 101 | * Gets the minimal neighbourhood size such that every reachable node appears in the shape of every other at least once. |
83 | */ | 102 | */ |
84 | def private getWidth(Map<DefinedElement, Set<String>> types, | 103 | def private getWidth(Map<DefinedElement, Set<String>> types, |
85 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 104 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
86 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) | 105 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) { |
87 | { | 106 | val elements = types.keySet |
88 | val elements = types.keySet | 107 | var Map<DefinedElement, Set<DefinedElement>> reachable = Maps.mutable.ofInitialCapacity(elements.size) |
89 | val Map<DefinedElement,Set<DefinedElement>> reachable = new HashMap | 108 | var Map<DefinedElement, Set<DefinedElement>> newReachable = Maps.mutable.ofInitialCapacity(elements.size) |
90 | for(element : elements) { | 109 | for (element : elements) { |
91 | val set = new HashSet | 110 | val set = Sets.mutable.of |
92 | set.add(element) | 111 | set.add(element) |
93 | reachable.put(element,set) | 112 | reachable.put(element, Sets.mutable.of) |
113 | newReachable.put(element, set) | ||
94 | } | 114 | } |
95 | 115 | ||
96 | var int width = 0 | 116 | var int width = 0 |
97 | var boolean newAdded | 117 | var boolean newAdded |
98 | do { | 118 | do { |
119 | var tmp = reachable | ||
120 | reachable = newReachable | ||
121 | newReachable = tmp | ||
99 | newAdded = false | 122 | newAdded = false |
100 | for(element : elements) { | 123 | for (element : elements) { |
101 | val elementNeigbours = element.lookup(reachable) | 124 | val elementNeigbours = element.lookup(reachable) |
102 | val size = elementNeigbours.size | 125 | val newElementNeigbours = element.lookup(newReachable) |
103 | for(incoming : element.lookup(IncomingRelations)) { | 126 | newElementNeigbours.addAll(elementNeigbours) |
104 | elementNeigbours.addAll(incoming.from.lookup(reachable)) | 127 | for (incoming : element.lookup(IncomingRelations)) { |
128 | newElementNeigbours.addAll(incoming.from.lookup(reachable)) | ||
105 | } | 129 | } |
106 | for(outgoing : element.lookup(OutgoingRelations)) { | 130 | for (outgoing : element.lookup(OutgoingRelations)) { |
107 | elementNeigbours.addAll(outgoing.to.lookup(reachable)) | 131 | newElementNeigbours.addAll(outgoing.to.lookup(reachable)) |
108 | } | 132 | } |
109 | newAdded = newAdded || (elementNeigbours.size > size) | 133 | newAdded = newAdded || (newElementNeigbours.size > elementNeigbours.size) |
110 | } | 134 | } |
111 | 135 | width += 1 | |
112 | width +=1 | 136 | } while (newAdded) |
113 | } while(newAdded) | ||
114 | return width | 137 | return width |
115 | } | 138 | } |
116 | |||
117 | /** | 139 | /** |
118 | * Creates a neighbourhood representation with traces | 140 | * Creates a neighbourhood representation with traces |
119 | * @param model The model to be represented. | 141 | * @param model The model to be represented. |
@@ -122,68 +144,71 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
122 | * @param range The range of the neighbourhood. | 144 | * @param range The range of the neighbourhood. |
123 | * @param parallels The maximal number of parallel references to be differentiated. | 145 | * @param parallels The maximal number of parallel references to be differentiated. |
124 | */ | 146 | */ |
125 | def private NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> doRecursiveNeighbourCalculation( | 147 | def private NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> doRecursiveNeighbourCalculation( |
126 | PartialInterpretation model, | 148 | PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
127 | Map<DefinedElement, Set<String>> types, | ||
128 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 149 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
129 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 150 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int range, int parallels, |
130 | int range, int parallels, int maxNumber) | 151 | int maxNumber, DefinedElement focusedElement) { |
131 | { | 152 | if (range == 0) { |
132 | if(range == 0){ | 153 | val r = calculateLocalNodeDescriptors(model, types, maxNumber, focusedElement) |
133 | val r = calculateLocalNodeDescriptors(model,types,maxNumber) | 154 | val res = this.createLocalRepresentation(r.value, r.key) |
134 | val res = this.createLocalRepresentation(r.value,r.key) | 155 | if (res.modelRepresentation === null) { |
135 | if(res.modelRepresentation === null) { | ||
136 | throw new IllegalArgumentException('''Model representation is null''') | 156 | throw new IllegalArgumentException('''Model representation is null''') |
137 | } else if(res.nodeRepresentations === null || res.nodeRepresentations.empty) { | 157 | } else if (res.nodeRepresentations === null || res.nodeRepresentations.empty) { |
138 | throw new IllegalArgumentException('''No node representation''') | 158 | throw new IllegalArgumentException('''No node representation''') |
139 | } else if(res.previousRepresentation !== null) { | 159 | } else if (res.previousRepresentation !== null) { |
140 | throw new IllegalArgumentException('''The previous representation of the first neighbourhood have to be null''') | 160 | throw new IllegalArgumentException('''The previous representation of the first neighbourhood have to be null''') |
141 | } else return res | 161 | } else |
142 | } else if(range > 0) { | 162 | return res |
143 | val previous = doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,range-1,parallels,maxNumber) | 163 | } else if (range > 0) { |
144 | val r = calculateFurtherNodeDescriptors(model,previous,IncomingRelations,OutgoingRelations,parallels,maxNumber) | 164 | val previous = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, |
145 | //println('''Level «range» finished.''') | 165 | range - 1, parallels, maxNumber, focusedElement) |
146 | val res = createFurtherRepresentation(r.key,r.value,previous,deepRepresentation) | 166 | val r = calculateFurtherNodeDescriptors(model, previous, IncomingRelations, OutgoingRelations, parallels, |
147 | if(res.modelRepresentation === null) { | 167 | maxNumber) |
168 | // println('''Level «range» finished.''') | ||
169 | val res = createFurtherRepresentation(r.key, r.value, previous, deepRepresentation) | ||
170 | if (res.modelRepresentation === null) { | ||
148 | throw new IllegalArgumentException('''Model representation is null''') | 171 | throw new IllegalArgumentException('''Model representation is null''') |
149 | } else if(res.nodeRepresentations === null || res.nodeRepresentations.empty) { | 172 | } else if (res.nodeRepresentations === null || res.nodeRepresentations.empty) { |
150 | throw new IllegalArgumentException('''No node representation''') | 173 | throw new IllegalArgumentException('''No node representation''') |
151 | } else if(res.previousRepresentation === null && deepRepresentation) { | 174 | } else if (res.previousRepresentation === null && deepRepresentation) { |
152 | throw new IllegalArgumentException('''Need previous representations''') | 175 | throw new IllegalArgumentException('''Need previous representations''') |
153 | } else return res | 176 | } else |
154 | } else if (range == FixPointRage) { | 177 | return res |
155 | return refineUntilFixpoint(model,types,IncomingRelations,OutgoingRelations,parallels,maxNumber) | 178 | } else if (range == FixPointRange) { |
179 | return refineUntilFixpoint(model, types, IncomingRelations, OutgoingRelations, parallels, maxNumber, | ||
180 | focusedElement) | ||
156 | } else if (range == GraphWidthRange) { | 181 | } else if (range == GraphWidthRange) { |
157 | val width = this.getWidth(types,IncomingRelations,OutgoingRelations) | 182 | val width = this.getWidth(types, IncomingRelations, OutgoingRelations) |
158 | //println(width) | 183 | // println(width) |
159 | return doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,width,parallels,maxNumber) | 184 | return doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, width, parallels, |
185 | maxNumber, focusedElement) | ||
160 | } | 186 | } |
161 | } | 187 | } |
162 | 188 | ||
163 | def private refineUntilFixpoint( | 189 | def private refineUntilFixpoint(PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
164 | PartialInterpretation model, | ||
165 | Map<DefinedElement, Set<String>> types, | ||
166 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 190 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
167 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 191 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, int maxNumbers, |
168 | int parallels, int maxNumbers) | 192 | DefinedElement focusedElement) { |
169 | { | ||
170 | var lastRange = 0 | 193 | var lastRange = 0 |
171 | val last = calculateLocalNodeDescriptors(model,types,maxNumbers) | 194 | val last = calculateLocalNodeDescriptors(model, types, maxNumbers, focusedElement) |
172 | var lastRepresentation = this.createLocalRepresentation(last.value,last.key) | 195 | var lastRepresentation = this.createLocalRepresentation(last.value, last.key) |
173 | //println('''Level 0 finished.''') | 196 | // println('''Level 0 finished.''') |
174 | var boolean hasRefined | 197 | var boolean hasRefined |
175 | do { | 198 | do { |
176 | val nextRange = lastRange+1 | 199 | val nextRange = lastRange + 1 |
177 | val next = calculateFurtherNodeDescriptors(model,lastRepresentation,IncomingRelations,OutgoingRelations,parallels,maxNumbers) | 200 | val next = calculateFurtherNodeDescriptors(model, lastRepresentation, IncomingRelations, OutgoingRelations, |
178 | val nextRepresentation = createFurtherRepresentation(next.key,next.value,lastRepresentation,deepRepresentation) | 201 | parallels, maxNumbers) |
179 | 202 | val nextRepresentation = createFurtherRepresentation(next.key, next.value, lastRepresentation, | |
180 | val previousNumberOfTypes =lastRepresentation.nodeRepresentations.values.toSet.size | 203 | deepRepresentation) |
181 | val nextNumberOfTypes = nextRepresentation.nodeRepresentations.values.toSet.size | 204 | |
182 | hasRefined = nextNumberOfTypes > previousNumberOfTypes | 205 | val previousNumberOfTypes = Sets.immutable.withAll(lastRepresentation.nodeRepresentations.values).size |
183 | 206 | val nextNumberOfTypes = Sets.immutable.withAll(nextRepresentation.nodeRepresentations.values).size | |
207 | hasRefined = nextNumberOfTypes > previousNumberOfTypes | ||
208 | |||
184 | lastRange = nextRange | 209 | lastRange = nextRange |
185 | lastRepresentation = nextRepresentation | 210 | lastRepresentation = nextRepresentation |
186 | 211 | ||
187 | // if(hasRefined) { | 212 | // if(hasRefined) { |
188 | // println('''Level «nextRange» is calculated, number of types is refined: «previousNumberOfTypes» -> «nextNumberOfTypes»''') | 213 | // println('''Level «nextRange» is calculated, number of types is refined: «previousNumberOfTypes» -> «nextNumberOfTypes»''') |
189 | // } else { | 214 | // } else { |
@@ -192,211 +217,217 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
192 | } while (hasRefined) | 217 | } while (hasRefined) |
193 | return lastRepresentation | 218 | return lastRepresentation |
194 | } | 219 | } |
195 | 220 | ||
196 | def private getElements(PartialInterpretation model) { | 221 | def private getElements(PartialInterpretation model) { |
197 | return | 222 | return model.problem.elements + model.newElements + model.openWorldElements |
198 | model.problem.elements + | ||
199 | model.newElements + | ||
200 | model.openWorldElements | ||
201 | } | 223 | } |
202 | 224 | ||
203 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, Set<TypeDeclaration> relevantTypes) { | 225 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, |
204 | for(element : model.elements) { | 226 | Set<TypeDeclaration> relevantTypes) { |
205 | node2Type.put(element, new HashSet) | 227 | for (element : model.elements) { |
228 | node2Type.put(element, Sets.mutable.of) | ||
206 | } | 229 | } |
207 | 230 | ||
208 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { | 231 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { |
209 | // // Dont need | 232 | // // Dont need |
210 | // } | 233 | // } |
211 | for(typeInterpretation : model.partialtypeinterpratation) { | 234 | for (typeInterpretation : model.partialtypeinterpratation) { |
212 | if(typeInterpretation instanceof PartialPrimitiveInterpretation) { | 235 | if (typeInterpretation instanceof PartialPrimitiveInterpretation) { |
213 | 236 | } else if (typeInterpretation instanceof PartialComplexTypeInterpretation) { | |
214 | } else if(typeInterpretation instanceof PartialComplexTypeInterpretation) { | ||
215 | val type = typeInterpretation.interpretationOf | 237 | val type = typeInterpretation.interpretationOf |
216 | if(type.isRelevant(relevantTypes)) { | 238 | if (type.isRelevant(relevantTypes)) { |
217 | for(element : typeInterpretation.elements) { | 239 | for (element : typeInterpretation.elements) { |
218 | element.lookup(node2Type).add(type.name) | 240 | element.lookup(node2Type).add(type.name) |
219 | } | 241 | } |
220 | } | 242 | } |
221 | } | 243 | } |
222 | } | 244 | } |
223 | } | 245 | } |
224 | 246 | ||
225 | /** | 247 | /** |
226 | * Indexes the references | 248 | * Indexes the references |
227 | */ | 249 | */ |
228 | def private fillReferences(PartialInterpretation model, | 250 | def private fillReferences(PartialInterpretation model, |
229 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 251 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
230 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 252 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
231 | Set<RelationDeclaration> relevantRelations) | 253 | Set<RelationDeclaration> relevantRelations) { |
232 | { | 254 | for (object : model.elements) { |
233 | for(object : model.elements) { | 255 | IncomingRelations.put(object, new ArrayList) |
234 | IncomingRelations.put(object,new LinkedList) | 256 | OutgoingRelations.put(object, new ArrayList) |
235 | OutgoingRelations.put(object,new LinkedList) | ||
236 | } | 257 | } |
237 | for(relationInterpretation : model.partialrelationinterpretation) { | 258 | for (relationInterpretation : model.partialrelationinterpretation) { |
238 | val type = relationInterpretation.interpretationOf | 259 | val type = relationInterpretation.interpretationOf |
239 | if(type.isRelevant(relevantRelations)) { | 260 | if (type.isRelevant(relevantRelations)) { |
240 | for(link : relationInterpretation.relationlinks) { | 261 | for (link : relationInterpretation.relationlinks) { |
241 | if(link instanceof BinaryElementRelationLink) { | 262 | if (link instanceof BinaryElementRelationLink) { |
242 | OutgoingRelations.get(link.param1) += new OutgoingRelation(link.param2,type.name) | 263 | OutgoingRelations.get(link.param1) += new OutgoingRelation(link.param2, type.name) |
243 | IncomingRelations.get(link.param2) += new IncomingRelation(link.param1,type.name) | 264 | IncomingRelations.get(link.param2) += new IncomingRelation(link.param1, type.name) |
244 | } else throw new UnsupportedOperationException | 265 | } else |
266 | throw new UnsupportedOperationException | ||
245 | } | 267 | } |
246 | } | 268 | } |
247 | } | 269 | } |
248 | } | 270 | } |
249 | 271 | ||
250 | /** | 272 | /** |
251 | * Creates a local representation of the objects (aka zero range neighbourhood) | 273 | * Creates a local representation of the objects (aka zero range neighbourhood) |
252 | */ | 274 | */ |
253 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> createLocalRepresentation( | 275 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> createLocalRepresentation( |
254 | Map<DefinedElement, LocalNodeDescriptor> node2Representation, | 276 | Map<DefinedElement, LocalNodeDescriptor> node2Representation, |
255 | Map<LocalNodeDescriptor, Integer> representation2Amount | 277 | Map<LocalNodeDescriptor, Integer> representation2Amount |
256 | ) | 278 | ) |
257 | 279 | ||
258 | /** | 280 | /** |
259 | * Creates a | 281 | * Creates a |
260 | */ | 282 | */ |
261 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> createFurtherRepresentation( | 283 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> createFurtherRepresentation( |
262 | Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> nodeDescriptors, | 284 | Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> nodeDescriptors, |
263 | Map<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> node2Representation, | 285 | Map<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> node2Representation, |
264 | NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> previous, | 286 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, |
265 | boolean deepRepresentation | 287 | boolean deepRepresentation |
266 | ) | 288 | ) |
267 | 289 | ||
268 | def private addOne(int original, int max) { | 290 | def private addOne(Integer originalObj, int max) { |
291 | if (originalObj === null) { | ||
292 | return 1 | ||
293 | } | ||
294 | val original = originalObj.intValue | ||
269 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE | 295 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE |
270 | if(original +1 > max) return Integer.MAX_VALUE | 296 | if(original + 1 > max) return Integer.MAX_VALUE else return original + 1 |
271 | else return original+1 | ||
272 | } | 297 | } |
273 | 298 | ||
274 | private def calculateIncomingEdges(Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 299 | private def calculateIncomingEdges(Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
275 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) | 300 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, |
276 | { | 301 | int parallel) { |
277 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = new HashMap | 302 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = Maps.mutable.of |
278 | for (incomingConcreteEdge : IncomingRelations.get(object)) { | 303 | for (incomingConcreteEdge : IncomingRelations.get(object)) { |
279 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( | 304 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( |
280 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) | 305 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) |
281 | if (res.containsKey(e)) { | 306 | res.compute(e, [key, value | addOne(value, parallel)]) |
282 | res.put(e, addOne(res.get(e),parallel)) | ||
283 | } else { | ||
284 | res.put(e, 1) | ||
285 | } | ||
286 | } | 307 | } |
287 | return res | 308 | return res |
288 | } | 309 | } |
289 | 310 | ||
290 | private def calcuateOutgoingEdges(Map<DefinedElement,List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 311 | private def calcuateOutgoingEdges(Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
291 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) | 312 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, |
292 | { | 313 | int parallel) { |
293 | val Map<OutgoingRelation<NodeRepresentation>,Integer> res= new HashMap | 314 | val Map<OutgoingRelation<NodeRepresentation>, Integer> res = Maps.mutable.of |
294 | for(outgoingConcreteEdge : OutgoingRelations.get(object)) { | 315 | for (outgoingConcreteEdge : OutgoingRelations.get(object)) { |
295 | val OutgoingRelation<NodeRepresentation> e = | 316 | val OutgoingRelation<NodeRepresentation> e = new OutgoingRelation( |
296 | new OutgoingRelation( | 317 | previousNodeRepresentations.get(outgoingConcreteEdge.to), outgoingConcreteEdge.type) |
297 | previousNodeRepresentations.get(outgoingConcreteEdge.to), | 318 | res.compute(e, [key, value | addOne(value, parallel)]) |
298 | outgoingConcreteEdge.type) | ||
299 | if(res.containsKey(e)) { | ||
300 | res.put(e,addOne(res.get(e),parallel)) | ||
301 | } else { | ||
302 | res.put(e,1) | ||
303 | } | ||
304 | } | 319 | } |
305 | return res; | 320 | return res |
306 | } | 321 | } |
307 | 322 | ||
308 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { | 323 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { |
309 | var Set<VALUE> s; | 324 | * var Set<VALUE> s; |
310 | if(map.containsKey(key)) { | 325 | * if(map.containsKey(key)) { |
311 | s = map.get(key); | 326 | * s = map.get(key); |
312 | } else { | 327 | * } else { |
313 | s = new HashSet | 328 | * s = new HashSet |
314 | map.put(key,s) | 329 | * map.put(key,s) |
315 | } | 330 | * } |
316 | s.add(value) | 331 | * s.add(value) |
317 | }*/ | 332 | }*/ |
318 | 333 | private def calculateFurtherNodeDescriptors(PartialInterpretation model, | |
319 | |||
320 | private def calculateFurtherNodeDescriptors( | ||
321 | PartialInterpretation model, | ||
322 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, | 334 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, |
323 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 335 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
324 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 336 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, int maxNumber) { |
325 | int parallels, int maxNumber) | ||
326 | { | ||
327 | val previousNodeRepresentations = previous.nodeRepresentations | 337 | val previousNodeRepresentations = previous.nodeRepresentations |
328 | val node2Representation = new HashMap<DefinedElement,FurtherNodeDescriptor<NodeRepresentation>> | 338 | val size = previousNodeRepresentations.size |
329 | val Map<FurtherNodeDescriptor<NodeRepresentation>,Integer> descriptor2Number = | 339 | val node2Representation = Maps.mutable.<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>>ofInitialCapacity(size) |
330 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | 340 | val Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> descriptor2Number = if (this. |
331 | val Map<FurtherNodeDescriptor<NodeRepresentation>,FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = | 341 | mergeSimilarNeighbourhood) { |
332 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | 342 | Maps.mutable.ofInitialCapacity(size) |
333 | 343 | } else { | |
334 | for(object: model.elements) { | 344 | null |
335 | val incomingEdges = this.calculateIncomingEdges(IncomingRelations, object, previousNodeRepresentations,parallels) | 345 | } |
336 | val outgoingEdges = this.calcuateOutgoingEdges(OutgoingRelations,object, previousNodeRepresentations,parallels) | 346 | val Map<FurtherNodeDescriptor<NodeRepresentation>, FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = if (this. |
337 | 347 | mergeSimilarNeighbourhood) { | |
348 | Maps.mutable.ofInitialCapacity(size) | ||
349 | } else { | ||
350 | null | ||
351 | } | ||
352 | |||
353 | for (object : model.elements) { | ||
354 | val incomingEdges = this.calculateIncomingEdges(IncomingRelations, object, previousNodeRepresentations, | ||
355 | parallels) | ||
356 | val outgoingEdges = this.calcuateOutgoingEdges(OutgoingRelations, object, previousNodeRepresentations, | ||
357 | parallels) | ||
358 | |||
338 | val previousType = previousNodeRepresentations.get(object) | 359 | val previousType = previousNodeRepresentations.get(object) |
339 | 360 | ||
340 | if(previousType === null) { | 361 | if (previousType === null) { |
341 | println("Error in state coder") | 362 | println("Error in state coder") |
342 | } | 363 | } |
343 | 364 | ||
344 | val nodeDescriptor = new FurtherNodeDescriptor( | 365 | val nodeDescriptor = new FurtherNodeDescriptor(previousType, incomingEdges, outgoingEdges) |
345 | previousType, | 366 | |
346 | incomingEdges, | 367 | if (this.mergeSimilarNeighbourhood) { |
347 | outgoingEdges) | 368 | if (descriptor2Number.containsKey(nodeDescriptor)) { |
348 | |||
349 | if(this.mergeSimilarNeighbourhood) { | ||
350 | if(descriptor2Number.containsKey(nodeDescriptor)) { | ||
351 | descriptor2Number.put( | 369 | descriptor2Number.put( |
352 | nodeDescriptor, | 370 | nodeDescriptor, |
353 | addOne(descriptor2Number.get(nodeDescriptor),maxNumber) | 371 | addOne(descriptor2Number.get(nodeDescriptor), maxNumber) |
354 | ) | 372 | ) |
355 | node2Representation.put(object,uniqueDescription.get(nodeDescriptor)) | 373 | node2Representation.put(object, uniqueDescription.get(nodeDescriptor)) |
356 | } else { | 374 | } else { |
357 | descriptor2Number.put(nodeDescriptor,if(1>maxNumber){Integer.MAX_VALUE}else{1}) | 375 | descriptor2Number.put(nodeDescriptor, if (1 > maxNumber) { |
358 | uniqueDescription.put(nodeDescriptor,nodeDescriptor) | 376 | Integer.MAX_VALUE |
359 | node2Representation.put(object,nodeDescriptor) | 377 | } else { |
378 | 1 | ||
379 | }) | ||
380 | uniqueDescription.put(nodeDescriptor, nodeDescriptor) | ||
381 | node2Representation.put(object, nodeDescriptor) | ||
360 | } | 382 | } |
361 | } else { | 383 | } else { |
362 | node2Representation.put(object,nodeDescriptor) | 384 | node2Representation.put(object, nodeDescriptor) |
363 | } | 385 | } |
364 | } | 386 | } |
365 | 387 | ||
366 | return descriptor2Number -> node2Representation | 388 | return descriptor2Number -> node2Representation |
367 | } | 389 | } |
368 | 390 | ||
369 | private def calculateLocalNodeDescriptors( | 391 | private def calculateLocalNodeDescriptors(PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
370 | PartialInterpretation model, | 392 | int maxNumber, DefinedElement focusedElement) { |
371 | Map<DefinedElement, Set<String>> types, | 393 | val size = types.size |
372 | int maxNumber) | 394 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = Maps.mutable.ofInitialCapacity(size) |
373 | { | 395 | val Map<LocalNodeDescriptor, Integer> representation2Amount = if (mergeSimilarNeighbourhood) { |
374 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = new HashMap | 396 | Maps.mutable.ofInitialCapacity(size) |
375 | val Map<LocalNodeDescriptor, Integer> representation2Amount = | 397 | } else { |
376 | if(mergeSimilarNeighbourhood){ new HashMap } else { null } | 398 | null |
377 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = | 399 | } |
378 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | 400 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = if (this.mergeSimilarNeighbourhood) { |
379 | 401 | Maps.mutable.ofInitialCapacity(size) | |
380 | for(element : model.elements) { | 402 | } else { |
381 | var newDescriptor = new LocalNodeDescriptor(element.name,element.lookup(types)) | 403 | null |
382 | if(this.mergeSimilarNeighbourhood){ | 404 | } |
383 | if(uniqueRepresentation.containsKey(newDescriptor)) { | 405 | |
406 | for (element : model.elements) { | ||
407 | val name = if(element == focusedElement) FOCUSED_ELEMENT_NAME else element.name | ||
408 | var newDescriptor = new LocalNodeDescriptor(name, element.lookup(types)) | ||
409 | if (this.mergeSimilarNeighbourhood) { | ||
410 | if (uniqueRepresentation.containsKey(newDescriptor)) { | ||
384 | newDescriptor = newDescriptor.lookup(uniqueRepresentation) | 411 | newDescriptor = newDescriptor.lookup(uniqueRepresentation) |
385 | node2Representation.put(element,newDescriptor) | 412 | node2Representation.put(element, newDescriptor) |
386 | representation2Amount.put( | 413 | representation2Amount.put( |
387 | newDescriptor, | 414 | newDescriptor, |
388 | addOne(newDescriptor.lookup(representation2Amount),maxNumber) | 415 | addOne(newDescriptor.lookup(representation2Amount), maxNumber) |
389 | ) | 416 | ) |
390 | } else { | 417 | } else { |
391 | uniqueRepresentation.put(newDescriptor,newDescriptor) | 418 | uniqueRepresentation.put(newDescriptor, newDescriptor) |
392 | node2Representation.put(element,newDescriptor) | 419 | node2Representation.put(element, newDescriptor) |
393 | representation2Amount.put(newDescriptor, if(1>maxNumber){Integer.MAX_VALUE}else{1}) | 420 | representation2Amount.put(newDescriptor, if (1 > maxNumber) { |
421 | Integer.MAX_VALUE | ||
422 | } else { | ||
423 | 1 | ||
424 | }) | ||
394 | } | 425 | } |
395 | } else { | 426 | } else { |
396 | node2Representation.put(element,newDescriptor) | 427 | node2Representation.put(element, newDescriptor) |
397 | } | 428 | } |
398 | } | 429 | } |
399 | 430 | ||
400 | return representation2Amount -> node2Representation | 431 | return representation2Amount -> node2Representation |
401 | } | 432 | } |
402 | } \ No newline at end of file | 433 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2PairwiseNeighbourhoodRepresentation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2PairwiseNeighbourhoodRepresentation.xtend new file mode 100644 index 00000000..c10457b0 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2PairwiseNeighbourhoodRepresentation.xtend | |||
@@ -0,0 +1,68 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood | ||
2 | |||
3 | import com.google.common.collect.Maps | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
6 | import java.util.HashMap | ||
7 | import java.util.Map | ||
8 | import org.eclipse.xtend.lib.annotations.Data | ||
9 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
10 | |||
11 | @Data | ||
12 | class PairwiseNeighbourhoodRepresentation<BasicNodeRepresentation> { | ||
13 | val Map<?, Integer> modelRepresentation | ||
14 | val Map<DefinedElement, BasicNodeRepresentation> basicNodeRepresentations | ||
15 | val Map<DefinedElement, ? extends Map<DefinedElement, ? extends BasicNodeRepresentation>> pairwiseNodeRepresentations | ||
16 | |||
17 | def getBasicRepresentation(DefinedElement a) { | ||
18 | basicNodeRepresentations.get(a) | ||
19 | } | ||
20 | |||
21 | def getPairwiseRepresentation(DefinedElement a, DefinedElement b) { | ||
22 | pairwiseNodeRepresentations.get(a).get(b) | ||
23 | } | ||
24 | } | ||
25 | |||
26 | @FinalFieldsConstructor | ||
27 | class PartialInterpretation2PairwiseNeighbourhoodRepresentation<BasicNodeRepresentation> { | ||
28 | val PartialInterpretation2NeighbourhoodRepresentation<? extends Map<? extends BasicNodeRepresentation, Integer>, BasicNodeRepresentation> basicNeighbourhoodRepresenter | ||
29 | |||
30 | def createRepresentation(PartialInterpretation model, NeighbourhoodOptions options) { | ||
31 | val basicRepresentation = basicNeighbourhoodRepresenter.createRepresentation(model, options) | ||
32 | val basicModelRepresentation = basicRepresentation.modelRepresentation | ||
33 | val basicNodeRepresentations = basicRepresentation.nodeRepresentations | ||
34 | val pairwiseNodeRepresentations = Maps.newHashMapWithExpectedSize(basicNodeRepresentations.size) | ||
35 | val modelRepresentation = new HashMap<Object, Integer> | ||
36 | for (nodeWithBasicRepresentation : basicNodeRepresentations.entrySet) { | ||
37 | val node = nodeWithBasicRepresentation.key | ||
38 | val basicNodeRepresentation = nodeWithBasicRepresentation.value | ||
39 | val count = basicModelRepresentation.get(basicNodeRepresentation) | ||
40 | if (count == 1) { | ||
41 | pairwiseNodeRepresentations.put(node, basicNodeRepresentations) | ||
42 | modelRepresentation.put(basicNodeRepresentation, count) | ||
43 | } else { | ||
44 | val neighbourhoodRepresentation = basicNeighbourhoodRepresenter. | ||
45 | createRepresentationWithFocus(model, options, node) | ||
46 | pairwiseNodeRepresentations.put(node, neighbourhoodRepresentation.nodeRepresentations) | ||
47 | modelRepresentation.compute(neighbourhoodRepresentation.modelRepresentation) [ key, value | | ||
48 | if (value === null) { | ||
49 | if (1 > options.maxNumber) { | ||
50 | Integer.MAX_VALUE | ||
51 | } else { | ||
52 | 1 | ||
53 | } | ||
54 | } else { | ||
55 | addOne(value, options.maxNumber) | ||
56 | } | ||
57 | ] | ||
58 | } | ||
59 | } | ||
60 | new PairwiseNeighbourhoodRepresentation(modelRepresentation, basicNodeRepresentations, | ||
61 | pairwiseNodeRepresentations) | ||
62 | } | ||
63 | |||
64 | def private addOne(int original, int max) { | ||
65 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE | ||
66 | if(original + 1 > max) return Integer.MAX_VALUE else return original + 1 | ||
67 | } | ||
68 | } | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/AbstractNeighborhoodBasedStateCoderFactory.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/AbstractNeighborhoodBasedStateCoderFactory.xtend new file mode 100644 index 00000000..089880b1 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/AbstractNeighborhoodBasedStateCoderFactory.xtend | |||
@@ -0,0 +1,137 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.NeighbourhoodOptions | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | ||
10 | import java.util.LinkedList | ||
11 | import java.util.List | ||
12 | import org.eclipse.emf.common.notify.Notifier | ||
13 | import org.eclipse.emf.ecore.EClass | ||
14 | import org.eclipse.emf.ecore.EObject | ||
15 | import org.eclipse.emf.ecore.EStructuralFeature | ||
16 | import org.eclipse.viatra.dse.statecode.IStateCoder | ||
17 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory | ||
18 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
19 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine | ||
20 | import org.eclipse.viatra.query.runtime.base.api.FeatureListener | ||
21 | import org.eclipse.viatra.query.runtime.base.api.IndexingLevel | ||
22 | import org.eclipse.viatra.query.runtime.base.api.InstanceListener | ||
23 | import org.eclipse.viatra.query.runtime.emf.EMFBaseIndexWrapper | ||
24 | import org.eclipse.viatra.query.runtime.emf.EMFScope | ||
25 | import org.eclipse.xtend.lib.annotations.Accessors | ||
26 | |||
27 | abstract class AbstractNeighbourhoodBasedStateCoderFactory implements IStateCoderFactory { | ||
28 | val List<AbstractNeighbourhoodBasedPartialInterpretationStateCoder> statecoders = new LinkedList | ||
29 | |||
30 | val NeighbourhoodOptions options | ||
31 | |||
32 | protected new() { | ||
33 | this(NeighbourhoodOptions.DEFAULT) | ||
34 | } | ||
35 | |||
36 | protected new(NeighbourhoodOptions options) { | ||
37 | this.options = options | ||
38 | } | ||
39 | |||
40 | synchronized override createStateCoder() { | ||
41 | val res = doCreateStateCoder(options) | ||
42 | statecoders += res | ||
43 | return res | ||
44 | } | ||
45 | |||
46 | protected def AbstractNeighbourhoodBasedPartialInterpretationStateCoder doCreateStateCoder( | ||
47 | NeighbourhoodOptions options) | ||
48 | |||
49 | def getSumStatecoderRuntime() { | ||
50 | statecoders.map[statecoderRuntime].reduce[p1, p2|p1 + p2] | ||
51 | } | ||
52 | } | ||
53 | |||
54 | abstract class AbstractNeighbourhoodBasedPartialInterpretationStateCoder implements IStateCoder { | ||
55 | val NeighbourhoodOptions options | ||
56 | |||
57 | var PartialInterpretation target | ||
58 | |||
59 | protected new(NeighbourhoodOptions options) { | ||
60 | this.options = options | ||
61 | } | ||
62 | |||
63 | @Accessors(PUBLIC_GETTER) var long statecoderRuntime = 0 | ||
64 | |||
65 | synchronized private def refreshStateCodes() { | ||
66 | if (refreshNeeded) { | ||
67 | val startTime = System.nanoTime | ||
68 | doRefreshStateCodes(target, options) | ||
69 | statecoderRuntime += (System.nanoTime - startTime) | ||
70 | } | ||
71 | } | ||
72 | |||
73 | protected def boolean isRefreshNeeded() | ||
74 | |||
75 | protected def void doRefreshStateCodes(PartialInterpretation target, NeighbourhoodOptions options) | ||
76 | |||
77 | synchronized override createActivationCode(IPatternMatch match) { | ||
78 | refreshStateCodes | ||
79 | val startTime = System.nanoTime | ||
80 | val code = doCreateActivationCode(match) | ||
81 | statecoderRuntime += (System.nanoTime - startTime) | ||
82 | code | ||
83 | } | ||
84 | |||
85 | protected def Object doCreateActivationCode(IPatternMatch match) | ||
86 | |||
87 | synchronized override createStateCode() { | ||
88 | refreshStateCodes | ||
89 | doCreateStateCode | ||
90 | } | ||
91 | |||
92 | protected def Object doCreateStateCode() | ||
93 | |||
94 | override init(Notifier notifier) { | ||
95 | this.target = notifier as PartialInterpretation | ||
96 | val queryEngine = ViatraQueryEngine.on(new EMFScope(notifier)) | ||
97 | val baseIndex = queryEngine.getBaseIndex() as EMFBaseIndexWrapper | ||
98 | val navigationHelper = baseIndex.getNavigationHelper(); | ||
99 | |||
100 | val classes = PartialinterpretationPackage.eINSTANCE.EClassifiers.filter(EClass).toSet | ||
101 | val features = classes.map[it.EAllStructuralFeatures].flatten.toSet | ||
102 | navigationHelper.registerObservedTypes(classes, null, features, IndexingLevel.FULL); | ||
103 | |||
104 | navigationHelper.addFeatureListener(features, new FeatureListener() { | ||
105 | override void featureInserted(EObject host, EStructuralFeature feature, Object value) { invalidate } | ||
106 | |||
107 | override void featureDeleted(EObject host, EStructuralFeature feature, Object value) { invalidate } | ||
108 | }) | ||
109 | navigationHelper.addInstanceListener(classes, new InstanceListener() { | ||
110 | override void instanceInserted(EClass clazz, EObject instance) { invalidate } | ||
111 | |||
112 | override void instanceDeleted(EClass clazz, EObject instance) { invalidate } | ||
113 | }) | ||
114 | } | ||
115 | |||
116 | synchronized def invalidate() { | ||
117 | doInvalidate | ||
118 | } | ||
119 | |||
120 | protected def void doInvalidate() | ||
121 | |||
122 | def protected getFallbackCode(Object o) { | ||
123 | switch (o) { | ||
124 | PartialInterpretation, | ||
125 | LogicProblem: | ||
126 | null | ||
127 | PartialRelationInterpretation: | ||
128 | o.interpretationOf.name | ||
129 | PartialPrimitiveInterpretation: | ||
130 | o.class.simpleName.hashCode | ||
131 | PartialComplexTypeInterpretation: | ||
132 | o.interpretationOf.name.hashCode | ||
133 | default: | ||
134 | throw new UnsupportedOperationException('''Unsupported type: «o.class.simpleName»''') | ||
135 | } | ||
136 | } | ||
137 | } | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend index f55a501a..c7b8ee37 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend | |||
@@ -62,13 +62,13 @@ class IdentifierBasedStateCode { | |||
62 | int numberOfNewElement | 62 | int numberOfNewElement |
63 | SortedSet<RelationStatecoder> relationStatecoders | 63 | SortedSet<RelationStatecoder> relationStatecoders |
64 | 64 | ||
65 | private static val comparator = new Comparator<RelationStatecoder>() { | 65 | static val comparator = new Comparator<RelationStatecoder>() { |
66 | override compare(RelationStatecoder o1, RelationStatecoder o2) { | 66 | override compare(RelationStatecoder o1, RelationStatecoder o2) { |
67 | o1.relationName.compareTo(o2.relationName) | 67 | o1.relationName.compareTo(o2.relationName) |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | public new(int numberOfNewElements) { | 71 | new(int numberOfNewElements) { |
72 | this.numberOfNewElement = numberOfNewElements | 72 | this.numberOfNewElement = numberOfNewElements |
73 | this.relationStatecoders = new TreeSet(comparator) | 73 | this.relationStatecoders = new TreeSet(comparator) |
74 | } | 74 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend index a86bcd1f..04c49506 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend | |||
@@ -1,223 +1,109 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder |
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.AbstractNodeDescriptor | 3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement |
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.NeighbourhoodOptions | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2Hash | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice | 6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice |
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2NeighbourhoodRepresentation | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | ||
7 | import java.util.ArrayList | 9 | import java.util.ArrayList |
8 | import java.util.LinkedList | ||
9 | import java.util.List | ||
10 | import java.util.Map | 10 | import java.util.Map |
11 | import org.eclipse.emf.common.notify.Notifier | ||
12 | import org.eclipse.emf.ecore.EClass | ||
13 | import org.eclipse.emf.ecore.EObject | ||
14 | import org.eclipse.emf.ecore.EStructuralFeature | ||
15 | import org.eclipse.viatra.dse.statecode.IStateCoder | ||
16 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory | ||
17 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | 11 | import org.eclipse.viatra.query.runtime.api.IPatternMatch |
18 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine | 12 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification |
19 | import org.eclipse.viatra.query.runtime.base.api.FeatureListener | ||
20 | import org.eclipse.viatra.query.runtime.base.api.IndexingLevel | ||
21 | import org.eclipse.viatra.query.runtime.base.api.InstanceListener | ||
22 | import org.eclipse.viatra.query.runtime.emf.EMFBaseIndexWrapper | ||
23 | import org.eclipse.viatra.query.runtime.emf.EMFScope | ||
24 | import org.eclipse.xtend.lib.annotations.Accessors | ||
25 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
26 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | ||
29 | import java.util.Set | ||
30 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | ||
31 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2NeighbourhoodRepresentation | ||
33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | ||
34 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation | ||
35 | 13 | ||
36 | class NeighbourhoodBasedStateCoderFactory implements IStateCoderFactory { | 14 | class NeighbourhoodBasedStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { |
37 | val List<NeighbourhoodBasedPartialInterpretationStateCoder> statecoders = new LinkedList | 15 | new() { |
38 | |||
39 | val int range | ||
40 | val int parallels | ||
41 | val int maxNumber | ||
42 | val Set<TypeDeclaration> relevantTypes | ||
43 | val Set<RelationDeclaration> relevantRelations | ||
44 | |||
45 | public new() { | ||
46 | this.range = PartialInterpretation2NeighbourhoodRepresentation::GraphWidthRange | ||
47 | this.parallels = PartialInterpretation2NeighbourhoodRepresentation::FullParallels | ||
48 | this.maxNumber = PartialInterpretation2NeighbourhoodRepresentation::MaxNumbers | ||
49 | this.relevantTypes = null | ||
50 | this.relevantRelations = null | ||
51 | } | 16 | } |
52 | 17 | ||
53 | public new(int range, int parallels, int maxNumber, Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations) { | 18 | new(NeighbourhoodOptions options) { |
54 | this.range = range | 19 | super(options) |
55 | this.parallels = parallels | 20 | } |
56 | this.maxNumber = maxNumber | 21 | |
57 | this.relevantTypes = relevantTypes | 22 | override protected doCreateStateCoder(NeighbourhoodOptions options) { |
58 | this.relevantRelations = relevantRelations | 23 | new NeighbourhoodBasedPartialInterpretationStateCoder(new PartialInterpretation2ImmutableTypeLattice, options) |
59 | } | 24 | } |
60 | |||
61 | synchronized override createStateCoder() { | ||
62 | val res = new NeighbourhoodBasedPartialInterpretationStateCoder(statecoders.size, | ||
63 | range,parallels,maxNumber,relevantTypes,relevantRelations) | ||
64 | statecoders += res | ||
65 | return res | ||
66 | } | ||
67 | def getSumStatecoderRuntime() { | ||
68 | statecoders.map[statecoderRuntime].reduce[p1, p2|p1+p2] | ||
69 | } | ||
70 | } | 25 | } |
71 | 26 | ||
72 | class NeighbourhoodBasedPartialInterpretationStateCoder implements IStateCoder{ | 27 | class NeighbourhoodBasedHashStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { |
73 | val int id; | 28 | new() { |
74 | val int range | 29 | } |
75 | val int parallels | 30 | |
76 | val int maxNumber | 31 | new(NeighbourhoodOptions options) { |
77 | val Set<TypeDeclaration> relevantTypes | 32 | super(options) |
78 | val Set<RelationDeclaration> relevantRelations | 33 | } |
79 | 34 | ||
80 | val calculator = | 35 | override protected doCreateStateCoder(NeighbourhoodOptions options) { |
81 | new PartialInterpretation2ImmutableTypeLattice | 36 | new NeighbourhoodBasedPartialInterpretationStateCoder(new PartialInterpretation2Hash, options) |
82 | var PartialInterpretation target | 37 | } |
83 | 38 | } | |
84 | private var Map<DefinedElement, ? extends AbstractNodeDescriptor> nodeRepresentations = null | 39 | |
85 | private var Map<? extends AbstractNodeDescriptor, Integer> modelRepresentation = null | 40 | class NeighbourhoodBasedPartialInterpretationStateCoder<ModelRep, NodeRep> extends AbstractNeighbourhoodBasedPartialInterpretationStateCoder { |
86 | 41 | val PartialInterpretation2NeighbourhoodRepresentation<ModelRep, NodeRep> calculator | |
87 | /*public new(int id) { | 42 | val Map<IQuerySpecification<?>, String> fullyQualifiedNames = newHashMap |
88 | this.id = id | 43 | var Map<DefinedElement, ? extends NodeRep> nodeRepresentations = null |
89 | this.range = PartialInterpretation2NeighbourhoodRepresentation::FixPointRage | 44 | var ModelRep modelRepresentation = null |
90 | this.parallels = PartialInterpretation2NeighbourhoodRepresentation::FullParallels | 45 | |
91 | this.maxNumber = maxNumber = PartialInterpretation2NeighbourhoodRepresentation::MaxNumbers | 46 | new(PartialInterpretation2NeighbourhoodRepresentation<ModelRep, NodeRep> calculator, NeighbourhoodOptions options) { |
92 | this.relevantTypes = relevantTypes | 47 | super(options) |
93 | this.relevantRelations = relevantRelations | 48 | this.calculator = calculator |
94 | }*/ | 49 | } |
50 | |||
51 | override protected isRefreshNeeded() { | ||
52 | nodeRepresentations === null || modelRepresentation === null | ||
53 | } | ||
54 | |||
55 | override doRefreshStateCodes(PartialInterpretation target, NeighbourhoodOptions options) { | ||
56 | val code = calculator.createRepresentation(target, options) | ||
57 | modelRepresentation = code.modelRepresentation | ||
58 | nodeRepresentations = code.nodeRepresentations | ||
59 | } | ||
95 | 60 | ||
96 | public new(int id, int range, int parallels, int maxNumber, Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations) { | 61 | private def getFullyQualifiedNameCached(IQuerySpecification<?> specification) { |
97 | this.id = id | 62 | fullyQualifiedNames.computeIfAbsent(specification, [fullyQualifiedName]) |
98 | this.range = range | ||
99 | this.parallels = parallels | ||
100 | this.maxNumber = maxNumber | ||
101 | this.relevantTypes = relevantTypes | ||
102 | this.relevantRelations = relevantRelations | ||
103 | } | 63 | } |
104 | 64 | ||
105 | @Accessors(PUBLIC_GETTER) var long statecoderRuntime = 0 | 65 | override doCreateActivationCode(IPatternMatch match) { |
106 | 66 | val size = match.specification.parameters.size | |
107 | // val range = -1 | 67 | var int hash = 0 |
108 | // val par = Integer.MAX_VALUE | 68 | val prime = 31 |
109 | //val deeprepresentation = false | 69 | |
110 | 70 | for (var int index = 0; index < size; index++) { | |
111 | ///////// | 71 | val matchArgument = match.get(index) |
112 | // Caching version | 72 | val code = getCode(matchArgument) |
113 | ///////// | 73 | val codeNumber = if (code === null) { |
114 | synchronized private def refreshStateCodes() { | 74 | 0 |
115 | if(this.nodeRepresentations === null || this.modelRepresentation === null) { | ||
116 | val startTime = System.nanoTime | ||
117 | //relevantObjects.forEach[println(it)] | ||
118 | val code = calculator.createRepresentation(target,range,parallels,maxNumber,relevantTypes,relevantRelations) | ||
119 | this.modelRepresentation = code.modelRepresentation | ||
120 | this.nodeRepresentations = code.nodeRepresentations | ||
121 | statecoderRuntime += (System.nanoTime - startTime) | ||
122 | } | ||
123 | } | ||
124 | synchronized override createActivationCode(IPatternMatch match) { | ||
125 | refreshStateCodes | ||
126 | |||
127 | val startTime = System.nanoTime | ||
128 | val size = match.specification.parameters.size | ||
129 | val res = new ArrayList(size) | ||
130 | var int index = 0 | ||
131 | var int equivalenceHash = 0 | ||
132 | val prime = 31 | ||
133 | |||
134 | while(index < size) { | ||
135 | res.add(getCode(match.get(index))) | ||
136 | index++ | ||
137 | for(var i = 0; i<index; i++) { | ||
138 | val number = if(match.get(index) === match.get(i)){1}else{0} | ||
139 | equivalenceHash = prime * equivalenceHash + number | ||
140 | } | ||
141 | } | ||
142 | |||
143 | statecoderRuntime += (System.nanoTime - startTime) | ||
144 | return match.specification.fullyQualifiedName->(res->equivalenceHash).hashCode | ||
145 | } | ||
146 | |||
147 | |||
148 | def private getCode(Object o) { | ||
149 | if(o instanceof DefinedElement) { | ||
150 | this.nodeRepresentations.get(o) | ||
151 | } else if(o instanceof PartialInterpretation || o instanceof LogicProblem) { | ||
152 | return null | ||
153 | } else if(o instanceof PartialRelationInterpretation) { | ||
154 | return o.interpretationOf.name | ||
155 | } else if(o instanceof PartialTypeInterpratation) { | ||
156 | if(o instanceof PartialPrimitiveInterpretation) { | ||
157 | o.class.simpleName.hashCode | ||
158 | } else if (o instanceof PartialComplexTypeInterpretation){ | ||
159 | return o.interpretationOf.name.hashCode | ||
160 | } else { | 75 | } else { |
161 | throw new UnsupportedOperationException('''Unsupported type: «o.class.simpleName»''') | 76 | code.hashCode |
77 | } | ||
78 | hash = prime * hash + codeNumber | ||
79 | for (var i = 0; i < index; i++) { | ||
80 | val number = if (matchArgument === match.get(i)) { | ||
81 | 1 | ||
82 | } else { | ||
83 | 0 | ||
84 | } | ||
85 | hash = prime * hash + number | ||
162 | } | 86 | } |
163 | } else { | ||
164 | throw new UnsupportedOperationException('''Unsupported type: «o.class.simpleName»''') | ||
165 | } | 87 | } |
166 | } | 88 | |
167 | 89 | match.specification.fullyQualifiedNameCached -> hash | |
168 | synchronized override createStateCode() { | 90 | } |
169 | refreshStateCodes | 91 | |
170 | return this.modelRepresentation.hashCode | 92 | def private getCode(Object o) { |
171 | } | 93 | switch (o) { |
172 | ///////// | 94 | DefinedElement: |
173 | // Caching version | 95 | nodeRepresentations.get(o) |
174 | ///////// | 96 | default: |
175 | 97 | getFallbackCode(o) | |
176 | ///////// | 98 | } |
177 | // Recalculating version | 99 | } |
178 | ///////// | 100 | |
179 | // synchronized override createActivationCode(IPatternMatch match) { | 101 | override doCreateStateCode() { |
180 | // val nodes = calculator.createRepresentation(getRelevantObjects().toList,range,par).nodeRepresentations | 102 | modelRepresentation.hashCode |
181 | // val res = match.toArray.map[objectInMatch | | 103 | } |
182 | // nodes.get(objectInMatch) | 104 | |
183 | // ] | 105 | override doInvalidate() { |
184 | // return res | 106 | nodeRepresentations = null |
185 | // } | 107 | modelRepresentation = null |
186 | // | ||
187 | // override createStateCode() { | ||
188 | // return this.calculator.createRepresentation(getRelevantObjects().toList,range,par).modelRepresentation | ||
189 | // } | ||
190 | ///////// | ||
191 | // Recalculating version | ||
192 | ///////// | ||
193 | |||
194 | override init(Notifier notifier) { | ||
195 | this.target = notifier as PartialInterpretation | ||
196 | val queryEngine = ViatraQueryEngine.on(new EMFScope(notifier)) | ||
197 | val baseIndex = queryEngine.getBaseIndex() as EMFBaseIndexWrapper | ||
198 | val navigationHelper = baseIndex.getNavigationHelper(); | ||
199 | |||
200 | val classes = PartialinterpretationPackage.eINSTANCE.EClassifiers.filter(EClass).toSet | ||
201 | val features = classes.map[it.EAllStructuralFeatures].flatten.toSet | ||
202 | navigationHelper.registerObservedTypes( | ||
203 | classes, | ||
204 | null, | ||
205 | features, | ||
206 | IndexingLevel.FULL); | ||
207 | |||
208 | |||
209 | navigationHelper.addFeatureListener(features, new FeatureListener() { | ||
210 | override public void featureInserted(EObject host, EStructuralFeature feature, Object value) { invalidate } | ||
211 | override public void featureDeleted(EObject host, EStructuralFeature feature, Object value) { invalidate } | ||
212 | }); | ||
213 | navigationHelper.addInstanceListener(classes, new InstanceListener() { | ||
214 | override public void instanceInserted(EClass clazz, EObject instance) { invalidate } | ||
215 | override public void instanceDeleted(EClass clazz, EObject instance) { invalidate } | ||
216 | }); | ||
217 | } | ||
218 | |||
219 | synchronized def public invalidate() { | ||
220 | this.nodeRepresentations = null | ||
221 | this.modelRepresentation = null | ||
222 | } | 108 | } |
223 | } | 109 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/PairwiseNeighbourhoodBasedStateCoderFactory.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/PairwiseNeighbourhoodBasedStateCoderFactory.xtend new file mode 100644 index 00000000..84e798f2 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/PairwiseNeighbourhoodBasedStateCoderFactory.xtend | |||
@@ -0,0 +1,75 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.AbstractNodeDescriptor | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.NeighbourhoodOptions | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PairwiseNeighbourhoodRepresentation | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2PairwiseNeighbourhoodRepresentation | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
10 | import java.util.ArrayList | ||
11 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
12 | |||
13 | class PairwiseNeighbourhoodBasedStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { | ||
14 | new() { | ||
15 | } | ||
16 | |||
17 | new(NeighbourhoodOptions options) { | ||
18 | super(options) | ||
19 | } | ||
20 | |||
21 | override protected doCreateStateCoder(NeighbourhoodOptions options) { | ||
22 | new PairwiseNeighbourhoodBasedPartialInterpretationStateCoder(options) | ||
23 | } | ||
24 | } | ||
25 | |||
26 | class PairwiseNeighbourhoodBasedPartialInterpretationStateCoder extends AbstractNeighbourhoodBasedPartialInterpretationStateCoder { | ||
27 | val calculator = new PartialInterpretation2PairwiseNeighbourhoodRepresentation( | ||
28 | new PartialInterpretation2ImmutableTypeLattice) | ||
29 | var PairwiseNeighbourhoodRepresentation<? extends AbstractNodeDescriptor> representation | ||
30 | |||
31 | new(NeighbourhoodOptions options) { | ||
32 | super(options) | ||
33 | } | ||
34 | |||
35 | override protected isRefreshNeeded() { | ||
36 | representation === null | ||
37 | } | ||
38 | |||
39 | override protected doRefreshStateCodes(PartialInterpretation target, NeighbourhoodOptions options) { | ||
40 | representation = calculator.createRepresentation(target, options) | ||
41 | } | ||
42 | |||
43 | override protected doCreateActivationCode(IPatternMatch match) { | ||
44 | val size = match.specification.parameters.size | ||
45 | val res = new ArrayList(size * size) | ||
46 | for (var int i = 0; i < size; i++) { | ||
47 | val a = match.get(i) | ||
48 | for (var int j = 0; j < size; j++) { | ||
49 | val b = match.get(j) | ||
50 | res.add(getPairwiseRepresentation(a, b)) | ||
51 | } | ||
52 | } | ||
53 | match.specification.fullyQualifiedName -> res.hashCode | ||
54 | } | ||
55 | |||
56 | private def getPairwiseRepresentation(Object a, Object b) { | ||
57 | if (b instanceof DefinedElement) { | ||
58 | if (a instanceof DefinedElement) { | ||
59 | representation.getPairwiseRepresentation(a, b) | ||
60 | } else { | ||
61 | representation.getBasicRepresentation(b) | ||
62 | } | ||
63 | } else { | ||
64 | getFallbackCode(b) | ||
65 | } | ||
66 | } | ||
67 | |||
68 | override protected doCreateStateCode() { | ||
69 | representation.modelRepresentation.hashCode | ||
70 | } | ||
71 | |||
72 | override protected doInvalidate() { | ||
73 | representation = null | ||
74 | } | ||
75 | } | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend index 2b42a8b1..bdf402f3 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/visualisation/PartialInterpretation2Gml.xtend | |||
@@ -5,9 +5,13 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation | |||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | 6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition |
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | 7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink |
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | 10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation |
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | 12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation |
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement | ||
11 | import java.util.HashMap | 15 | import java.util.HashMap |
12 | import java.util.Map | 16 | import java.util.Map |
13 | import java.util.Set | 17 | import java.util.Set |
@@ -106,10 +110,38 @@ class PartialInterpretation2Gml { | |||
106 | ''' | 110 | ''' |
107 | } | 111 | } |
108 | 112 | ||
109 | def protected transormTitle(DefinedElement object) { | 113 | def protected dispatch transormTitle(DefinedElement object) { |
110 | if(object.name!= null)object.name | 114 | if(object.name !== null) object.name.replace("\"", "") |
111 | else "null" | 115 | else "null" |
112 | } | 116 | } |
117 | def protected dispatch transormTitle(BooleanElement object) { | ||
118 | if(object.valueSet) { | ||
119 | object.value.toString | ||
120 | } else { | ||
121 | "?" | ||
122 | } | ||
123 | } | ||
124 | def protected dispatch transormTitle(IntegerElement object) { | ||
125 | if(object.valueSet) { | ||
126 | object.value.toString | ||
127 | } else { | ||
128 | "?" | ||
129 | } | ||
130 | } | ||
131 | def protected dispatch transormTitle(RealElement object) { | ||
132 | if(object.valueSet) { | ||
133 | object.value.toString | ||
134 | } else { | ||
135 | "?" | ||
136 | } | ||
137 | } | ||
138 | def protected dispatch transormTitle(StringElement object) { | ||
139 | if(object.valueSet) { | ||
140 | object.value.toString | ||
141 | } else { | ||
142 | "?" | ||
143 | } | ||
144 | } | ||
113 | 145 | ||
114 | def protected transformLink( | 146 | def protected transformLink( |
115 | PartialRelationInterpretation reference, | 147 | PartialRelationInterpretation reference, |