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, 120 insertions, 76 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..e4bdb086 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,10 +4,21 @@ 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 org.eclipse.xtend2.lib.StringConcatenationClient | ||
7 | 8 | ||
8 | @Data abstract class AbstractNodeDescriptor { | 9 | @Data abstract class AbstractNodeDescriptor { |
9 | long dataHash | 10 | long dataHash |
10 | 11 | ||
12 | protected def StringConcatenationClient prettyPrint() { | ||
13 | '''(«dataHash»)[«class.simpleName»]''' | ||
14 | } | ||
15 | |||
16 | override toString() { | ||
17 | ''' | ||
18 | «prettyPrint» | ||
19 | ''' | ||
20 | } | ||
21 | |||
11 | // @Pure | 22 | // @Pure |
12 | // @Override | 23 | // @Override |
13 | // override public boolean equals(Object obj) { | 24 | // override public boolean equals(Object obj) { |
@@ -24,34 +35,45 @@ import org.eclipse.xtend.lib.annotations.Data | |||
24 | // } | 35 | // } |
25 | } | 36 | } |
26 | 37 | ||
27 | @Data class LocalNodeDescriptor extends AbstractNodeDescriptor{ | 38 | @Data class LocalNodeDescriptor extends AbstractNodeDescriptor { |
28 | Set<String> types | 39 | Set<String> types |
29 | String id; | 40 | String id; |
41 | |||
30 | new(String id, Set<String> types) { | 42 | new(String id, Set<String> types) { |
31 | super(calcualteDataHash(id,types)) | 43 | super(calcualteDataHash(id, types)) |
32 | this.types = types | 44 | this.types = types |
33 | this.id = id | 45 | this.id = id |
34 | } | 46 | } |
35 | 47 | ||
36 | def private static calcualteDataHash(String id, Set<String> types) { | 48 | def private static calcualteDataHash(String id, Set<String> types) { |
37 | val int prime = 31; | 49 | val int prime = 31; |
38 | var result = 0 | 50 | var result = 0 |
39 | if(id !== null) | 51 | if (id !== null) |
40 | result = id.hashCode(); | 52 | result = id.hashCode(); |
41 | if(types !== null) { | 53 | if (types !== null) { |
42 | result = prime * result + types.hashCode | 54 | result = prime * result + types.hashCode |
43 | } | 55 | } |
44 | return result | 56 | return result |
45 | } | 57 | } |
46 | 58 | ||
47 | override hashCode() { | 59 | override hashCode() { |
48 | return this.dataHash.hashCode | 60 | return this.dataHash.hashCode |
49 | } | 61 | } |
50 | 62 | ||
63 | override equals(Object other) { | ||
64 | other.class == LocalNodeDescriptor && (other as AbstractNodeDescriptor).hashCode == hashCode | ||
65 | } | ||
66 | |||
67 | override protected prettyPrint() { | ||
68 | '''(«dataHash»)[«IF id !== null»id = "«id»"«IF types === null || !types.empty», «ENDIF»«ENDIF»«IF types === null»TYPES = null«ELSE»«FOR type : types SEPARATOR ", "»«type»«ENDFOR»«ENDIF»]''' | ||
69 | } | ||
70 | |||
51 | override toString() { | 71 | override toString() { |
52 | return class.name + this.dataHash | 72 | ''' |
73 | «prettyPrint» | ||
74 | ''' | ||
53 | } | 75 | } |
54 | 76 | ||
55 | // @Pure | 77 | // @Pure |
56 | // @Override | 78 | // @Override |
57 | // override public boolean equals(Object obj) { | 79 | // override public boolean equals(Object obj) { |
@@ -66,7 +88,6 @@ import org.eclipse.xtend.lib.annotations.Data | |||
66 | // return false; | 88 | // return false; |
67 | // return true; | 89 | // return true; |
68 | // } | 90 | // } |
69 | |||
70 | // @Pure | 91 | // @Pure |
71 | // override public boolean equals(Object obj) { | 92 | // override public boolean equals(Object obj) { |
72 | // if (this === obj) | 93 | // if (this === obj) |
@@ -97,49 +118,74 @@ import org.eclipse.xtend.lib.annotations.Data | |||
97 | String type | 118 | String type |
98 | } | 119 | } |
99 | 120 | ||
100 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor{ | 121 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor { |
101 | 122 | ||
102 | NodeRep previousRepresentation | 123 | NodeRep previousRepresentation |
103 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges | 124 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges |
104 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges | 125 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges |
105 | 126 | ||
106 | new( | 127 | new(NodeRep previousRepresentation, Map<IncomingRelation<NodeRep>, Integer> incomingEdges, |
107 | NodeRep previousRepresentation, | 128 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { |
108 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges, | 129 | super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges)) |
109 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges) | 130 | this.previousRepresentation = previousRepresentation |
110 | { | 131 | this.incomingEdges = new HashMap(incomingEdges) |
111 | super(calculateDataHash(previousRepresentation,incomingEdges,outgoingEdges)) | 132 | this.outgoingEdges = new HashMap(outgoingEdges) |
112 | this.previousRepresentation = previousRepresentation | ||
113 | this.incomingEdges = new HashMap(incomingEdges) | ||
114 | this.outgoingEdges = new HashMap(outgoingEdges) | ||
115 | } | ||
116 | |||
117 | static def private <NodeRep> int calculateDataHash( | ||
118 | NodeRep previousRepresentation, | ||
119 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges, | ||
120 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges) | ||
121 | { | ||
122 | val int prime = 31; | ||
123 | var int result = previousRepresentation.hashCode; | ||
124 | if(incomingEdges !== null) | ||
125 | result = prime * result + incomingEdges.hashCode(); | ||
126 | if(outgoingEdges !== null) | ||
127 | result = prime * result + outgoingEdges.hashCode(); | ||
128 | return result; | ||
129 | } | ||
130 | |||
131 | override hashCode() { | ||
132 | return this.dataHash.hashCode | ||
133 | } | 133 | } |
134 | 134 | ||
135 | static def private <NodeRep> int calculateDataHash(NodeRep previousRepresentation, | ||
136 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges, Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { | ||
137 | val int prime = 31; | ||
138 | var int result = previousRepresentation.hashCode; | ||
139 | if (incomingEdges !== null) | ||
140 | result = prime * result + incomingEdges.hashCode(); | ||
141 | if (outgoingEdges !== null) | ||
142 | result = prime * result + outgoingEdges.hashCode(); | ||
143 | return result; | ||
144 | } | ||
145 | |||
146 | override hashCode() { | ||
147 | return this.dataHash.hashCode | ||
148 | } | ||
149 | |||
150 | override equals(Object other) { | ||
151 | other.class == FurtherNodeDescriptor && (other as AbstractNodeDescriptor).hashCode == hashCode | ||
152 | } | ||
153 | |||
154 | override prettyPrint() { | ||
155 | ''' | ||
156 | («dataHash»)[ | ||
157 | PREV = «previousRepresentation?.prettyPrint» | ||
158 | «IF incomingEdges === null» | ||
159 | IN null | ||
160 | «ELSE» | ||
161 | «FOR edge : incomingEdges.entrySet» | ||
162 | IN «edge.value» «edge.key.type» = «edge.key.from.prettyPrint» | ||
163 | «ENDFOR» | ||
164 | «ENDIF» | ||
165 | «IF outgoingEdges === null» | ||
166 | OUT null | ||
167 | «ELSE» | ||
168 | «FOR edge : outgoingEdges.entrySet» | ||
169 | OUT «edge.value» «edge.key.type» = «edge.key.to.prettyPrint» | ||
170 | «ENDFOR» | ||
171 | «ENDIF» | ||
172 | ]''' | ||
173 | } | ||
174 | |||
175 | private def StringConcatenationClient prettyPrint(NodeRep rep) { | ||
176 | if (rep instanceof AbstractNodeDescriptor) { | ||
177 | rep.prettyPrint | ||
178 | } else { | ||
179 | '''«rep»''' | ||
180 | } | ||
181 | } | ||
182 | |||
135 | override toString() { | 183 | override toString() { |
136 | return class.name + dataHash | 184 | ''' |
137 | // return '''[«previousRepresentation»,(«FOR | 185 | «prettyPrint» |
138 | // in: incomingEdges.entrySet»(«in.key.type.name»=«in.key.from»,«in.value»)«ENDFOR»),(«FOR | 186 | ''' |
139 | // out: outgoingEdges.entrySet»(«out.key.type.name»=«out.key.to»,«out.value»)«ENDFOR»),«FOR | ||
140 | // att: attributeValues»(«att.type.name»=«att.value»)«ENDFOR»]''' | ||
141 | } | 187 | } |
142 | 188 | ||
143 | // @Pure | 189 | // @Pure |
144 | // @Override | 190 | // @Override |
145 | // override public boolean equals(Object obj) { | 191 | // override public boolean equals(Object obj) { |
@@ -154,7 +200,6 @@ import org.eclipse.xtend.lib.annotations.Data | |||
154 | // return false; | 200 | // return false; |
155 | // return true; | 201 | // return true; |
156 | // } | 202 | // } |
157 | |||
158 | // @Pure | 203 | // @Pure |
159 | // override public boolean equals(Object obj) { | 204 | // override public boolean equals(Object obj) { |
160 | // if (this === obj) | 205 | // if (this === obj) |
@@ -191,24 +236,23 @@ import org.eclipse.xtend.lib.annotations.Data | |||
191 | // return true; | 236 | // return true; |
192 | // } | 237 | // } |
193 | } | 238 | } |
194 | |||
195 | /* | 239 | /* |
196 | @Data | 240 | * @Data |
197 | class ModelDescriptor { | 241 | * class ModelDescriptor { |
198 | int dataHash | 242 | * int dataHash |
199 | int unknownElements | 243 | * int unknownElements |
200 | Map<? extends AbstractNodeDescriptor,Integer> knownElements | 244 | * Map<? extends AbstractNodeDescriptor,Integer> knownElements |
201 | 245 | * | |
202 | public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) { | 246 | * public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) { |
203 | this.dataHash = calculateDataHash(knownElements,unknownElements) | 247 | * this.dataHash = calculateDataHash(knownElements,unknownElements) |
204 | this.unknownElements = unknownElements | 248 | * this.unknownElements = unknownElements |
205 | this.knownElements = knownElements | 249 | * this.knownElements = knownElements |
206 | } | 250 | * } |
207 | 251 | * | |
208 | def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) | 252 | * def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) |
209 | { | 253 | * { |
210 | val int prime = 31; | 254 | * val int prime = 31; |
211 | return knownElements.hashCode * prime + unknownElements.hashCode | 255 | * return knownElements.hashCode * prime + unknownElements.hashCode |
212 | } | 256 | * } |
213 | } | 257 | * } |
214 | */ \ No newline at end of file | 258 | */ |