diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ScopePropagator.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ScopePropagator.xtend | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ScopePropagator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ScopePropagator.xtend deleted file mode 100644 index 8012776f..00000000 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/ScopePropagator.xtend +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.Scope | ||
6 | import java.util.HashMap | ||
7 | import java.util.Map | ||
8 | import java.util.Set | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | ||
10 | import java.util.HashSet | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation | ||
12 | |||
13 | class ScopePropagator { | ||
14 | PartialInterpretation partialInterpretation | ||
15 | Map<PartialTypeInterpratation,Scope> type2Scope | ||
16 | |||
17 | val Map<Scope, Set<Scope>> superScopes | ||
18 | val Map<Scope, Set<Scope>> subScopes | ||
19 | |||
20 | public new(PartialInterpretation p) { | ||
21 | partialInterpretation = p | ||
22 | type2Scope = new HashMap | ||
23 | for(scope : p.scopes) { | ||
24 | type2Scope.put(scope.targetTypeInterpretation,scope) | ||
25 | } | ||
26 | |||
27 | superScopes = new HashMap | ||
28 | subScopes = new HashMap | ||
29 | for(scope : p.scopes) { | ||
30 | superScopes.put(scope,new HashSet) | ||
31 | subScopes.put(scope,new HashSet) | ||
32 | } | ||
33 | |||
34 | for(scope : p.scopes) { | ||
35 | val target = scope.targetTypeInterpretation | ||
36 | if(target instanceof PartialComplexTypeInterpretation) { | ||
37 | val supertypeInterpretations = target.supertypeInterpretation | ||
38 | for(supertypeInterpretation : supertypeInterpretations) { | ||
39 | val supertypeScope = type2Scope.get(supertypeInterpretation) | ||
40 | superScopes.get(scope).add(supertypeScope) | ||
41 | subScopes.get(supertypeScope).add(scope) | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | |||
47 | def public propagateAllScopeConstraints() { | ||
48 | var boolean hadChanged | ||
49 | do{ | ||
50 | hadChanged = false | ||
51 | for(superScopeEntry : superScopes.entrySet) { | ||
52 | val sub = superScopeEntry.key | ||
53 | hadChanged = propagateLowerLimitUp(sub,partialInterpretation) || hadChanged | ||
54 | hadChanged = propagateUpperLimitDown(sub,partialInterpretation) || hadChanged | ||
55 | for(sup: superScopeEntry.value) { | ||
56 | hadChanged = propagateLowerLimitUp(sub,sup) || hadChanged | ||
57 | hadChanged = propagateUpperLimitDown(sub,sup) || hadChanged | ||
58 | } | ||
59 | } | ||
60 | } while(hadChanged) | ||
61 | // println('''All constraints are propagated.''') | ||
62 | } | ||
63 | |||
64 | def public propagateAdditionToType(PartialTypeInterpratation t) { | ||
65 | val isPrimitive = t instanceof PartialPrimitiveInterpretation || t === null | ||
66 | if(!isPrimitive) { | ||
67 | // println('''Adding to «(t as PartialComplexTypeInterpretation).interpretationOf.name»''') | ||
68 | val targetScope = type2Scope.get(t) | ||
69 | if(targetScope!==null) { | ||
70 | targetScope.removeOne | ||
71 | val sups = superScopes.get(targetScope) | ||
72 | sups.forEach[removeOne] | ||
73 | } | ||
74 | |||
75 | |||
76 | if(this.partialInterpretation.minNewElements > 0 ) { | ||
77 | this.partialInterpretation.minNewElements = this.partialInterpretation.minNewElements-1 | ||
78 | } | ||
79 | if(this.partialInterpretation.maxNewElements > 0) { | ||
80 | this.partialInterpretation.maxNewElements = this.partialInterpretation.maxNewElements-1 | ||
81 | } else if(this.partialInterpretation.maxNewElements === 0) { | ||
82 | this.partialInterpretation.maxNewElements = 0 | ||
83 | //throw new IllegalArgumentException('''Inconsistent object creation: lower node limit is 0!''') | ||
84 | } | ||
85 | |||
86 | // subScopes.get(targetScope).forEach[propagateUpperLimitDown(it,targetScope)] | ||
87 | // for(sup: sups) { | ||
88 | // subScopes.get(sup).forEach[propagateUpperLimitDown(it,sup)] | ||
89 | // } | ||
90 | // for(scope : type2Scope.values) { | ||
91 | // propagateUpperLimitDown(scope,partialInterpretation) | ||
92 | // } | ||
93 | |||
94 | propagateAllScopeConstraints | ||
95 | |||
96 | // println('''Target Scope: «targetScope.minNewElements» - «targetScope.maxNewElements»''') | ||
97 | // println(''' «this.partialInterpretation.minNewElements» - «this.partialInterpretation.maxNewElements»''') | ||
98 | // this.partialInterpretation.scopes.forEach[println(''' «(it.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name»: «it.minNewElements»-«it.maxNewElements»''')] | ||
99 | // println('''All constraints are propagated upon increasing «(t as PartialComplexTypeInterpretation).interpretationOf.name»''') | ||
100 | } | ||
101 | } | ||
102 | |||
103 | private def propagateLowerLimitUp(Scope subScope, Scope superScope) { | ||
104 | if(subScope.minNewElements>superScope.minNewElements) { | ||
105 | // println(''' | ||
106 | // «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> «(superScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» | ||
107 | // superScope.minNewElements «superScope.minNewElements» = subScope.minNewElements «subScope.minNewElements» | ||
108 | // ''') | ||
109 | superScope.minNewElements = subScope.minNewElements | ||
110 | return true | ||
111 | } else { | ||
112 | return false | ||
113 | } | ||
114 | } | ||
115 | |||
116 | private def propagateUpperLimitDown(Scope subScope, Scope superScope) { | ||
117 | if(superScope.maxNewElements>=0 && (superScope.maxNewElements<subScope.maxNewElements || subScope.maxNewElements<0)) { | ||
118 | // println(''' | ||
119 | // «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> «(superScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» | ||
120 | // subScope.maxNewElements «subScope.maxNewElements» = superScope.maxNewElements «superScope.maxNewElements» | ||
121 | // ''') | ||
122 | subScope.maxNewElements = superScope.maxNewElements | ||
123 | return true | ||
124 | } else { | ||
125 | return false | ||
126 | } | ||
127 | } | ||
128 | |||
129 | private def propagateLowerLimitUp(Scope subScope, PartialInterpretation p) { | ||
130 | if(subScope.minNewElements>p.minNewElements) { | ||
131 | // println(''' | ||
132 | // «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> nodes | ||
133 | // p.minNewElements «p.minNewElements» = subScope.minNewElements «subScope.minNewElements» | ||
134 | // ''') | ||
135 | p.minNewElements = subScope.minNewElements | ||
136 | return true | ||
137 | } else { | ||
138 | return false | ||
139 | } | ||
140 | } | ||
141 | |||
142 | private def propagateUpperLimitDown(Scope subScope, PartialInterpretation p) { | ||
143 | if(p.maxNewElements>=0 && (p.maxNewElements<subScope.maxNewElements || subScope.maxNewElements<0)) { | ||
144 | // println(''' | ||
145 | // «(subScope.targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf.name» -> nodes | ||
146 | // subScope.maxNewElements «subScope.maxNewElements» = p.maxNewElements «p.maxNewElements» | ||
147 | // ''') | ||
148 | subScope.maxNewElements = p.maxNewElements | ||
149 | return true | ||
150 | } else { | ||
151 | return false | ||
152 | } | ||
153 | } | ||
154 | private def removeOne(Scope scope) { | ||
155 | if(scope.maxNewElements===0) { | ||
156 | scope.maxNewElements=0 | ||
157 | //throw new IllegalArgumentException('''Inconsistent object creation: «scope.targetTypeInterpretation»''') | ||
158 | } else if(scope.maxNewElements>0) { | ||
159 | scope.maxNewElements= scope.maxNewElements-1 | ||
160 | } | ||
161 | if(scope.minNewElements>0) { | ||
162 | scope.minNewElements= scope.minNewElements-1 | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | \ No newline at end of file | ||