diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2NeighbourhoodRepresentation.xtend')
1 files changed, 222 insertions, 199 deletions
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 d1bf0348..a0382e8e 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 |
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation | ||
10 | import java.util.ArrayList | ||
8 | import java.util.HashMap | 11 | import java.util.HashMap |
9 | import java.util.HashSet | 12 | import java.util.HashSet |
10 | import java.util.LinkedList | ||
11 | import java.util.List | 13 | import java.util.List |
12 | import java.util.Map | 14 | import java.util.Map |
13 | import java.util.Set | 15 | import java.util.Set |
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 FixPointRage = NeighbourhoodOptions.FixPointRage |
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,45 +55,50 @@ 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 | |
63 | def createRepresentationWithFocus(PartialInterpretation model, NeighbourhoodOptions options, | ||
64 | DefinedElement focusedElement) { | ||
65 | createRepresentationWithFocus(model, options.range, options.parallels, options.maxNumber, options.relevantTypes, | ||
66 | options.relevantRelations, focusedElement) | ||
67 | } | ||
68 | |||
69 | def createRepresentationWithFocus(PartialInterpretation model, int range, int parallels, int maxNumber, | ||
70 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations, DefinedElement focusedElement) { | ||
56 | val Map<DefinedElement, Set<String>> types = new HashMap | 71 | val Map<DefinedElement, Set<String>> types = new HashMap |
57 | fillTypes(model,types,relevantTypes) | 72 | fillTypes(model, types, relevantTypes) |
58 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = new HashMap; | 73 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = new HashMap; |
59 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = new HashMap; | 74 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = new HashMap; |
60 | fillReferences(model,IncomingRelations,OutgoingRelations,relevantRelations) | 75 | fillReferences(model, IncomingRelations, OutgoingRelations, relevantRelations) |
61 | 76 | ||
62 | val res = doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,range,parallels,maxNumber); | 77 | val res = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, range, parallels, |
63 | 78 | maxNumber, focusedElement); | |
79 | |||
64 | return res; | 80 | return res; |
65 | } | 81 | } |
66 | 82 | ||
67 | def private isRelevant(TypeDeclaration t, Set<TypeDeclaration> relevantTypes) { | 83 | def private isRelevant(TypeDeclaration t, Set<TypeDeclaration> relevantTypes) { |
68 | if(relevantTypes === null) { | 84 | if (relevantTypes === null) { |
69 | return true | 85 | return true |
70 | } else { | 86 | } else { |
71 | return relevantTypes.contains(t) | 87 | return relevantTypes.contains(t) |
72 | } | 88 | } |
73 | } | 89 | } |
90 | |||
74 | def private isRelevant(RelationDeclaration r, Set<RelationDeclaration> relevantRelations) { | 91 | def private isRelevant(RelationDeclaration r, Set<RelationDeclaration> relevantRelations) { |
75 | if(relevantRelations === null) { | 92 | if (relevantRelations === null) { |
76 | return true | 93 | return true |
77 | } else { | 94 | } else { |
78 | return relevantRelations.contains(r) | 95 | return relevantRelations.contains(r) |
79 | } | 96 | } |
80 | } | 97 | } |
81 | /** | ||
82 | * Gets the largest | ||
83 | */ | ||
84 | /** | ||
85 | 98 | ||
99 | /** | ||
86 | * Gets the minimal neighbourhood size such that every reachable node appears in the shape of every other at least once. | 100 | * Gets the minimal neighbourhood size such that every reachable node appears in the shape of every other at least once. |
87 | |||
88 | */ | 101 | */ |
89 | |||
90 | def private getWidth(Map<DefinedElement, Set<String>> types, | 102 | def private getWidth(Map<DefinedElement, Set<String>> types, |
91 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 103 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
92 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) { | 104 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) { |
@@ -99,6 +111,7 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
99 | reachable.put(element, new HashSet) | 111 | reachable.put(element, new HashSet) |
100 | newReachable.put(element, set) | 112 | newReachable.put(element, set) |
101 | } | 113 | } |
114 | |||
102 | var int width = 0 | 115 | var int width = 0 |
103 | var boolean newAdded | 116 | var boolean newAdded |
104 | do { | 117 | do { |
@@ -122,7 +135,6 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
122 | } while (newAdded) | 135 | } while (newAdded) |
123 | return width | 136 | return width |
124 | } | 137 | } |
125 | |||
126 | /** | 138 | /** |
127 | * Creates a neighbourhood representation with traces | 139 | * Creates a neighbourhood representation with traces |
128 | * @param model The model to be represented. | 140 | * @param model The model to be represented. |
@@ -131,68 +143,71 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
131 | * @param range The range of the neighbourhood. | 143 | * @param range The range of the neighbourhood. |
132 | * @param parallels The maximal number of parallel references to be differentiated. | 144 | * @param parallels The maximal number of parallel references to be differentiated. |
133 | */ | 145 | */ |
134 | def private NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> doRecursiveNeighbourCalculation( | 146 | def private NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> doRecursiveNeighbourCalculation( |
135 | PartialInterpretation model, | 147 | PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
136 | Map<DefinedElement, Set<String>> types, | ||
137 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 148 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
138 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 149 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int range, int parallels, |
139 | int range, int parallels, int maxNumber) | 150 | int maxNumber, DefinedElement focusedElement) { |
140 | { | 151 | if (range == 0) { |
141 | if(range == 0){ | 152 | val r = calculateLocalNodeDescriptors(model, types, maxNumber, focusedElement) |
142 | val r = calculateLocalNodeDescriptors(model,types,maxNumber) | 153 | val res = this.createLocalRepresentation(r.value, r.key) |
143 | val res = this.createLocalRepresentation(r.value,r.key) | 154 | if (res.modelRepresentation === null) { |
144 | if(res.modelRepresentation === null) { | ||
145 | throw new IllegalArgumentException('''Model representation is null''') | 155 | throw new IllegalArgumentException('''Model representation is null''') |
146 | } else if(res.nodeRepresentations === null || res.nodeRepresentations.empty) { | 156 | } else if (res.nodeRepresentations === null || res.nodeRepresentations.empty) { |
147 | throw new IllegalArgumentException('''No node representation''') | 157 | throw new IllegalArgumentException('''No node representation''') |
148 | } else if(res.previousRepresentation !== null) { | 158 | } else if (res.previousRepresentation !== null) { |
149 | throw new IllegalArgumentException('''The previous representation of the first neighbourhood have to be null''') | 159 | throw new IllegalArgumentException('''The previous representation of the first neighbourhood have to be null''') |
150 | } else return res | 160 | } else |
151 | } else if(range > 0) { | 161 | return res |
152 | val previous = doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,range-1,parallels,maxNumber) | 162 | } else if (range > 0) { |
153 | val r = calculateFurtherNodeDescriptors(model,previous,IncomingRelations,OutgoingRelations,parallels,maxNumber) | 163 | val previous = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, |
154 | //println('''Level «range» finished.''') | 164 | range - 1, parallels, maxNumber, focusedElement) |
155 | val res = createFurtherRepresentation(r.key,r.value,previous,deepRepresentation) | 165 | val r = calculateFurtherNodeDescriptors(model, previous, IncomingRelations, OutgoingRelations, parallels, |
156 | if(res.modelRepresentation === null) { | 166 | maxNumber) |
167 | // println('''Level «range» finished.''') | ||
168 | val res = createFurtherRepresentation(r.key, r.value, previous, deepRepresentation) | ||
169 | if (res.modelRepresentation === null) { | ||
157 | throw new IllegalArgumentException('''Model representation is null''') | 170 | throw new IllegalArgumentException('''Model representation is null''') |
158 | } else if(res.nodeRepresentations === null || res.nodeRepresentations.empty) { | 171 | } else if (res.nodeRepresentations === null || res.nodeRepresentations.empty) { |
159 | throw new IllegalArgumentException('''No node representation''') | 172 | throw new IllegalArgumentException('''No node representation''') |
160 | } else if(res.previousRepresentation === null && deepRepresentation) { | 173 | } else if (res.previousRepresentation === null && deepRepresentation) { |
161 | throw new IllegalArgumentException('''Need previous representations''') | 174 | throw new IllegalArgumentException('''Need previous representations''') |
162 | } else return res | 175 | } else |
176 | return res | ||
163 | } else if (range == FixPointRage) { | 177 | } else if (range == FixPointRage) { |
164 | return refineUntilFixpoint(model,types,IncomingRelations,OutgoingRelations,parallels,maxNumber) | 178 | return refineUntilFixpoint(model, types, IncomingRelations, OutgoingRelations, parallels, maxNumber, |
179 | focusedElement) | ||
165 | } else if (range == GraphWidthRange) { | 180 | } else if (range == GraphWidthRange) { |
166 | val width = this.getWidth(types,IncomingRelations,OutgoingRelations) | 181 | val width = this.getWidth(types, IncomingRelations, OutgoingRelations) |
167 | //println(width) | 182 | // println(width) |
168 | return doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,width,parallels,maxNumber) | 183 | return doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, width, parallels, |
184 | maxNumber, focusedElement) | ||
169 | } | 185 | } |
170 | } | 186 | } |
171 | 187 | ||
172 | def private refineUntilFixpoint( | 188 | def private refineUntilFixpoint(PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
173 | PartialInterpretation model, | ||
174 | Map<DefinedElement, Set<String>> types, | ||
175 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 189 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
176 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 190 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, int maxNumbers, |
177 | int parallels, int maxNumbers) | 191 | DefinedElement focusedElement) { |
178 | { | ||
179 | var lastRange = 0 | 192 | var lastRange = 0 |
180 | val last = calculateLocalNodeDescriptors(model,types,maxNumbers) | 193 | val last = calculateLocalNodeDescriptors(model, types, maxNumbers, focusedElement) |
181 | var lastRepresentation = this.createLocalRepresentation(last.value,last.key) | 194 | var lastRepresentation = this.createLocalRepresentation(last.value, last.key) |
182 | //println('''Level 0 finished.''') | 195 | // println('''Level 0 finished.''') |
183 | var boolean hasRefined | 196 | var boolean hasRefined |
184 | do { | 197 | do { |
185 | val nextRange = lastRange+1 | 198 | val nextRange = lastRange + 1 |
186 | val next = calculateFurtherNodeDescriptors(model,lastRepresentation,IncomingRelations,OutgoingRelations,parallels,maxNumbers) | 199 | val next = calculateFurtherNodeDescriptors(model, lastRepresentation, IncomingRelations, OutgoingRelations, |
187 | val nextRepresentation = createFurtherRepresentation(next.key,next.value,lastRepresentation,deepRepresentation) | 200 | parallels, maxNumbers) |
188 | 201 | val nextRepresentation = createFurtherRepresentation(next.key, next.value, lastRepresentation, | |
189 | val previousNumberOfTypes =lastRepresentation.nodeRepresentations.values.toSet.size | 202 | deepRepresentation) |
203 | |||
204 | val previousNumberOfTypes = lastRepresentation.nodeRepresentations.values.toSet.size | ||
190 | val nextNumberOfTypes = nextRepresentation.nodeRepresentations.values.toSet.size | 205 | val nextNumberOfTypes = nextRepresentation.nodeRepresentations.values.toSet.size |
191 | hasRefined = nextNumberOfTypes > previousNumberOfTypes | 206 | hasRefined = nextNumberOfTypes > previousNumberOfTypes |
192 | 207 | ||
193 | lastRange = nextRange | 208 | lastRange = nextRange |
194 | lastRepresentation = nextRepresentation | 209 | lastRepresentation = nextRepresentation |
195 | 210 | ||
196 | // if(hasRefined) { | 211 | // if(hasRefined) { |
197 | // println('''Level «nextRange» is calculated, number of types is refined: «previousNumberOfTypes» -> «nextNumberOfTypes»''') | 212 | // println('''Level «nextRange» is calculated, number of types is refined: «previousNumberOfTypes» -> «nextNumberOfTypes»''') |
198 | // } else { | 213 | // } else { |
@@ -201,211 +216,219 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
201 | } while (hasRefined) | 216 | } while (hasRefined) |
202 | return lastRepresentation | 217 | return lastRepresentation |
203 | } | 218 | } |
204 | 219 | ||
205 | def private getElements(PartialInterpretation model) { | 220 | def private getElements(PartialInterpretation model) { |
206 | return | 221 | return model.problem.elements + model.newElements + model.openWorldElements |
207 | model.problem.elements + | ||
208 | model.newElements + | ||
209 | model.openWorldElements | ||
210 | } | 222 | } |
211 | 223 | ||
212 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, Set<TypeDeclaration> relevantTypes) { | 224 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, |
213 | for(element : model.elements) { | 225 | Set<TypeDeclaration> relevantTypes) { |
226 | for (element : model.elements) { | ||
214 | node2Type.put(element, new HashSet) | 227 | node2Type.put(element, new HashSet) |
215 | } | 228 | } |
216 | 229 | ||
217 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { | 230 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { |
218 | // // Dont need | 231 | // // Dont need |
219 | // } | 232 | // } |
220 | for(typeInterpretation : model.partialtypeinterpratation) { | 233 | for (typeInterpretation : model.partialtypeinterpratation) { |
221 | if(typeInterpretation instanceof PartialPrimitiveInterpretation) { | 234 | if (typeInterpretation instanceof PartialPrimitiveInterpretation) { |
222 | 235 | } else if (typeInterpretation instanceof PartialComplexTypeInterpretation) { | |
223 | } else if(typeInterpretation instanceof PartialComplexTypeInterpretation) { | ||
224 | val type = typeInterpretation.interpretationOf | 236 | val type = typeInterpretation.interpretationOf |
225 | if(type.isRelevant(relevantTypes)) { | 237 | if (type.isRelevant(relevantTypes)) { |
226 | for(element : typeInterpretation.elements) { | 238 | for (element : typeInterpretation.elements) { |
227 | element.lookup(node2Type).add(type.name) | 239 | element.lookup(node2Type).add(type.name) |
228 | } | 240 | } |
229 | } | 241 | } |
230 | } | 242 | } |
231 | } | 243 | } |
232 | } | 244 | } |
233 | 245 | ||
234 | /** | 246 | /** |
235 | * Indexes the references | 247 | * Indexes the references |
236 | */ | 248 | */ |
237 | def private fillReferences(PartialInterpretation model, | 249 | def private fillReferences(PartialInterpretation model, |
238 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 250 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
239 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 251 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
240 | Set<RelationDeclaration> relevantRelations) | 252 | Set<RelationDeclaration> relevantRelations) { |
241 | { | 253 | for (object : model.elements) { |
242 | for(object : model.elements) { | 254 | IncomingRelations.put(object, new ArrayList) |
243 | IncomingRelations.put(object,new LinkedList) | 255 | OutgoingRelations.put(object, new ArrayList) |
244 | OutgoingRelations.put(object,new LinkedList) | ||
245 | } | 256 | } |
246 | for(relationInterpretation : model.partialrelationinterpretation) { | 257 | for (relationInterpretation : model.partialrelationinterpretation) { |
247 | val type = relationInterpretation.interpretationOf | 258 | val type = relationInterpretation.interpretationOf |
248 | if(type.isRelevant(relevantRelations)) { | 259 | if (type.isRelevant(relevantRelations)) { |
249 | for(link : relationInterpretation.relationlinks) { | 260 | for (link : relationInterpretation.relationlinks) { |
250 | if(link instanceof BinaryElementRelationLink) { | 261 | if (link instanceof BinaryElementRelationLink) { |
251 | OutgoingRelations.get(link.param1) += new OutgoingRelation(link.param2,type.name) | 262 | OutgoingRelations.get(link.param1) += new OutgoingRelation(link.param2, type.name) |
252 | IncomingRelations.get(link.param2) += new IncomingRelation(link.param1,type.name) | 263 | IncomingRelations.get(link.param2) += new IncomingRelation(link.param1, type.name) |
253 | } else throw new UnsupportedOperationException | 264 | } else |
265 | throw new UnsupportedOperationException | ||
254 | } | 266 | } |
255 | } | 267 | } |
256 | } | 268 | } |
257 | } | 269 | } |
258 | 270 | ||
259 | /** | 271 | /** |
260 | * Creates a local representation of the objects (aka zero range neighbourhood) | 272 | * Creates a local representation of the objects (aka zero range neighbourhood) |
261 | */ | 273 | */ |
262 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> createLocalRepresentation( | 274 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> createLocalRepresentation( |
263 | Map<DefinedElement, LocalNodeDescriptor> node2Representation, | 275 | Map<DefinedElement, LocalNodeDescriptor> node2Representation, |
264 | Map<LocalNodeDescriptor, Integer> representation2Amount | 276 | Map<LocalNodeDescriptor, Integer> representation2Amount |
265 | ) | 277 | ) |
266 | 278 | ||
267 | /** | 279 | /** |
268 | * Creates a | 280 | * Creates a |
269 | */ | 281 | */ |
270 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> createFurtherRepresentation( | 282 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> createFurtherRepresentation( |
271 | Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> nodeDescriptors, | 283 | Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> nodeDescriptors, |
272 | Map<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> node2Representation, | 284 | Map<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> node2Representation, |
273 | NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> previous, | 285 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, |
274 | boolean deepRepresentation | 286 | boolean deepRepresentation |
275 | ) | 287 | ) |
276 | 288 | ||
277 | def private addOne(int original, int max) { | 289 | def private addOne(int original, int max) { |
278 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE | 290 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE |
279 | if(original +1 > max) return Integer.MAX_VALUE | 291 | if(original + 1 > max) return Integer.MAX_VALUE else return original + 1 |
280 | else return original+1 | ||
281 | } | 292 | } |
282 | 293 | ||
283 | private def calculateIncomingEdges(Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 294 | private def calculateIncomingEdges(Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
284 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) | 295 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, |
285 | { | 296 | int parallel) { |
286 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = new HashMap | 297 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = new HashMap |
287 | for (incomingConcreteEdge : IncomingRelations.get(object)) { | 298 | for (incomingConcreteEdge : IncomingRelations.get(object)) { |
288 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( | 299 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( |
289 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) | 300 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) |
290 | if (res.containsKey(e)) { | 301 | if (res.containsKey(e)) { |
291 | res.put(e, addOne(res.get(e),parallel)) | 302 | res.put(e, addOne(res.get(e), parallel)) |
292 | } else { | 303 | } else { |
293 | res.put(e, 1) | 304 | res.put(e, 1) |
294 | } | 305 | } |
295 | } | 306 | } |
296 | return res | 307 | return res |
297 | } | 308 | } |
298 | 309 | ||
299 | private def calcuateOutgoingEdges(Map<DefinedElement,List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 310 | private def calcuateOutgoingEdges(Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
300 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) | 311 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, |
301 | { | 312 | int parallel) { |
302 | val Map<OutgoingRelation<NodeRepresentation>,Integer> res= new HashMap | 313 | val Map<OutgoingRelation<NodeRepresentation>, Integer> res = new HashMap |
303 | for(outgoingConcreteEdge : OutgoingRelations.get(object)) { | 314 | for (outgoingConcreteEdge : OutgoingRelations.get(object)) { |
304 | val OutgoingRelation<NodeRepresentation> e = | 315 | val OutgoingRelation<NodeRepresentation> e = new OutgoingRelation( |
305 | new OutgoingRelation( | 316 | previousNodeRepresentations.get(outgoingConcreteEdge.to), outgoingConcreteEdge.type) |
306 | previousNodeRepresentations.get(outgoingConcreteEdge.to), | 317 | if (res.containsKey(e)) { |
307 | outgoingConcreteEdge.type) | 318 | res.put(e, addOne(res.get(e), parallel)) |
308 | if(res.containsKey(e)) { | ||
309 | res.put(e,addOne(res.get(e),parallel)) | ||
310 | } else { | 319 | } else { |
311 | res.put(e,1) | 320 | res.put(e, 1) |
312 | } | 321 | } |
313 | } | 322 | } |
314 | return res; | 323 | return res; |
315 | } | 324 | } |
316 | 325 | ||
317 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { | 326 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { |
318 | var Set<VALUE> s; | 327 | * var Set<VALUE> s; |
319 | if(map.containsKey(key)) { | 328 | * if(map.containsKey(key)) { |
320 | s = map.get(key); | 329 | * s = map.get(key); |
321 | } else { | 330 | * } else { |
322 | s = new HashSet | 331 | * s = new HashSet |
323 | map.put(key,s) | 332 | * map.put(key,s) |
324 | } | 333 | * } |
325 | s.add(value) | 334 | * s.add(value) |
326 | }*/ | 335 | }*/ |
327 | 336 | private def calculateFurtherNodeDescriptors(PartialInterpretation model, | |
328 | |||
329 | private def calculateFurtherNodeDescriptors( | ||
330 | PartialInterpretation model, | ||
331 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, | 337 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, |
332 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 338 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
333 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 339 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, int maxNumber) { |
334 | int parallels, int maxNumber) | ||
335 | { | ||
336 | val previousNodeRepresentations = previous.nodeRepresentations | 340 | val previousNodeRepresentations = previous.nodeRepresentations |
337 | val node2Representation = new HashMap<DefinedElement,FurtherNodeDescriptor<NodeRepresentation>> | 341 | val node2Representation = new HashMap<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> |
338 | val Map<FurtherNodeDescriptor<NodeRepresentation>,Integer> descriptor2Number = | 342 | val Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> descriptor2Number = if (this. |
339 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | 343 | mergeSimilarNeighbourhood) { |
340 | val Map<FurtherNodeDescriptor<NodeRepresentation>,FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = | 344 | new HashMap |
341 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | 345 | } else { |
342 | 346 | null | |
343 | for(object: model.elements) { | 347 | } |
344 | val incomingEdges = this.calculateIncomingEdges(IncomingRelations, object, previousNodeRepresentations,parallels) | 348 | val Map<FurtherNodeDescriptor<NodeRepresentation>, FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = if (this. |
345 | val outgoingEdges = this.calcuateOutgoingEdges(OutgoingRelations,object, previousNodeRepresentations,parallels) | 349 | mergeSimilarNeighbourhood) { |
346 | 350 | new HashMap | |
351 | } else { | ||
352 | null | ||
353 | } | ||
354 | |||
355 | for (object : model.elements) { | ||
356 | val incomingEdges = this.calculateIncomingEdges(IncomingRelations, object, previousNodeRepresentations, | ||
357 | parallels) | ||
358 | val outgoingEdges = this.calcuateOutgoingEdges(OutgoingRelations, object, previousNodeRepresentations, | ||
359 | parallels) | ||
360 | |||
347 | val previousType = previousNodeRepresentations.get(object) | 361 | val previousType = previousNodeRepresentations.get(object) |
348 | 362 | ||
349 | if(previousType === null) { | 363 | if (previousType === null) { |
350 | println("Error in state coder") | 364 | println("Error in state coder") |
351 | } | 365 | } |
352 | 366 | ||
353 | val nodeDescriptor = new FurtherNodeDescriptor( | 367 | val nodeDescriptor = new FurtherNodeDescriptor(previousType, incomingEdges, outgoingEdges) |
354 | previousType, | 368 | |
355 | incomingEdges, | 369 | if (this.mergeSimilarNeighbourhood) { |
356 | outgoingEdges) | 370 | if (descriptor2Number.containsKey(nodeDescriptor)) { |
357 | |||
358 | if(this.mergeSimilarNeighbourhood) { | ||
359 | if(descriptor2Number.containsKey(nodeDescriptor)) { | ||
360 | descriptor2Number.put( | 371 | descriptor2Number.put( |
361 | nodeDescriptor, | 372 | nodeDescriptor, |
362 | addOne(descriptor2Number.get(nodeDescriptor),maxNumber) | 373 | addOne(descriptor2Number.get(nodeDescriptor), maxNumber) |
363 | ) | 374 | ) |
364 | node2Representation.put(object,uniqueDescription.get(nodeDescriptor)) | 375 | node2Representation.put(object, uniqueDescription.get(nodeDescriptor)) |
365 | } else { | 376 | } else { |
366 | descriptor2Number.put(nodeDescriptor,if(1>maxNumber){Integer.MAX_VALUE}else{1}) | 377 | descriptor2Number.put(nodeDescriptor, if (1 > maxNumber) { |
367 | uniqueDescription.put(nodeDescriptor,nodeDescriptor) | 378 | Integer.MAX_VALUE |
368 | node2Representation.put(object,nodeDescriptor) | 379 | } else { |
380 | 1 | ||
381 | }) | ||
382 | uniqueDescription.put(nodeDescriptor, nodeDescriptor) | ||
383 | node2Representation.put(object, nodeDescriptor) | ||
369 | } | 384 | } |
370 | } else { | 385 | } else { |
371 | node2Representation.put(object,nodeDescriptor) | 386 | node2Representation.put(object, nodeDescriptor) |
372 | } | 387 | } |
373 | } | 388 | } |
374 | 389 | ||
375 | return descriptor2Number -> node2Representation | 390 | return descriptor2Number -> node2Representation |
376 | } | 391 | } |
377 | 392 | ||
378 | private def calculateLocalNodeDescriptors( | 393 | private def calculateLocalNodeDescriptors(PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
379 | PartialInterpretation model, | 394 | int maxNumber, DefinedElement focusedElement) { |
380 | Map<DefinedElement, Set<String>> types, | ||
381 | int maxNumber) | ||
382 | { | ||
383 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = new HashMap | 395 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = new HashMap |
384 | val Map<LocalNodeDescriptor, Integer> representation2Amount = | 396 | val Map<LocalNodeDescriptor, Integer> representation2Amount = if (mergeSimilarNeighbourhood) { |
385 | if(mergeSimilarNeighbourhood){ new HashMap } else { null } | 397 | new HashMap |
386 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = | 398 | } else { |
387 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | 399 | null |
388 | 400 | } | |
389 | for(element : model.elements) { | 401 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = if (this.mergeSimilarNeighbourhood) { |
390 | var newDescriptor = new LocalNodeDescriptor(element.name,element.lookup(types)) | 402 | new HashMap |
391 | if(this.mergeSimilarNeighbourhood){ | 403 | } else { |
392 | if(uniqueRepresentation.containsKey(newDescriptor)) { | 404 | null |
405 | } | ||
406 | |||
407 | for (element : model.elements) { | ||
408 | val name = if(element == focusedElement) FOCUSED_ELEMENT_NAME else element.name | ||
409 | var newDescriptor = new LocalNodeDescriptor(name, element.lookup(types)) | ||
410 | if (this.mergeSimilarNeighbourhood) { | ||
411 | if (uniqueRepresentation.containsKey(newDescriptor)) { | ||
393 | newDescriptor = newDescriptor.lookup(uniqueRepresentation) | 412 | newDescriptor = newDescriptor.lookup(uniqueRepresentation) |
394 | node2Representation.put(element,newDescriptor) | 413 | node2Representation.put(element, newDescriptor) |
395 | representation2Amount.put( | 414 | representation2Amount.put( |
396 | newDescriptor, | 415 | newDescriptor, |
397 | addOne(newDescriptor.lookup(representation2Amount),maxNumber) | 416 | addOne(newDescriptor.lookup(representation2Amount), maxNumber) |
398 | ) | 417 | ) |
399 | } else { | 418 | } else { |
400 | uniqueRepresentation.put(newDescriptor,newDescriptor) | 419 | uniqueRepresentation.put(newDescriptor, newDescriptor) |
401 | node2Representation.put(element,newDescriptor) | 420 | node2Representation.put(element, newDescriptor) |
402 | representation2Amount.put(newDescriptor, if(1>maxNumber){Integer.MAX_VALUE}else{1}) | 421 | representation2Amount.put(newDescriptor, if (1 > maxNumber) { |
422 | Integer.MAX_VALUE | ||
423 | } else { | ||
424 | 1 | ||
425 | }) | ||
403 | } | 426 | } |
404 | } else { | 427 | } else { |
405 | node2Representation.put(element,newDescriptor) | 428 | node2Representation.put(element, newDescriptor) |
406 | } | 429 | } |
407 | } | 430 | } |
408 | 431 | ||
409 | return representation2Amount -> node2Representation | 432 | return representation2Amount -> node2Representation |
410 | } | 433 | } |
411 | } \ No newline at end of file | 434 | } |