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, 112 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..c7c1ad77 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,41 @@ 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 protected prettyPrint() { | ||
64 | '''(«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»]''' | ||
65 | } | ||
66 | |||
51 | override toString() { | 67 | override toString() { |
52 | return class.name + this.dataHash | 68 | ''' |
69 | «prettyPrint» | ||
70 | ''' | ||
53 | } | 71 | } |
54 | 72 | ||
55 | // @Pure | 73 | // @Pure |
56 | // @Override | 74 | // @Override |
57 | // override public boolean equals(Object obj) { | 75 | // override public boolean equals(Object obj) { |
@@ -66,7 +84,6 @@ import org.eclipse.xtend.lib.annotations.Data | |||
66 | // return false; | 84 | // return false; |
67 | // return true; | 85 | // return true; |
68 | // } | 86 | // } |
69 | |||
70 | // @Pure | 87 | // @Pure |
71 | // override public boolean equals(Object obj) { | 88 | // override public boolean equals(Object obj) { |
72 | // if (this === obj) | 89 | // if (this === obj) |
@@ -97,49 +114,70 @@ import org.eclipse.xtend.lib.annotations.Data | |||
97 | String type | 114 | String type |
98 | } | 115 | } |
99 | 116 | ||
100 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor{ | 117 | @Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor { |
101 | 118 | ||
102 | NodeRep previousRepresentation | 119 | NodeRep previousRepresentation |
103 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges | 120 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges |
104 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges | 121 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges |
105 | 122 | ||
106 | new( | 123 | new(NodeRep previousRepresentation, Map<IncomingRelation<NodeRep>, Integer> incomingEdges, |
107 | NodeRep previousRepresentation, | 124 | Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { |
108 | Map<IncomingRelation<NodeRep>,Integer> incomingEdges, | 125 | super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges)) |
109 | Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges) | 126 | this.previousRepresentation = previousRepresentation |
110 | { | 127 | this.incomingEdges = new HashMap(incomingEdges) |
111 | super(calculateDataHash(previousRepresentation,incomingEdges,outgoingEdges)) | 128 | 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 | } | 129 | } |
134 | 130 | ||
131 | static def private <NodeRep> int calculateDataHash(NodeRep previousRepresentation, | ||
132 | Map<IncomingRelation<NodeRep>, Integer> incomingEdges, Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) { | ||
133 | val int prime = 31; | ||
134 | var int result = previousRepresentation.hashCode; | ||
135 | if (incomingEdges !== null) | ||
136 | result = prime * result + incomingEdges.hashCode(); | ||
137 | if (outgoingEdges !== null) | ||
138 | result = prime * result + outgoingEdges.hashCode(); | ||
139 | return result; | ||
140 | } | ||
141 | |||
142 | override hashCode() { | ||
143 | return this.dataHash.hashCode | ||
144 | } | ||
145 | |||
146 | override prettyPrint() { | ||
147 | ''' | ||
148 | («dataHash»)[ | ||
149 | PREV = «previousRepresentation?.prettyPrint» | ||
150 | «IF incomingEdges === null» | ||
151 | IN null | ||
152 | «ELSE» | ||
153 | «FOR edge : incomingEdges.entrySet» | ||
154 | IN «edge.value» «edge.key.type» = «edge.key.from.prettyPrint» | ||
155 | «ENDFOR» | ||
156 | «ENDIF» | ||
157 | «IF outgoingEdges === null» | ||
158 | OUT null | ||
159 | «ELSE» | ||
160 | «FOR edge : outgoingEdges.entrySet» | ||
161 | OUT «edge.value» «edge.key.type» = «edge.key.to.prettyPrint» | ||
162 | «ENDFOR» | ||
163 | «ENDIF» | ||
164 | ]''' | ||
165 | } | ||
166 | |||
167 | private def StringConcatenationClient prettyPrint(NodeRep rep) { | ||
168 | if (rep instanceof AbstractNodeDescriptor) { | ||
169 | rep.prettyPrint | ||
170 | } else { | ||
171 | '''«rep»''' | ||
172 | } | ||
173 | } | ||
174 | |||
135 | override toString() { | 175 | override toString() { |
136 | return class.name + dataHash | 176 | ''' |
137 | // return '''[«previousRepresentation»,(«FOR | 177 | «prettyPrint» |
138 | // in: incomingEdges.entrySet»(«in.key.type.name»=«in.key.from»,«in.value»)«ENDFOR»),(«FOR | 178 | ''' |
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 | } | 179 | } |
142 | 180 | ||
143 | // @Pure | 181 | // @Pure |
144 | // @Override | 182 | // @Override |
145 | // override public boolean equals(Object obj) { | 183 | // override public boolean equals(Object obj) { |
@@ -154,7 +192,6 @@ import org.eclipse.xtend.lib.annotations.Data | |||
154 | // return false; | 192 | // return false; |
155 | // return true; | 193 | // return true; |
156 | // } | 194 | // } |
157 | |||
158 | // @Pure | 195 | // @Pure |
159 | // override public boolean equals(Object obj) { | 196 | // override public boolean equals(Object obj) { |
160 | // if (this === obj) | 197 | // if (this === obj) |
@@ -191,24 +228,23 @@ import org.eclipse.xtend.lib.annotations.Data | |||
191 | // return true; | 228 | // return true; |
192 | // } | 229 | // } |
193 | } | 230 | } |
194 | |||
195 | /* | 231 | /* |
196 | @Data | 232 | * @Data |
197 | class ModelDescriptor { | 233 | * class ModelDescriptor { |
198 | int dataHash | 234 | * int dataHash |
199 | int unknownElements | 235 | * int unknownElements |
200 | Map<? extends AbstractNodeDescriptor,Integer> knownElements | 236 | * Map<? extends AbstractNodeDescriptor,Integer> knownElements |
201 | 237 | * | |
202 | public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) { | 238 | * public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) { |
203 | this.dataHash = calculateDataHash(knownElements,unknownElements) | 239 | * this.dataHash = calculateDataHash(knownElements,unknownElements) |
204 | this.unknownElements = unknownElements | 240 | * this.unknownElements = unknownElements |
205 | this.knownElements = knownElements | 241 | * this.knownElements = knownElements |
206 | } | 242 | * } |
207 | 243 | * | |
208 | def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) | 244 | * def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) |
209 | { | 245 | * { |
210 | val int prime = 31; | 246 | * val int prime = 31; |
211 | return knownElements.hashCode * prime + unknownElements.hashCode | 247 | * return knownElements.hashCode * prime + unknownElements.hashCode |
212 | } | 248 | * } |
213 | } | 249 | * } |
214 | */ \ No newline at end of file | 250 | */ |