aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/AbstractNeighborhoodBasedStateCoderFactory.xtend
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kris7topher@gmail.com>2019-06-15 20:56:47 -0400
committerLibravatar Kristóf Marussy <kris7topher@gmail.com>2019-06-15 20:56:47 -0400
commitc0c5a1644cc221352b8b9b370eea6a87677ba948 (patch)
tree4b1412577c568440b7098dc31691438ebc8e7e9d /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/AbstractNeighborhoodBasedStateCoderFactory.xtend
parentBump MDEOptimizer version (diff)
downloadVIATRA-Generator-c0c5a1644cc221352b8b9b370eea6a87677ba948.tar.gz
VIATRA-Generator-c0c5a1644cc221352b8b9b370eea6a87677ba948.tar.zst
VIATRA-Generator-c0c5a1644cc221352b8b9b370eea6a87677ba948.zip
Try fix statecode bug
Modified graph width calculation to not depend on order of nodes
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/AbstractNeighborhoodBasedStateCoderFactory.xtend')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/AbstractNeighborhoodBasedStateCoderFactory.xtend137
1 files changed, 137 insertions, 0 deletions
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 @@
1package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder
2
3import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
4import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.NeighbourhoodOptions
5import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation
6import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation
7import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation
8import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation
9import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage
10import java.util.LinkedList
11import java.util.List
12import org.eclipse.emf.common.notify.Notifier
13import org.eclipse.emf.ecore.EClass
14import org.eclipse.emf.ecore.EObject
15import org.eclipse.emf.ecore.EStructuralFeature
16import org.eclipse.viatra.dse.statecode.IStateCoder
17import org.eclipse.viatra.dse.statecode.IStateCoderFactory
18import org.eclipse.viatra.query.runtime.api.IPatternMatch
19import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
20import org.eclipse.viatra.query.runtime.base.api.FeatureListener
21import org.eclipse.viatra.query.runtime.base.api.IndexingLevel
22import org.eclipse.viatra.query.runtime.base.api.InstanceListener
23import org.eclipse.viatra.query.runtime.emf.EMFBaseIndexWrapper
24import org.eclipse.viatra.query.runtime.emf.EMFScope
25import org.eclipse.xtend.lib.annotations.Accessors
26
27abstract 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
54abstract 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}