diff options
author | 2020-07-14 10:45:03 +0200 | |
---|---|---|
committer | 2020-07-14 10:45:03 +0200 | |
commit | 329ac27dfa84e9a07760bea75b36476dddcf29a7 (patch) | |
tree | 67ffc01b3ff1da6b196e5a9e52eac0d5c22b5ddb /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf | |
parent | Fix event storm on EMF transaction finish (diff) | |
download | VIATRA-Generator-329ac27dfa84e9a07760bea75b36476dddcf29a7.tar.gz VIATRA-Generator-329ac27dfa84e9a07760bea75b36476dddcf29a7.tar.zst VIATRA-Generator-329ac27dfa84e9a07760bea75b36476dddcf29a7.zip |
Optimizations
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf')
4 files changed, 86 insertions, 118 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 e4bdb086..685a1f5a 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 | |||
@@ -7,7 +7,7 @@ import org.eclipse.xtend.lib.annotations.Data | |||
7 | import org.eclipse.xtend2.lib.StringConcatenationClient | 7 | import org.eclipse.xtend2.lib.StringConcatenationClient |
8 | 8 | ||
9 | @Data abstract class AbstractNodeDescriptor { | 9 | @Data abstract class AbstractNodeDescriptor { |
10 | long dataHash | 10 | int dataHash |
11 | 11 | ||
12 | protected def StringConcatenationClient prettyPrint() { | 12 | protected def StringConcatenationClient prettyPrint() { |
13 | '''(«dataHash»)[«class.simpleName»]''' | 13 | '''(«dataHash»)[«class.simpleName»]''' |
@@ -57,7 +57,7 @@ import org.eclipse.xtend2.lib.StringConcatenationClient | |||
57 | } | 57 | } |
58 | 58 | ||
59 | override hashCode() { | 59 | override hashCode() { |
60 | return this.dataHash.hashCode | 60 | return this.dataHash |
61 | } | 61 | } |
62 | 62 | ||
63 | override equals(Object other) { | 63 | override equals(Object other) { |
@@ -119,7 +119,6 @@ import org.eclipse.xtend2.lib.StringConcatenationClient | |||
119 | } | 119 | } |
120 | 120 | ||
121 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor { | 121 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor { |
122 | |||
123 | NodeRep previousRepresentation | 122 | NodeRep previousRepresentation |
124 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges | 123 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges |
125 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges | 124 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges |
@@ -128,8 +127,8 @@ import org.eclipse.xtend2.lib.StringConcatenationClient | |||
128 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { | 127 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { |
129 | super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges)) | 128 | super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges)) |
130 | this.previousRepresentation = previousRepresentation | 129 | this.previousRepresentation = previousRepresentation |
131 | this.incomingEdges = new HashMap(incomingEdges) | 130 | this.incomingEdges = incomingEdges |
132 | this.outgoingEdges = new HashMap(outgoingEdges) | 131 | this.outgoingEdges = outgoingEdges |
133 | } | 132 | } |
134 | 133 | ||
135 | static def private <NodeRep> int calculateDataHash(NodeRep previousRepresentation, | 134 | static def private <NodeRep> int calculateDataHash(NodeRep previousRepresentation, |
@@ -137,14 +136,14 @@ import org.eclipse.xtend2.lib.StringConcatenationClient | |||
137 | val int prime = 31; | 136 | val int prime = 31; |
138 | var int result = previousRepresentation.hashCode; | 137 | var int result = previousRepresentation.hashCode; |
139 | if (incomingEdges !== null) | 138 | if (incomingEdges !== null) |
140 | result = prime * result + incomingEdges.hashCode(); | 139 | result = prime * result + hashIncomingNeighborhood(incomingEdges) |
141 | if (outgoingEdges !== null) | 140 | if (outgoingEdges !== null) |
142 | result = prime * result + outgoingEdges.hashCode(); | 141 | result = prime * result + hashOutgoingNeighborhood(outgoingEdges) |
143 | return result; | 142 | return result; |
144 | } | 143 | } |
145 | 144 | ||
146 | override hashCode() { | 145 | override hashCode() { |
147 | return this.dataHash.hashCode | 146 | return this.dataHash |
148 | } | 147 | } |
149 | 148 | ||
150 | override equals(Object other) { | 149 | override equals(Object other) { |
@@ -179,80 +178,31 @@ import org.eclipse.xtend2.lib.StringConcatenationClient | |||
179 | '''«rep»''' | 178 | '''«rep»''' |
180 | } | 179 | } |
181 | } | 180 | } |
181 | |||
182 | private static def <NodeRep> hashIncomingNeighborhood(Map<IncomingRelation<NodeRep>, Integer> neighborhood) { | ||
183 | val int prime = 31 | ||
184 | var int hash = 0 | ||
185 | for (entry : neighborhood.entrySet) { | ||
186 | val relation = entry.key | ||
187 | hash += (prime * relation.from.hashCode + relation.type.hashCode).bitwiseXor(entry.value.hashCode) | ||
188 | } | ||
189 | hash | ||
190 | } | ||
191 | |||
192 | private static def <NodeRep> hashOutgoingNeighborhood(Map<OutgoingRelation<NodeRep>, Integer> neighborhood) { | ||
193 | val int prime = 31 | ||
194 | var int hash = 0 | ||
195 | for (entry : neighborhood.entrySet) { | ||
196 | val relation = entry.key | ||
197 | hash += (prime * relation.to.hashCode + relation.type.hashCode).bitwiseXor(entry.value.hashCode) | ||
198 | } | ||
199 | hash | ||
200 | } | ||
182 | 201 | ||
183 | override toString() { | 202 | override toString() { |
184 | ''' | 203 | ''' |
185 | «prettyPrint» | 204 | «prettyPrint» |
186 | ''' | 205 | ''' |
187 | } | 206 | } |
188 | |||
189 | // @Pure | ||
190 | // @Override | ||
191 | // override public boolean equals(Object obj) { | ||
192 | // if (this === obj) | ||
193 | // return true; | ||
194 | // if (obj === null) | ||
195 | // return false; | ||
196 | // if (getClass() != obj.getClass()) | ||
197 | // return false; | ||
198 | // val AbstractNodeDescriptor other = obj as AbstractNodeDescriptor; | ||
199 | // if (other.dataHash != this.dataHash) | ||
200 | // return false; | ||
201 | // return true; | ||
202 | // } | ||
203 | // @Pure | ||
204 | // override public boolean equals(Object obj) { | ||
205 | // if (this === obj) | ||
206 | // return true; | ||
207 | // if (obj === null) | ||
208 | // return false; | ||
209 | // if (getClass() != obj.getClass()) | ||
210 | // return false; | ||
211 | // if (!super.equals(obj)) | ||
212 | // return false; | ||
213 | // val FurtherNodeDescriptor<?> other = obj as FurtherNodeDescriptor<?>; | ||
214 | // if (this.previousRepresentation === null) { | ||
215 | // if (other.previousRepresentation != null) | ||
216 | // return false; | ||
217 | // | ||
218 | // } | ||
219 | //// } else if (!this.previousRepresentation.equals(other.previousRepresentation)) | ||
220 | //// return false; | ||
221 | // if (this.incomingEdges === null) { | ||
222 | // if (other.incomingEdges != null) | ||
223 | // return false; | ||
224 | // } else if (!this.incomingEdges.equals(other.incomingEdges)) | ||
225 | // return false; | ||
226 | // if (this.outgoingEdges === null) { | ||
227 | // if (other.outgoingEdges != null) | ||
228 | // return false; | ||
229 | // } else if (!this.outgoingEdges.equals(other.outgoingEdges)) | ||
230 | // return false; | ||
231 | // if (this.attributeValues === null) { | ||
232 | // if (other.attributeValues != null) | ||
233 | // return false; | ||
234 | // } else if (!this.attributeValues.equals(other.attributeValues)) | ||
235 | // return false; | ||
236 | // return true; | ||
237 | // } | ||
238 | } | 207 | } |
239 | /* | 208 | |
240 | * @Data | ||
241 | * class ModelDescriptor { | ||
242 | * int dataHash | ||
243 | * int unknownElements | ||
244 | * Map<? extends AbstractNodeDescriptor,Integer> knownElements | ||
245 | * | ||
246 | * public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) { | ||
247 | * this.dataHash = calculateDataHash(knownElements,unknownElements) | ||
248 | * this.unknownElements = unknownElements | ||
249 | * this.knownElements = knownElements | ||
250 | * } | ||
251 | * | ||
252 | * def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) | ||
253 | * { | ||
254 | * val int prime = 31; | ||
255 | * return knownElements.hashCode * prime + unknownElements.hashCode | ||
256 | * } | ||
257 | * } | ||
258 | */ | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend index ddf7d712..5da202eb 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/PartialInterpretation2Hash.xtend | |||
@@ -1,7 +1,8 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood |
2 | 2 | ||
3 | import java.util.Map | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | 3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement |
4 | import java.util.Map | ||
5 | import org.eclipse.collections.api.factory.Maps | ||
5 | 6 | ||
6 | class PartialInterpretation2Hash extends PartialInterpretation2NeighbourhoodRepresentation<Integer, Integer>{ | 7 | class PartialInterpretation2Hash extends PartialInterpretation2NeighbourhoodRepresentation<Integer, Integer>{ |
7 | 8 | ||
@@ -11,15 +12,22 @@ class PartialInterpretation2Hash extends PartialInterpretation2NeighbourhoodRepr | |||
11 | 12 | ||
12 | override protected createLocalRepresentation(Map<DefinedElement, LocalNodeDescriptor> node2Representation, Map<LocalNodeDescriptor, Integer> representation2Amount) { | 13 | override protected createLocalRepresentation(Map<DefinedElement, LocalNodeDescriptor> node2Representation, Map<LocalNodeDescriptor, Integer> representation2Amount) { |
13 | return new NeighbourhoodWithTraces( | 14 | return new NeighbourhoodWithTraces( |
14 | representation2Amount.hashCode,node2Representation.mapValues[it.hashCode], | 15 | representation2Amount.hashCode,node2Representation.hashValues, |
15 | null) | 16 | null) |
16 | } | 17 | } |
17 | 18 | ||
18 | override protected createFurtherRepresentation(Map<FurtherNodeDescriptor<Integer>, Integer> nodeDescriptors, Map<DefinedElement, FurtherNodeDescriptor<Integer>> node2Representation, NeighbourhoodWithTraces<Integer, Integer> previous, boolean deepRepresentation) { | 19 | override protected createFurtherRepresentation(Map<FurtherNodeDescriptor<Integer>, Integer> nodeDescriptors, Map<DefinedElement, FurtherNodeDescriptor<Integer>> node2Representation, NeighbourhoodWithTraces<Integer, Integer> previous, boolean deepRepresentation) { |
19 | return new NeighbourhoodWithTraces( | 20 | return new NeighbourhoodWithTraces( |
20 | nodeDescriptors.hashCode, | 21 | nodeDescriptors.hashCode, |
21 | node2Representation.mapValues[it.hashCode], | 22 | node2Representation.hashValues, |
22 | if(deepRepresentation) {previous} else {null}) | 23 | if(deepRepresentation) {previous} else {null}) |
23 | } | 24 | } |
24 | 25 | ||
26 | private def <T> hashValues(Map<DefinedElement, T> map) { | ||
27 | val hashedMap = Maps.mutable.ofInitialCapacity(map.size) | ||
28 | for (entry : map.entrySet) { | ||
29 | hashedMap.put(entry.key, entry.value.hashCode) | ||
30 | } | ||
31 | hashedMap | ||
32 | } | ||
25 | } | 33 | } |
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 3048167e..93eab816 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 | |||
@@ -8,11 +8,11 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
8 | 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 | 9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialPrimitiveInterpretation |
10 | import java.util.ArrayList | 10 | import java.util.ArrayList |
11 | import java.util.HashMap | ||
12 | import java.util.HashSet | ||
13 | import java.util.List | 11 | import java.util.List |
14 | import java.util.Map | 12 | import java.util.Map |
15 | import java.util.Set | 13 | import java.util.Set |
14 | import org.eclipse.collections.api.factory.Maps | ||
15 | import org.eclipse.collections.impl.factory.Sets | ||
16 | 16 | ||
17 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 17 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
18 | 18 | ||
@@ -68,10 +68,11 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
68 | 68 | ||
69 | def createRepresentationWithFocus(PartialInterpretation model, int range, int parallels, int maxNumber, | 69 | def createRepresentationWithFocus(PartialInterpretation model, int range, int parallels, int maxNumber, |
70 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations, DefinedElement focusedElement) { | 70 | Set<TypeDeclaration> relevantTypes, Set<RelationDeclaration> relevantRelations, DefinedElement focusedElement) { |
71 | val Map<DefinedElement, Set<String>> types = new HashMap | 71 | val initialSize = model.elements.size |
72 | val Map<DefinedElement, Set<String>> types = Maps.mutable.ofInitialCapacity(initialSize) | ||
72 | fillTypes(model, types, relevantTypes) | 73 | fillTypes(model, types, relevantTypes) |
73 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = new HashMap; | 74 | val Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations = Maps.mutable.ofInitialCapacity(initialSize); |
74 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = new HashMap; | 75 | val Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations = Maps.mutable.ofInitialCapacity(initialSize); |
75 | fillReferences(model, IncomingRelations, OutgoingRelations, relevantRelations) | 76 | fillReferences(model, IncomingRelations, OutgoingRelations, relevantRelations) |
76 | 77 | ||
77 | val res = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, range, parallels, | 78 | val res = doRecursiveNeighbourCalculation(model, types, IncomingRelations, OutgoingRelations, range, parallels, |
@@ -103,12 +104,12 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
103 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 104 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
104 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) { | 105 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations) { |
105 | val elements = types.keySet | 106 | val elements = types.keySet |
106 | var Map<DefinedElement, Set<DefinedElement>> reachable = new HashMap | 107 | var Map<DefinedElement, Set<DefinedElement>> reachable = Maps.mutable.ofInitialCapacity(elements.size) |
107 | var Map<DefinedElement, Set<DefinedElement>> newReachable = new HashMap | 108 | var Map<DefinedElement, Set<DefinedElement>> newReachable = Maps.mutable.ofInitialCapacity(elements.size) |
108 | for (element : elements) { | 109 | for (element : elements) { |
109 | val set = new HashSet | 110 | val set = Sets.mutable.of |
110 | set.add(element) | 111 | set.add(element) |
111 | reachable.put(element, new HashSet) | 112 | reachable.put(element, Sets.mutable.of) |
112 | newReachable.put(element, set) | 113 | newReachable.put(element, set) |
113 | } | 114 | } |
114 | 115 | ||
@@ -201,8 +202,8 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
201 | val nextRepresentation = createFurtherRepresentation(next.key, next.value, lastRepresentation, | 202 | val nextRepresentation = createFurtherRepresentation(next.key, next.value, lastRepresentation, |
202 | deepRepresentation) | 203 | deepRepresentation) |
203 | 204 | ||
204 | val previousNumberOfTypes = lastRepresentation.nodeRepresentations.values.toSet.size | 205 | val previousNumberOfTypes = Sets.immutable.withAll(lastRepresentation.nodeRepresentations.values).size |
205 | val nextNumberOfTypes = nextRepresentation.nodeRepresentations.values.toSet.size | 206 | val nextNumberOfTypes = Sets.immutable.withAll(nextRepresentation.nodeRepresentations.values).size |
206 | hasRefined = nextNumberOfTypes > previousNumberOfTypes | 207 | hasRefined = nextNumberOfTypes > previousNumberOfTypes |
207 | 208 | ||
208 | lastRange = nextRange | 209 | lastRange = nextRange |
@@ -224,7 +225,7 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
224 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, | 225 | def private fillTypes(PartialInterpretation model, Map<DefinedElement, Set<String>> node2Type, |
225 | Set<TypeDeclaration> relevantTypes) { | 226 | Set<TypeDeclaration> relevantTypes) { |
226 | for (element : model.elements) { | 227 | for (element : model.elements) { |
227 | node2Type.put(element, new HashSet) | 228 | node2Type.put(element, Sets.mutable.of) |
228 | } | 229 | } |
229 | 230 | ||
230 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { | 231 | // for(typeDefinition : model.problem.types.filter(TypeDefinition)) { |
@@ -286,7 +287,11 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
286 | boolean deepRepresentation | 287 | boolean deepRepresentation |
287 | ) | 288 | ) |
288 | 289 | ||
289 | def private addOne(int original, int max) { | 290 | def private addOne(Integer originalObj, int max) { |
291 | if (originalObj === null) { | ||
292 | return 1 | ||
293 | } | ||
294 | val original = originalObj.intValue | ||
290 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE | 295 | if(original == Integer.MAX_VALUE) return Integer.MAX_VALUE |
291 | if(original + 1 > max) return Integer.MAX_VALUE else return original + 1 | 296 | if(original + 1 > max) return Integer.MAX_VALUE else return original + 1 |
292 | } | 297 | } |
@@ -294,15 +299,11 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
294 | private def calculateIncomingEdges(Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 299 | private def calculateIncomingEdges(Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
295 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, | 300 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, |
296 | int parallel) { | 301 | int parallel) { |
297 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = new HashMap | 302 | val Map<IncomingRelation<NodeRepresentation>, Integer> res = Maps.mutable.of |
298 | for (incomingConcreteEdge : IncomingRelations.get(object)) { | 303 | for (incomingConcreteEdge : IncomingRelations.get(object)) { |
299 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( | 304 | val IncomingRelation<NodeRepresentation> e = new IncomingRelation( |
300 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) | 305 | previousNodeRepresentations.get(incomingConcreteEdge.from), incomingConcreteEdge.type) |
301 | if (res.containsKey(e)) { | 306 | res.compute(e, [key, value | addOne(value, parallel)]) |
302 | res.put(e, addOne(res.get(e), parallel)) | ||
303 | } else { | ||
304 | res.put(e, 1) | ||
305 | } | ||
306 | } | 307 | } |
307 | return res | 308 | return res |
308 | } | 309 | } |
@@ -310,17 +311,13 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
310 | private def calcuateOutgoingEdges(Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, | 311 | private def calcuateOutgoingEdges(Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, |
311 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, | 312 | DefinedElement object, Map<DefinedElement, ? extends NodeRepresentation> previousNodeRepresentations, |
312 | int parallel) { | 313 | int parallel) { |
313 | val Map<OutgoingRelation<NodeRepresentation>, Integer> res = new HashMap | 314 | val Map<OutgoingRelation<NodeRepresentation>, Integer> res = Maps.mutable.of |
314 | for (outgoingConcreteEdge : OutgoingRelations.get(object)) { | 315 | for (outgoingConcreteEdge : OutgoingRelations.get(object)) { |
315 | val OutgoingRelation<NodeRepresentation> e = new OutgoingRelation( | 316 | val OutgoingRelation<NodeRepresentation> e = new OutgoingRelation( |
316 | previousNodeRepresentations.get(outgoingConcreteEdge.to), outgoingConcreteEdge.type) | 317 | previousNodeRepresentations.get(outgoingConcreteEdge.to), outgoingConcreteEdge.type) |
317 | if (res.containsKey(e)) { | 318 | res.compute(e, [key, value | addOne(value, parallel)]) |
318 | res.put(e, addOne(res.get(e), parallel)) | ||
319 | } else { | ||
320 | res.put(e, 1) | ||
321 | } | ||
322 | } | 319 | } |
323 | return res; | 320 | return res |
324 | } | 321 | } |
325 | 322 | ||
326 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { | 323 | /*def private <KEY,VALUE> void addOrCreate_Set(Map<KEY,Set<VALUE>> map, KEY key, VALUE value) { |
@@ -338,16 +335,17 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
338 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, | 335 | Map<DefinedElement, List<IncomingRelation<DefinedElement>>> IncomingRelations, |
339 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, int maxNumber) { | 336 | Map<DefinedElement, List<OutgoingRelation<DefinedElement>>> OutgoingRelations, int parallels, int maxNumber) { |
340 | val previousNodeRepresentations = previous.nodeRepresentations | 337 | val previousNodeRepresentations = previous.nodeRepresentations |
341 | val node2Representation = new HashMap<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>> | 338 | val size = previousNodeRepresentations.size |
339 | val node2Representation = Maps.mutable.<DefinedElement, FurtherNodeDescriptor<NodeRepresentation>>ofInitialCapacity(size) | ||
342 | val Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> descriptor2Number = if (this. | 340 | val Map<FurtherNodeDescriptor<NodeRepresentation>, Integer> descriptor2Number = if (this. |
343 | mergeSimilarNeighbourhood) { | 341 | mergeSimilarNeighbourhood) { |
344 | new HashMap | 342 | Maps.mutable.ofInitialCapacity(size) |
345 | } else { | 343 | } else { |
346 | null | 344 | null |
347 | } | 345 | } |
348 | val Map<FurtherNodeDescriptor<NodeRepresentation>, FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = if (this. | 346 | val Map<FurtherNodeDescriptor<NodeRepresentation>, FurtherNodeDescriptor<NodeRepresentation>> uniqueDescription = if (this. |
349 | mergeSimilarNeighbourhood) { | 347 | mergeSimilarNeighbourhood) { |
350 | new HashMap | 348 | Maps.mutable.ofInitialCapacity(size) |
351 | } else { | 349 | } else { |
352 | null | 350 | null |
353 | } | 351 | } |
@@ -392,14 +390,15 @@ abstract class PartialInterpretation2NeighbourhoodRepresentation<ModelRepresenta | |||
392 | 390 | ||
393 | private def calculateLocalNodeDescriptors(PartialInterpretation model, Map<DefinedElement, Set<String>> types, | 391 | private def calculateLocalNodeDescriptors(PartialInterpretation model, Map<DefinedElement, Set<String>> types, |
394 | int maxNumber, DefinedElement focusedElement) { | 392 | int maxNumber, DefinedElement focusedElement) { |
395 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = new HashMap | 393 | val size = types.size |
394 | val Map<DefinedElement, LocalNodeDescriptor> node2Representation = Maps.mutable.ofInitialCapacity(size) | ||
396 | val Map<LocalNodeDescriptor, Integer> representation2Amount = if (mergeSimilarNeighbourhood) { | 395 | val Map<LocalNodeDescriptor, Integer> representation2Amount = if (mergeSimilarNeighbourhood) { |
397 | new HashMap | 396 | Maps.mutable.ofInitialCapacity(size) |
398 | } else { | 397 | } else { |
399 | null | 398 | null |
400 | } | 399 | } |
401 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = if (this.mergeSimilarNeighbourhood) { | 400 | val Map<LocalNodeDescriptor, LocalNodeDescriptor> uniqueRepresentation = if (this.mergeSimilarNeighbourhood) { |
402 | new HashMap | 401 | Maps.mutable.ofInitialCapacity(size) |
403 | } else { | 402 | } else { |
404 | null | 403 | null |
405 | } | 404 | } |
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 f19ac30f..04c49506 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 | |||
@@ -9,6 +9,7 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
9 | import java.util.ArrayList | 9 | import java.util.ArrayList |
10 | import java.util.Map | 10 | import java.util.Map |
11 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | 11 | import org.eclipse.viatra.query.runtime.api.IPatternMatch |
12 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | ||
12 | 13 | ||
13 | class NeighbourhoodBasedStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { | 14 | class NeighbourhoodBasedStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { |
14 | new() { | 15 | new() { |
@@ -38,6 +39,7 @@ class NeighbourhoodBasedHashStateCoderFactory extends AbstractNeighbourhoodBased | |||
38 | 39 | ||
39 | class NeighbourhoodBasedPartialInterpretationStateCoder<ModelRep, NodeRep> extends AbstractNeighbourhoodBasedPartialInterpretationStateCoder { | 40 | class NeighbourhoodBasedPartialInterpretationStateCoder<ModelRep, NodeRep> extends AbstractNeighbourhoodBasedPartialInterpretationStateCoder { |
40 | val PartialInterpretation2NeighbourhoodRepresentation<ModelRep, NodeRep> calculator | 41 | val PartialInterpretation2NeighbourhoodRepresentation<ModelRep, NodeRep> calculator |
42 | val Map<IQuerySpecification<?>, String> fullyQualifiedNames = newHashMap | ||
41 | var Map<DefinedElement, ? extends NodeRep> nodeRepresentations = null | 43 | var Map<DefinedElement, ? extends NodeRep> nodeRepresentations = null |
42 | var ModelRep modelRepresentation = null | 44 | var ModelRep modelRepresentation = null |
43 | 45 | ||
@@ -55,27 +57,36 @@ class NeighbourhoodBasedPartialInterpretationStateCoder<ModelRep, NodeRep> exten | |||
55 | modelRepresentation = code.modelRepresentation | 57 | modelRepresentation = code.modelRepresentation |
56 | nodeRepresentations = code.nodeRepresentations | 58 | nodeRepresentations = code.nodeRepresentations |
57 | } | 59 | } |
60 | |||
61 | private def getFullyQualifiedNameCached(IQuerySpecification<?> specification) { | ||
62 | fullyQualifiedNames.computeIfAbsent(specification, [fullyQualifiedName]) | ||
63 | } | ||
58 | 64 | ||
59 | override doCreateActivationCode(IPatternMatch match) { | 65 | override doCreateActivationCode(IPatternMatch match) { |
60 | val size = match.specification.parameters.size | 66 | val size = match.specification.parameters.size |
61 | val res = new ArrayList(size) | 67 | var int hash = 0 |
62 | var int equivalenceHash = 0 | ||
63 | val prime = 31 | 68 | val prime = 31 |
64 | 69 | ||
65 | for (var int index = 0; index < size; index++) { | 70 | for (var int index = 0; index < size; index++) { |
66 | val matchArgument = match.get(index) | 71 | val matchArgument = match.get(index) |
67 | res.add(getCode(matchArgument)) | 72 | val code = getCode(matchArgument) |
73 | val codeNumber = if (code === null) { | ||
74 | 0 | ||
75 | } else { | ||
76 | code.hashCode | ||
77 | } | ||
78 | hash = prime * hash + codeNumber | ||
68 | for (var i = 0; i < index; i++) { | 79 | for (var i = 0; i < index; i++) { |
69 | val number = if (matchArgument === match.get(i)) { | 80 | val number = if (matchArgument === match.get(i)) { |
70 | 1 | 81 | 1 |
71 | } else { | 82 | } else { |
72 | 0 | 83 | 0 |
73 | } | 84 | } |
74 | equivalenceHash = prime * equivalenceHash + number | 85 | hash = prime * hash + number |
75 | } | 86 | } |
76 | } | 87 | } |
77 | 88 | ||
78 | match.specification.fullyQualifiedName -> (res -> equivalenceHash).hashCode | 89 | match.specification.fullyQualifiedNameCached -> hash |
79 | } | 90 | } |
80 | 91 | ||
81 | def private getCode(Object o) { | 92 | def private getCode(Object o) { |