diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage')
3 files changed, 410 insertions, 296 deletions
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..2e8f61a9 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,6 +4,7 @@ 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 java.util.List | ||
7 | 8 | ||
8 | @Data abstract class AbstractNodeDescriptor { | 9 | @Data abstract class AbstractNodeDescriptor { |
9 | long dataHash | 10 | long dataHash |
@@ -24,6 +25,7 @@ import org.eclipse.xtend.lib.annotations.Data | |||
24 | // } | 25 | // } |
25 | } | 26 | } |
26 | 27 | ||
28 | //TODO: Modify for patterns | ||
27 | @Data class LocalNodeDescriptor extends AbstractNodeDescriptor{ | 29 | @Data class LocalNodeDescriptor extends AbstractNodeDescriptor{ |
28 | Set<String> types | 30 | Set<String> types |
29 | String id; | 31 | String id; |
@@ -87,6 +89,14 @@ import org.eclipse.xtend.lib.annotations.Data | |||
87 | // } | 89 | // } |
88 | } | 90 | } |
89 | 91 | ||
92 | //TODO: PatternRelation | ||
93 | |||
94 | @Data class PatternRelation<NODESHAPE> { | ||
95 | String patternName | ||
96 | int param | ||
97 | List<NODESHAPE> parameters | ||
98 | } | ||
99 | |||
90 | @Data class IncomingRelation<FROM> { | 100 | @Data class IncomingRelation<FROM> { |
91 | FROM from | 101 | FROM from |
92 | String type | 102 | String type |
@@ -97,6 +107,7 @@ import org.eclipse.xtend.lib.annotations.Data | |||
97 | String type | 107 | String type |
98 | } | 108 | } |
99 | 109 | ||
110 | //TODO: Modify for hypergraphs | ||
100 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor{ | 111 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor{ |
101 | 112 | ||
102 | NodeRep previousRepresentation | 113 | NodeRep previousRepresentation |
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 bf593add..1d26a413 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,109 +4,196 @@ 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 | ||
8 | import java.util.HashMap | 10 | import java.util.HashMap |
9 | import java.util.HashSet | 11 | import java.util.HashSet |
10 | import java.util.LinkedList | 12 | 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 |
16 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
17 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | ||
14 | 18 | ||
15 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 19 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation | 20 | import java.util.ArrayList |
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | ||
18 | 21 | ||
19 | abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresentation,NodeRepresentation> { | 22 | abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresentation, NodeRepresentation> { |
23 | /** | ||
24 | * Includes shape of a smaller range in the current shape | ||
25 | */ | ||
20 | private val boolean deepRepresentation | 26 | private val boolean deepRepresentation |
27 | /** | ||
28 | * Treats similar shapes as one (recommended) | ||
29 | */ | ||
21 | private val boolean mergeSimilarNeighbourhood | 30 | private val boolean mergeSimilarNeighbourhood |
22 | 31 | ||
23 | protected new(boolean deeprepresentation, boolean mergeSimilarNeighbourhood) { | 32 | protected new(boolean deeprepresentation, boolean mergeSimilarNeighbourhood) { |
24 | this.deepRepresentation = deeprepresentation | 33 | this.deepRepresentation = deeprepresentation |
25 | this.mergeSimilarNeighbourhood = mergeSimilarNeighbourhood | 34 | this.mergeSimilarNeighbourhood = mergeSimilarNeighbourhood |
26 | } | 35 | } |
27 | 36 | ||
37 | /** | ||
38 | * Constant to be used as the range parameter of the createRepresentation function for enforcing fix point semantics instead of a predefined range | ||
39 | */ | ||
28 | public static val FixPointRage = -1 | 40 | public static val FixPointRage = -1 |
41 | /** | ||
42 | * Constant to be used as the range parameter of the createRepresentation function for using the width of the graph as the range | ||
43 | */ | ||
29 | public static val GraphWidthRange = -2 | 44 | public static val GraphWidthRange = -2 |
45 | /** | ||
46 | * Constant to be used as the parallels parameter of the createRepresentation function for prohibiting cardinality abstractions | ||
47 | */ | ||
30 | public static val FullParallels = Integer.MAX_VALUE | 48 | public static val FullParallels = Integer.MAX_VALUE |
49 | /** | ||
50 | * Constant to be used as the parallels parameter of the createRepresentation function for prohibiting multiplicity abstractions | ||
51 | */ | ||
31 | public static val MaxNumbers = Integer.MAX_VALUE | 52 | public static val MaxNumbers = Integer.MAX_VALUE |
32 | 53 | ||
33 | /** | 54 | /** |
34 | * Creates a neighbourhood representation with traces | 55 | * Creates a neighbourhood representation with traces |
35 | * @param model The model to be represented. | 56 | * @param model The model to be represented. |
36 | * @param range The range of the neighbourhood. | 57 | * @param range The range of the neighbourhood. |
37 | * @param parallels The maximal number of parallel references to be differentiated. | 58 | * @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. | 59 | * @param maxNumber The maximal number of elements in a equivalence class that can be differentiated. |
39 | */ | 60 | */ |
40 | def public createRepresentation(PartialInterpretation model, int range, int parallels, int maxNumber) { | 61 | def public createRepresentation(PartialInterpretation model, int range, int parallels, int maxNumber) { |
41 | return createRepresentation(model,range,parallels,maxNumber,null,null) | 62 | return createRepresentation(model, range, parallels, maxNumber, null, null, null) |
42 | } | 63 | } |
43 | 64 | ||
44 | def public createRepresentation( | 65 | /** |
45 | PartialInterpretation model, | 66 | * Creates a neighbourhood representation with traces |
46 | int range, int parallels, int maxNumber, | 67 | * @param model The model to be represented. |
47 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations) | 68 | * @param range The range of the neighbourhood. |
48 | { | 69 | * @param parallels The maximal number of parallel references to be differentiated. |
70 | * @param maxNumber The maximal number of elements in a equivalence class that can be differentiated. | ||
71 | * @param relevantTypes The set of types to include in the diversity calculations (when value is null, all types are considered) | ||
72 | * @param relevantRelations The set of relations to include in the diversity calculations (when value is null, all relations are considered) | ||
73 | * @param relevantPatterns The set of patterns to include in the diversity calculations | ||
74 | * (NOT the well-formedness constraints) - when value is null, NO patterns are considered | ||
75 | */ | ||
76 | def public createRepresentation(PartialInterpretation model, int range, int parallels, int maxNumber, | ||
77 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations, | ||
78 | Set<ViatraQueryMatcher<? extends IPatternMatch>> relevantPatterns) { | ||
79 | |||
49 | val Map<DefinedElement, Set<String>> types = new HashMap | 80 | val Map<DefinedElement, Set<String>> types = new HashMap |
50 | fillTypes(model,types,relevantTypes) | 81 | fillTypes(model, types, relevantTypes) |
51 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = new HashMap; | 82 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = new HashMap; |
52 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = new HashMap; | 83 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = new HashMap; |
53 | fillReferences(model,IncomingRelations,OutgoingRelations,relevantRelations) | 84 | fillReferences(model, IncomingRelations, OutgoingRelations, relevantRelations); |
85 | val Map<DefinedElement, List<PatternRelation<DefinedElement>>> PatternRelations = createPatternRelations(model, | ||
86 | relevantPatterns); | ||
54 | 87 | ||
55 | val res = doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,range,parallels,maxNumber); | ||
56 | 88 | ||
89 | |||
90 | val res = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, PatternRelations,range, parallels, | ||
91 | maxNumber); | ||
92 | |||
57 | return res; | 93 | return res; |
58 | } | 94 | } |
59 | 95 | ||
96 | /** | ||
97 | * Collects all pattern relations for shaping | ||
98 | */ | ||
99 | def Map<DefinedElement, List<PatternRelation<DefinedElement>>> createPatternRelations( | ||
100 | PartialInterpretation model, Set<ViatraQueryMatcher<? extends IPatternMatch>> relevantPatterns) { | ||
101 | val Map<DefinedElement, List<PatternRelation<DefinedElement>>> result=new HashMap; | ||
102 | if (relevantPatterns==null) return result; | ||
103 | for (element : model.elements) { | ||
104 | result.put(element,new LinkedList<PatternRelation<DefinedElement>>) | ||
105 | } | ||
106 | |||
107 | for (pattern : relevantPatterns) { | ||
108 | val name=pattern.patternName | ||
109 | val arity=pattern.parameterNames.size | ||
110 | |||
111 | val ignoredParams=new HashSet<String>(); | ||
112 | |||
113 | for (match : pattern.allMatches) { | ||
114 | val sanitizedMatch=new ArrayList<DefinedElement>(); | ||
115 | for (var i=0; i<arity;i++) { | ||
116 | val matchedElement=match.get(i) | ||
117 | if (matchedElement instanceof DefinedElement) { | ||
118 | sanitizedMatch.add(matchedElement) | ||
119 | } else { | ||
120 | ignoredParams.add(pattern.parameterNames.get(i)) | ||
121 | } | ||
122 | } | ||
123 | var id=0; | ||
124 | for (DefinedElement e:sanitizedMatch) { | ||
125 | if (e!=null) { | ||
126 | result.get(e).add(new PatternRelation<DefinedElement>(name,id,sanitizedMatch)) | ||
127 | } | ||
128 | id++ | ||
129 | } | ||
130 | } | ||
131 | |||
132 | println('''Ignored params '''+ignoredParams+''' of pattern '''+ name) | ||
133 | } | ||
134 | |||
135 | /*for(relevantPattern : relevantPatterns) { | ||
136 | * relevantPattern.allMatches.forEach[ | ||
137 | * it. | ||
138 | * ] | ||
139 | }*/ | ||
140 | |||
141 | |||
142 | return result; | ||
143 | |||
144 | } | ||
145 | |||
60 | def private isRelevant(TypeDeclaration t, Set<TypeDeclaration> relevantTypes) { | 146 | def private isRelevant(TypeDeclaration t, Set<TypeDeclaration> relevantTypes) { |
61 | if(relevantTypes === null) { | 147 | if (relevantTypes === null) { |
62 | return true | 148 | return true |
63 | } else { | 149 | } else { |
64 | return relevantTypes.contains(t) | 150 | return relevantTypes.contains(t) |
65 | } | 151 | } |
66 | } | 152 | } |
153 | |||
67 | def private isRelevant(RelationDeclaration r, Set<RelationDeclaration> relevantRelations) { | 154 | def private isRelevant(RelationDeclaration r, Set<RelationDeclaration> relevantRelations) { |
68 | if(relevantRelations === null) { | 155 | if (relevantRelations === null) { |
69 | return true | 156 | return true |
70 | } else { | 157 | } else { |
71 | return relevantRelations.contains(r) | 158 | return relevantRelations.contains(r) |
72 | } | 159 | } |
73 | } | 160 | } |
161 | |||
74 | /** | 162 | /** |
75 | * Gets the largest | 163 | * @returns the diameter (maximal size of shortest paths between nodes) of the partial model |
76 | */ | 164 | */ |
77 | def private getWidth(Map<DefinedElement, Set<String>> types, | 165 | def private getWidth(Map<DefinedElement, Set<String>> types, |
78 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 166 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
79 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) | 167 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) { |
80 | { | 168 | val elements = types.keySet |
81 | val elements = types.keySet | 169 | val Map<DefinedElement, Set<DefinedElement>> reachable = new HashMap |
82 | val Map<DefinedElement,Set<DefinedElement>> reachable = new HashMap | 170 | for (element : elements) { |
83 | for(element : elements) { | ||
84 | val set = new HashSet | 171 | val set = new HashSet |
85 | set.add(element) | 172 | set.add(element) |
86 | reachable.put(element,set) | 173 | reachable.put(element, set) |
87 | } | 174 | } |
88 | 175 | ||
89 | var int width = 0 | 176 | var int width = 0 |
90 | var boolean newAdded | 177 | var boolean newAdded |
91 | do { | 178 | do { |
92 | newAdded = false | 179 | newAdded = false |
93 | for(element : elements) { | 180 | for (element : elements) { |
94 | val elementNeigbours = element.lookup(reachable) | 181 | val elementNeigbours = element.lookup(reachable) |
95 | val size = elementNeigbours.size | 182 | val size = elementNeigbours.size |
96 | for(incoming : element.lookup(IncomingRelations)) { | 183 | for (incoming : element.lookup(IncomingRelations)) { |
97 | elementNeigbours.addAll(incoming.from.lookup(reachable)) | 184 | elementNeigbours.addAll(incoming.from.lookup(reachable)) |
98 | } | 185 | } |
99 | for(outgoing : element.lookup(OutgoingRelations)) { | 186 | for (outgoing : element.lookup(OutgoingRelations)) { |
100 | elementNeigbours.addAll(outgoing.to.lookup(reachable)) | 187 | elementNeigbours.addAll(outgoing.to.lookup(reachable)) |
101 | } | 188 | } |
102 | newAdded = newAdded || (elementNeigbours.size > size) | 189 | newAdded = newAdded || (elementNeigbours.size > size) |
103 | } | 190 | } |
104 | 191 | ||
105 | width +=1 | 192 | width += 1 |
106 | } while(newAdded) | 193 | } while (newAdded) |
107 | return width | 194 | return width |
108 | } | 195 | } |
109 | 196 | ||
110 | /** | 197 | /** |
111 | * Creates a neighbourhood representation with traces | 198 | * Creates a neighbourhood representation with traces |
112 | * @param model The model to be represented. | 199 | * @param model The model to be represented. |
@@ -115,281 +202,296 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
115 | * @param range The range of the neighbourhood. | 202 | * @param range The range of the neighbourhood. |
116 | * @param parallels The maximal number of parallel references to be differentiated. | 203 | * @param parallels The maximal number of parallel references to be differentiated. |
117 | */ | 204 | */ |
118 | def private NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> doRecursiveNeighbourCalculation( | 205 | def private NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> doRecursiveNeighbourCalculation( |
119 | PartialInterpretation model, | 206 | PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
120 | Map<DefinedElement, Set<String>> types, | ||
121 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 207 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
122 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 208 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
123 | int range, int parallels, int maxNumber) | 209 | Map<DefinedElement, List<PatternRelation<DefinedElement>>> PatternRelations, int range, int parallels, |
124 | { | 210 | int maxNumber) { |
125 | if(range == 0){ | 211 | if (range == 0) { |
126 | val r = calculateLocalNodeDescriptors(model,types,maxNumber) | 212 | val r = calculateLocalNodeDescriptors(model, types, maxNumber) |
127 | val res = this.createLocalRepresentation(r.value,r.key) | 213 | val res = this.createLocalRepresentation(r.value, r.key) |
128 | if(res.modelRepresentation === null) { | 214 | if (res.modelRepresentation === null) { |
129 | throw new IllegalArgumentException('''Model representation is null''') | 215 | throw new IllegalArgumentException('''Model representation is null''') |
130 | } else if(res.nodeRepresentations === null || res.nodeRepresentations.empty) { | 216 | } else if (res.nodeRepresentations === null || res.nodeRepresentations.empty) { |
131 | throw new IllegalArgumentException('''No node representation''') | 217 | throw new IllegalArgumentException('''No node representation''') |
132 | } else if(res.previousRepresentation !== null) { | 218 | } else if (res.previousRepresentation !== null) { |
133 | throw new IllegalArgumentException('''The previous representation of the first neighbourhood have to be null''') | 219 | throw new IllegalArgumentException('''The previous representation of the first neighbourhood have to be null''') |
134 | } else return res | 220 | } else |
135 | } else if(range > 0) { | 221 | return res |
136 | val previous = doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,range-1,parallels,maxNumber) | 222 | } else if (range > 0) { |
137 | val r = calculateFurtherNodeDescriptors(model,previous,IncomingRelations,OutgoingRelations,parallels,maxNumber) | 223 | val previous = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, PatternRelations, |
138 | //println('''Level «range» finished.''') | 224 | range - 1, parallels, maxNumber) |
139 | val res = createFurtherRepresentation(r.key,r.value,previous,deepRepresentation) | 225 | val r = calculateFurtherNodeDescriptors(model, previous, IncomingRelations, OutgoingRelations, |
140 | if(res.modelRepresentation === null) { | 226 | parallels, maxNumber) |
141 | throw new IllegalArgumentException('''Model representation is null''') | 227 | // println('''Level «range» finished.''') |
142 | } else if(res.nodeRepresentations === null || res.nodeRepresentations.empty) { | 228 | val res = createFurtherRepresentation(r.key, r.value, previous, deepRepresentation) |
143 | throw new IllegalArgumentException('''No node representation''') | 229 | if (res.modelRepresentation === null) { |
144 | } else if(res.previousRepresentation === null && deepRepresentation) { | 230 | throw new IllegalArgumentException('''Model representation is null''') |
145 | throw new IllegalArgumentException('''Need previous representations''') | 231 | } else if (res.nodeRepresentations === null || res.nodeRepresentations.empty) { |
146 | } else return res | 232 | throw new IllegalArgumentException('''No node representation''') |
147 | } else if (range == FixPointRage) { | 233 | } else if (res.previousRepresentation === null && deepRepresentation) { |
148 | return refineUntilFixpoint(model,types,IncomingRelations,OutgoingRelations,parallels,maxNumber) | 234 | throw new IllegalArgumentException('''Need previous representations''') |
149 | } else if (range == GraphWidthRange) { | 235 | } else |
150 | val width = this.getWidth(types,IncomingRelations,OutgoingRelations) | 236 | return res |
151 | //println(width) | 237 | } else if (range == FixPointRage) { |
152 | return doRecursiveNeighbourCalculation(model,types,IncomingRelations,OutgoingRelations,width,parallels,maxNumber) | 238 | return refineUntilFixpoint(model, types, IncomingRelations, OutgoingRelations, parallels, maxNumber) |
239 | } else if (range == GraphWidthRange) { | ||
240 | val width = this.getWidth(types, IncomingRelations, OutgoingRelations) | ||
241 | // println(width) | ||
242 | return doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations,PatternRelations, width, | ||
243 | parallels, maxNumber) | ||
244 | } | ||
153 | } | 245 | } |
154 | } | 246 | |
155 | 247 | def private refineUntilFixpoint(PartialInterpretation model, Map<DefinedElement, Set<String>> types, | |
156 | def private refineUntilFixpoint( | 248 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
157 | PartialInterpretation model, | 249 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, |
158 | Map<DefinedElement, Set<String>> types, | 250 | int maxNumbers) { |
159 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 251 | var lastRange = 0 |
160 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 252 | val last = calculateLocalNodeDescriptors(model, types, maxNumbers) |
161 | int parallels, int maxNumbers) | 253 | var lastRepresentation = this.createLocalRepresentation(last.value, last.key) |
162 | { | 254 | // println('''Level 0 finished.''') |
163 | var lastRange = 0 | 255 | var boolean hasRefined |
164 | val last = calculateLocalNodeDescriptors(model,types,maxNumbers) | 256 | do { |
165 | var lastRepresentation = this.createLocalRepresentation(last.value,last.key) | 257 | val nextRange = lastRange + 1 |
166 | //println('''Level 0 finished.''') | 258 | val next = calculateFurtherNodeDescriptors(model, lastRepresentation, IncomingRelations, |
167 | var boolean hasRefined | 259 | OutgoingRelations, parallels, maxNumbers) |
168 | do { | 260 | val nextRepresentation = createFurtherRepresentation(next.key, next.value, lastRepresentation, |
169 | val nextRange = lastRange+1 | 261 | deepRepresentation) |
170 | val next = calculateFurtherNodeDescriptors(model,lastRepresentation,IncomingRelations,OutgoingRelations,parallels,maxNumbers) | 262 | |
171 | val nextRepresentation = createFurtherRepresentation(next.key,next.value,lastRepresentation,deepRepresentation) | 263 | val previousNumberOfTypes = lastRepresentation.nodeRepresentations.values.toSet.size |
172 | 264 | val nextNumberOfTypes = nextRepresentation.nodeRepresentations.values.toSet.size | |
173 | val previousNumberOfTypes =lastRepresentation.nodeRepresentations.values.toSet.size | 265 | hasRefined = nextNumberOfTypes > previousNumberOfTypes |
174 | val nextNumberOfTypes = nextRepresentation.nodeRepresentations.values.toSet.size | 266 | |
175 | hasRefined = nextNumberOfTypes > previousNumberOfTypes | 267 | lastRange = nextRange |
176 | 268 | lastRepresentation = nextRepresentation | |
177 | lastRange = nextRange | 269 | |
178 | lastRepresentation = nextRepresentation | ||
179 | |||
180 | // if(hasRefined) { | 270 | // if(hasRefined) { |
181 | // println('''Level «nextRange» is calculated, number of types is refined: «previousNumberOfTypes» -> «nextNumberOfTypes»''') | 271 | // println('''Level «nextRange» is calculated, number of types is refined: «previousNumberOfTypes» -> «nextNumberOfTypes»''') |
182 | // } else { | 272 | // } else { |
183 | // println('''Level «nextRange» is calculated, but the number of types is not refined: «previousNumberOfTypes» = «nextNumberOfTypes»''') | 273 | // println('''Level «nextRange» is calculated, but the number of types is not refined: «previousNumberOfTypes» = «nextNumberOfTypes»''') |
184 | // } | 274 | // } |
185 | } while (hasRefined) | 275 | } while (hasRefined) |
186 | return lastRepresentation | 276 | return lastRepresentation |
187 | } | 277 | } |
188 | 278 | ||
189 | def private getElements(PartialInterpretation model) { | 279 | def private getElements(PartialInterpretation model) { |
190 | return | 280 | return model.problem.elements + model.newElements + model.openWorldElements |
191 | model.problem.elements + | 281 | } |
192 | model.newElements + | 282 | |
193 | model.openWorldElements | 283 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, |
194 | } | 284 | Set<TypeDeclaration> relevantTypes) { |
195 | 285 | for (element : model.elements) { | |
196 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, Set<TypeDeclaration> relevantTypes) { | 286 | node2Type.put(element, new HashSet) |
197 | for(element : model.elements) { | 287 | } |
198 | node2Type.put(element, new HashSet) | 288 | |
199 | } | ||
200 | |||
201 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { | 289 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { |
202 | // // Dont need | 290 | // // Dont need |
203 | // } | 291 | // } |
204 | for(typeInterpretation : model.partialtypeinterpratation) { | 292 | for (typeInterpretation : model.partialtypeinterpratation) { |
205 | if(typeInterpretation instanceof PartialPrimitiveInterpretation) { | 293 | if (typeInterpretation instanceof PartialPrimitiveInterpretation) { |
206 | 294 | } else if (typeInterpretation instanceof PartialComplexTypeInterpretation) { | |
207 | } else if(typeInterpretation instanceof PartialComplexTypeInterpretation) { | 295 | val type = typeInterpretation.interpretationOf |
208 | val type = typeInterpretation.interpretationOf | 296 | if (type.isRelevant(relevantTypes)) { |
209 | if(type.isRelevant(relevantTypes)) { | 297 | for (element : typeInterpretation.elements) { |
210 | for(element : typeInterpretation.elements) { | 298 | element.lookup(node2Type).add(type.name) |
211 | element.lookup(node2Type).add(type.name) | 299 | } |
300 | } | ||
212 | } | 301 | } |
213 | } | 302 | } |
214 | } | 303 | } |
215 | } | 304 | |
216 | } | 305 | /** |
217 | 306 | * Indexes the references | |
218 | /** | 307 | */ |
219 | * Indexes the references | 308 | def private fillReferences(PartialInterpretation model, |
220 | */ | 309 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
221 | def private fillReferences(PartialInterpretation model, | 310 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
222 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 311 | Set<RelationDeclaration> relevantRelations) { |
223 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 312 | for (object : model.elements) { |
224 | Set<RelationDeclaration> relevantRelations) | 313 | IncomingRelations.put(object, new LinkedList) |
225 | { | 314 | OutgoingRelations.put(object, new LinkedList) |
226 | for(object : model.elements) { | 315 | } |
227 | IncomingRelations.put(object,new LinkedList) | 316 | for (relationInterpretation : model.partialrelationinterpretation) { |
228 | OutgoingRelations.put(object,new LinkedList) | 317 | val type = relationInterpretation.interpretationOf |
229 | } | 318 | if (type.isRelevant(relevantRelations)) { |
230 | for(relationInterpretation : model.partialrelationinterpretation) { | 319 | for (link : relationInterpretation.relationlinks) { |
231 | val type = relationInterpretation.interpretationOf | 320 | if (link instanceof BinaryElementRelationLink) { |
232 | if(type.isRelevant(relevantRelations)) { | 321 | OutgoingRelations.get(link.param1) += new OutgoingRelation(link.param2, type.name) |
233 | for(link : relationInterpretation.relationlinks) { | 322 | IncomingRelations.get(link.param2) += new IncomingRelation(link.param1, type.name) |
234 | if(link instanceof BinaryElementRelationLink) { | 323 | } else |
235 | OutgoingRelations.get(link.param1) += new OutgoingRelation(link.param2,type.name) | 324 | throw new UnsupportedOperationException |
236 | IncomingRelations.get(link.param2) += new IncomingRelation(link.param1,type.name) | 325 | } |
237 | } else throw new UnsupportedOperationException | 326 | } |
327 | } | ||
238 | } | 328 | } |
239 | } | 329 | |
240 | } | 330 | /** |
241 | } | 331 | * Creates a local representation of the objects (aka zero range neighbourhood) |
242 | 332 | */ | |
243 | /** | 333 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> createLocalRepresentation( |
244 | * Creates a local representation of the objects (aka zero range neighbourhood) | 334 | Map<DefinedElement, LocalNodeDescriptor> node2Representation, |
245 | */ | 335 | Map<LocalNodeDescriptor, Integer> representation2Amount |
246 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> createLocalRepresentation( | 336 | ) |
247 | Map<DefinedElement, LocalNodeDescriptor> node2Representation, | 337 | |
248 | Map<LocalNodeDescriptor, Integer> representation2Amount | 338 | /** |
249 | ) | 339 | * Creates a |
250 | 340 | */ | |
251 | /** | 341 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> createFurtherRepresentation( |
252 | * Creates a | 342 | Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> nodeDescriptors, |
253 | */ | 343 | Map<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> node2Representation, |
254 | def abstract protected NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> createFurtherRepresentation( | 344 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, |
255 | Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> nodeDescriptors, | 345 | boolean deepRepresentation |
256 | Map<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> node2Representation, | 346 | ) |
257 | NeighbourhoodWithTraces<ModelRepresentation,NodeRepresentation> previous, | 347 | |
258 | boolean deepRepresentation | 348 | def private addOne(int original, int max) { |
259 | ) | 349 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE |
260 | 350 | if(original + 1 > max) return Integer.MAX_VALUE else return original + 1 | |
261 | def private addOne(int original, int max) { | ||
262 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE | ||
263 | if(original +1 > max) return Integer.MAX_VALUE | ||
264 | else return original+1 | ||
265 | } | ||
266 | |||
267 | private def calculateIncomingEdges(Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | ||
268 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) | ||
269 | { | ||
270 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = new HashMap | ||
271 | for (incomingConcreteEdge : IncomingRelations.get(object)) { | ||
272 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( | ||
273 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) | ||
274 | if (res.containsKey(e)) { | ||
275 | res.put(e, addOne(res.get(e),parallel)) | ||
276 | } else { | ||
277 | res.put(e, 1) | ||
278 | } | ||
279 | } | ||
280 | return res | ||
281 | } | ||
282 | |||
283 | private def calcuateOutgoingEdges(Map<DefinedElement,List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | ||
284 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) | ||
285 | { | ||
286 | val Map<OutgoingRelation<NodeRepresentation>,Integer> res= new HashMap | ||
287 | for(outgoingConcreteEdge : OutgoingRelations.get(object)) { | ||
288 | val OutgoingRelation<NodeRepresentation> e = | ||
289 | new OutgoingRelation( | ||
290 | previousNodeRepresentations.get(outgoingConcreteEdge.to), | ||
291 | outgoingConcreteEdge.type) | ||
292 | if(res.containsKey(e)) { | ||
293 | res.put(e,addOne(res.get(e),parallel)) | ||
294 | } else { | ||
295 | res.put(e,1) | ||
296 | } | ||
297 | } | ||
298 | return res; | ||
299 | } | ||
300 | |||
301 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { | ||
302 | var Set<VALUE> s; | ||
303 | if(map.containsKey(key)) { | ||
304 | s = map.get(key); | ||
305 | } else { | ||
306 | s = new HashSet | ||
307 | map.put(key,s) | ||
308 | } | ||
309 | s.add(value) | ||
310 | }*/ | ||
311 | |||
312 | |||
313 | private def calculateFurtherNodeDescriptors( | ||
314 | PartialInterpretation model, | ||
315 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, | ||
316 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | ||
317 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | ||
318 | int parallels, int maxNumber) | ||
319 | { | ||
320 | val previousNodeRepresentations = previous.nodeRepresentations | ||
321 | val node2Representation = new HashMap<DefinedElement,FurtherNodeDescriptor<NodeRepresentation>> | ||
322 | val Map<FurtherNodeDescriptor<NodeRepresentation>,Integer> descriptor2Number = | ||
323 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | ||
324 | val Map<FurtherNodeDescriptor<NodeRepresentation>,FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = | ||
325 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | ||
326 | |||
327 | for(object: model.elements) { | ||
328 | val incomingEdges = this.calculateIncomingEdges(IncomingRelations, object, previousNodeRepresentations,parallels) | ||
329 | val outgoingEdges = this.calcuateOutgoingEdges(OutgoingRelations,object, previousNodeRepresentations,parallels) | ||
330 | |||
331 | val previousType = previousNodeRepresentations.get(object) | ||
332 | |||
333 | if(previousType === null) { | ||
334 | println("Error in state coder") | ||
335 | } | ||
336 | |||
337 | val nodeDescriptor = new FurtherNodeDescriptor( | ||
338 | previousType, | ||
339 | incomingEdges, | ||
340 | outgoingEdges) | ||
341 | |||
342 | if(this.mergeSimilarNeighbourhood) { | ||
343 | if(descriptor2Number.containsKey(nodeDescriptor)) { | ||
344 | descriptor2Number.put( | ||
345 | nodeDescriptor, | ||
346 | addOne(descriptor2Number.get(nodeDescriptor),maxNumber) | ||
347 | ) | ||
348 | node2Representation.put(object,uniqueDescription.get(nodeDescriptor)) | ||
349 | } else { | ||
350 | descriptor2Number.put(nodeDescriptor,if(1>maxNumber){Integer.MAX_VALUE}else{1}) | ||
351 | uniqueDescription.put(nodeDescriptor,nodeDescriptor) | ||
352 | node2Representation.put(object,nodeDescriptor) | ||
353 | } | 351 | } |
354 | } else { | 352 | |
355 | node2Representation.put(object,nodeDescriptor) | 353 | private def calculateIncomingEdges( |
356 | } | 354 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
357 | } | 355 | DefinedElement object, |
358 | 356 | Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) { | |
359 | return descriptor2Number -> node2Representation | 357 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = new HashMap |
360 | } | 358 | for (incomingConcreteEdge : IncomingRelations.get(object)) { |
361 | 359 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( | |
362 | private def calculateLocalNodeDescriptors( | 360 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) |
363 | PartialInterpretation model, | 361 | if (res.containsKey(e)) { |
364 | Map<DefinedElement, Set<String>> types, | 362 | res.put(e, addOne(res.get(e), parallel)) |
365 | int maxNumber) | 363 | } else { |
366 | { | 364 | res.put(e, 1) |
367 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = new HashMap | 365 | } |
368 | val Map<LocalNodeDescriptor, Integer> representation2Amount = | 366 | } |
369 | if(mergeSimilarNeighbourhood){ new HashMap } else { null } | 367 | return res |
370 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = | ||
371 | if(this.mergeSimilarNeighbourhood){ new HashMap } else { null } | ||
372 | |||
373 | for(element : model.elements) { | ||
374 | var newDescriptor = new LocalNodeDescriptor(element.name,element.lookup(types)) | ||
375 | if(this.mergeSimilarNeighbourhood){ | ||
376 | if(uniqueRepresentation.containsKey(newDescriptor)) { | ||
377 | newDescriptor = newDescriptor.lookup(uniqueRepresentation) | ||
378 | node2Representation.put(element,newDescriptor) | ||
379 | representation2Amount.put( | ||
380 | newDescriptor, | ||
381 | addOne(newDescriptor.lookup(representation2Amount),maxNumber) | ||
382 | ) | ||
383 | } else { | ||
384 | uniqueRepresentation.put(newDescriptor,newDescriptor) | ||
385 | node2Representation.put(element,newDescriptor) | ||
386 | representation2Amount.put(newDescriptor, if(1>maxNumber){Integer.MAX_VALUE}else{1}) | ||
387 | } | 368 | } |
388 | } else { | 369 | |
389 | node2Representation.put(element,newDescriptor) | 370 | private def calcuateOutgoingEdges( |
390 | } | 371 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
391 | } | 372 | DefinedElement object, |
392 | 373 | Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, int parallel) { | |
393 | return representation2Amount -> node2Representation | 374 | val Map<OutgoingRelation<NodeRepresentation>, Integer> res = new HashMap |
394 | } | 375 | for (outgoingConcreteEdge : OutgoingRelations.get(object)) { |
395 | } \ No newline at end of file | 376 | val OutgoingRelation<NodeRepresentation> e = new OutgoingRelation( |
377 | previousNodeRepresentations.get(outgoingConcreteEdge.to), outgoingConcreteEdge.type) | ||
378 | if (res.containsKey(e)) { | ||
379 | res.put(e, addOne(res.get(e), parallel)) | ||
380 | } else { | ||
381 | res.put(e, 1) | ||
382 | } | ||
383 | } | ||
384 | return res; | ||
385 | } | ||
386 | |||
387 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { | ||
388 | * var Set<VALUE> s; | ||
389 | * if(map.containsKey(key)) { | ||
390 | * s = map.get(key); | ||
391 | * } else { | ||
392 | * s = new HashSet | ||
393 | * map.put(key,s) | ||
394 | * } | ||
395 | * s.add(value) | ||
396 | }*/ | ||
397 | private def calculateFurtherNodeDescriptors(PartialInterpretation model, | ||
398 | NeighbourhoodWithTraces<ModelRepresentation, NodeRepresentation> previous, | ||
399 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | ||
400 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, | ||
401 | int maxNumber) { | ||
402 | val previousNodeRepresentations = previous.nodeRepresentations | ||
403 | val node2Representation = new HashMap<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> | ||
404 | val Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> descriptor2Number = if (this. | ||
405 | mergeSimilarNeighbourhood) { | ||
406 | new HashMap | ||
407 | } else { | ||
408 | null | ||
409 | } | ||
410 | val Map<FurtherNodeDescriptor<NodeRepresentation>, FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = if (this. | ||
411 | mergeSimilarNeighbourhood) { | ||
412 | new HashMap | ||
413 | } else { | ||
414 | null | ||
415 | } | ||
416 | |||
417 | for (object : model.elements) { | ||
418 | val incomingEdges = this.calculateIncomingEdges(IncomingRelations, object, | ||
419 | previousNodeRepresentations, parallels) | ||
420 | val outgoingEdges = this.calcuateOutgoingEdges(OutgoingRelations, object, | ||
421 | previousNodeRepresentations, parallels) | ||
422 | // TODO: patternDescriptors | ||
423 | val previousType = previousNodeRepresentations.get(object) | ||
424 | |||
425 | if (previousType === null) { | ||
426 | println("Error in state coder") | ||
427 | } | ||
428 | |||
429 | val nodeDescriptor = new FurtherNodeDescriptor(previousType, incomingEdges, outgoingEdges) | ||
430 | |||
431 | if (this.mergeSimilarNeighbourhood) { | ||
432 | if (descriptor2Number.containsKey(nodeDescriptor)) { | ||
433 | descriptor2Number.put( | ||
434 | nodeDescriptor, | ||
435 | addOne(descriptor2Number.get(nodeDescriptor), maxNumber) | ||
436 | ) | ||
437 | node2Representation.put(object, uniqueDescription.get(nodeDescriptor)) | ||
438 | } else { | ||
439 | descriptor2Number.put(nodeDescriptor, if (1 > maxNumber) { | ||
440 | Integer.MAX_VALUE | ||
441 | } else { | ||
442 | 1 | ||
443 | }) | ||
444 | uniqueDescription.put(nodeDescriptor, nodeDescriptor) | ||
445 | node2Representation.put(object, nodeDescriptor) | ||
446 | } | ||
447 | } else { | ||
448 | node2Representation.put(object, nodeDescriptor) | ||
449 | } | ||
450 | } | ||
451 | |||
452 | return descriptor2Number -> node2Representation | ||
453 | } | ||
454 | |||
455 | private def calculateLocalNodeDescriptors(PartialInterpretation model, | ||
456 | Map<DefinedElement, Set<String>> types, int maxNumber) { | ||
457 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = new HashMap | ||
458 | val Map<LocalNodeDescriptor, Integer> representation2Amount = if (mergeSimilarNeighbourhood) { | ||
459 | new HashMap | ||
460 | } else { | ||
461 | null | ||
462 | } | ||
463 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = if (this. | ||
464 | mergeSimilarNeighbourhood) { | ||
465 | new HashMap | ||
466 | } else { | ||
467 | null | ||
468 | } | ||
469 | |||
470 | for (element : model.elements) { | ||
471 | var newDescriptor = new LocalNodeDescriptor(element.name, element.lookup(types)) | ||
472 | if (this.mergeSimilarNeighbourhood) { | ||
473 | if (uniqueRepresentation.containsKey(newDescriptor)) { | ||
474 | newDescriptor = newDescriptor.lookup(uniqueRepresentation) | ||
475 | node2Representation.put(element, newDescriptor) | ||
476 | representation2Amount.put( | ||
477 | newDescriptor, | ||
478 | addOne(newDescriptor.lookup(representation2Amount), maxNumber) | ||
479 | ) | ||
480 | } else { | ||
481 | uniqueRepresentation.put(newDescriptor, newDescriptor) | ||
482 | node2Representation.put(element, newDescriptor) | ||
483 | representation2Amount.put(newDescriptor, if (1 > maxNumber) { | ||
484 | Integer.MAX_VALUE | ||
485 | } else { | ||
486 | 1 | ||
487 | }) | ||
488 | } | ||
489 | } else { | ||
490 | node2Representation.put(element, newDescriptor) | ||
491 | } | ||
492 | } | ||
493 | |||
494 | return representation2Amount -> node2Representation | ||
495 | } | ||
496 | } | ||
497 | \ No newline at end of file | ||
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 65a8207e..33a62bea 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 | |||
@@ -32,6 +32,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | |||
32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2NeighbourhoodRepresentation | 32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2NeighbourhoodRepresentation |
33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | 33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation |
34 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation | 34 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation |
35 | import java.util.HashSet | ||
35 | 36 | ||
36 | class NeighbourhoodBasedStateCoderFactory implements IStateCoderFactory { | 37 | class NeighbourhoodBasedStateCoderFactory implements IStateCoderFactory { |
37 | val List<NeighbourhoodBasedPartialInterpretationStateCoder> statecoders = new LinkedList | 38 | val List<NeighbourhoodBasedPartialInterpretationStateCoder> statecoders = new LinkedList |
@@ -115,7 +116,7 @@ class NeighbourhoodBasedPartialInterpretationStateCoder implements IStateCoder{ | |||
115 | if(this.nodeRepresentations === null || this.modelRepresentation === null) { | 116 | if(this.nodeRepresentations === null || this.modelRepresentation === null) { |
116 | val startTime = System.nanoTime | 117 | val startTime = System.nanoTime |
117 | //relevantObjects.forEach[println(it)] | 118 | //relevantObjects.forEach[println(it)] |
118 | val code = calculator.createRepresentation(target,range,parallels,maxNumber,relevantTypes,relevantRelations) | 119 | val code = calculator.createRepresentation(target,range,parallels,maxNumber,relevantTypes,relevantRelations, null) |
119 | this.modelRepresentation = code.modelRepresentation | 120 | this.modelRepresentation = code.modelRepresentation |
120 | this.nodeRepresentations = code.nodeRepresentations | 121 | this.nodeRepresentations = code.nodeRepresentations |
121 | statecoderRuntime += (System.nanoTime - startTime) | 122 | statecoderRuntime += (System.nanoTime - startTime) |