diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend')
1 files changed, 28 insertions, 78 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 | */ | ||