diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2019-08-01 14:45:26 +0200 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2019-08-01 14:45:26 +0200 |
commit | c300e9e7918aa71b04cb681c558eb282dd1fb390 (patch) | |
tree | 3424e832659e3a98187fd7a870e4a7f8eebc65ff /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/TypeHierarchyScopePropagator.xtend | |
parent | Configurability and better statistics for measurements (diff) | |
download | VIATRA-Generator-c300e9e7918aa71b04cb681c558eb282dd1fb390.tar.gz VIATRA-Generator-c300e9e7918aa71b04cb681c558eb282dd1fb390.tar.zst VIATRA-Generator-c300e9e7918aa71b04cb681c558eb282dd1fb390.zip |
Counting scope propagator (simpler than BasicTypeHierarchy)
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/TypeHierarchyScopePropagator.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/TypeHierarchyScopePropagator.xtend | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/TypeHierarchyScopePropagator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/TypeHierarchyScopePropagator.xtend new file mode 100644 index 00000000..be8ef00a --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/cardinality/TypeHierarchyScopePropagator.xtend | |||
@@ -0,0 +1,77 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationStatistics | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.Scope | ||
6 | |||
7 | class TypeHierarchyScopePropagator extends ScopePropagator { | ||
8 | |||
9 | new(PartialInterpretation p, ModelGenerationStatistics statistics) { | ||
10 | super(p, statistics) | ||
11 | } | ||
12 | |||
13 | protected override doPropagateAllScopeConstraints() { | ||
14 | var boolean hadChanged | ||
15 | do { | ||
16 | hadChanged = false | ||
17 | for (superScopeEntry : superScopes.entrySet) { | ||
18 | val sub = superScopeEntry.key | ||
19 | hadChanged = propagateLowerLimitUp(sub, partialInterpretation) || hadChanged | ||
20 | hadChanged = propagateUpperLimitDown(sub, partialInterpretation) || hadChanged | ||
21 | for (sup : superScopeEntry.value) { | ||
22 | hadChanged = propagateLowerLimitUp(sub, sup) || hadChanged | ||
23 | hadChanged = propagateUpperLimitDown(sub, sup) || hadChanged | ||
24 | } | ||
25 | } | ||
26 | } while (hadChanged) | ||
27 | } | ||
28 | |||
29 | private def propagateLowerLimitUp(Scope subScope, Scope superScope) { | ||
30 | if (subScope.minNewElements > superScope.minNewElements) { | ||
31 | superScope.minNewElements = subScope.minNewElements | ||
32 | return true | ||
33 | } else { | ||
34 | return false | ||
35 | } | ||
36 | } | ||
37 | |||
38 | private def propagateUpperLimitDown(Scope subScope, Scope superScope) { | ||
39 | if (superScope.maxNewElements >= 0 && | ||
40 | (superScope.maxNewElements < subScope.maxNewElements || subScope.maxNewElements < 0)) { | ||
41 | // println(''' | ||
42 | // «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> «(superScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» | ||
43 | // subScope.maxNewElements «subScope.maxNewElements» = superScope.maxNewElements «superScope.maxNewElements» | ||
44 | // ''') | ||
45 | subScope.maxNewElements = superScope.maxNewElements | ||
46 | return true | ||
47 | } else { | ||
48 | return false | ||
49 | } | ||
50 | } | ||
51 | |||
52 | private def propagateLowerLimitUp(Scope subScope, PartialInterpretation p) { | ||
53 | if (subScope.minNewElements > p.minNewElements) { | ||
54 | // println(''' | ||
55 | // «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> nodes | ||
56 | // p.minNewElements «p.minNewElements» = subScope.minNewElements «subScope.minNewElements» | ||
57 | // ''') | ||
58 | p.minNewElements = subScope.minNewElements | ||
59 | return true | ||
60 | } else { | ||
61 | return false | ||
62 | } | ||
63 | } | ||
64 | |||
65 | private def propagateUpperLimitDown(Scope subScope, PartialInterpretation p) { | ||
66 | if (p.maxNewElements >= 0 && (p.maxNewElements < subScope.maxNewElements || subScope.maxNewElements < 0)) { | ||
67 | // println(''' | ||
68 | // «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> nodes | ||
69 | // subScope.maxNewElements «subScope.maxNewElements» = p.maxNewElements «p.maxNewElements» | ||
70 | // ''') | ||
71 | subScope.maxNewElements = p.maxNewElements | ||
72 | return true | ||
73 | } else { | ||
74 | return false | ||
75 | } | ||
76 | } | ||
77 | } | ||