aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend')
-rw-r--r--Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend242
1 files changed, 118 insertions, 124 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..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
@@ -4,10 +4,21 @@ import java.util.HashMap
4import java.util.Map 4import java.util.Map
5import java.util.Set 5import java.util.Set
6import org.eclipse.xtend.lib.annotations.Data 6import org.eclipse.xtend.lib.annotations.Data
7import org.eclipse.xtend2.lib.StringConcatenationClient
7 8
8@Data abstract class AbstractNodeDescriptor { 9@Data abstract class AbstractNodeDescriptor {
9 long dataHash 10 int 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
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,118 +118,91 @@ 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 NodeRep previousRepresentation
102 NodeRep previousRepresentation 123 Map<IncomingRelation<NodeRep>, Integer> incomingEdges
103 Map<IncomingRelation<NodeRep>,Integer> incomingEdges 124 Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges
104 Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges 125
105 126 new(NodeRep previousRepresentation, Map<IncomingRelation<NodeRep>, Integer> incomingEdges,
106 new( 127 Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) {
107 NodeRep previousRepresentation, 128 super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges))
108 Map<IncomingRelation<NodeRep>,Integer> incomingEdges, 129 this.previousRepresentation = previousRepresentation
109 Map<OutgoingRelation<NodeRep>,Integer> outgoingEdges) 130 this.incomingEdges = incomingEdges
110 { 131 this.outgoingEdges = outgoingEdges
111 super(calculateDataHash(previousRepresentation,incomingEdges,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 } 132 }
134 133
135 override toString() { 134 static def private <NodeRep> int calculateDataHash(NodeRep previousRepresentation,
136 return class.name + dataHash 135 Map<IncomingRelation<NodeRep>, Integer> incomingEdges, Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) {
137// return '''[«previousRepresentation»,(«FOR 136 val int prime = 31;
138// in: incomingEdges.entrySet»(«in.key.type.name»=«in.key.from»,«in.value»)«ENDFOR»),(«FOR 137 var int result = previousRepresentation.hashCode;
139// out: outgoingEdges.entrySet»(«out.key.type.name»=«out.key.to»,«out.value»)«ENDFOR»),«FOR 138 if (incomingEdges !== null)
140// att: attributeValues»(«att.type.name»=«att.value»)«ENDFOR»]''' 139 result = prime * result + hashIncomingNeighborhood(incomingEdges)
140 if (outgoingEdges !== null)
141 result = prime * result + hashOutgoingNeighborhood(outgoingEdges)
142 return result;
141 } 143 }
142
143// @Pure
144// @Override
145// override public boolean equals(Object obj) {
146// if (this === obj)
147// return true;
148// if (obj === null)
149// return false;
150// if (getClass() != obj.getClass())
151// return false;
152// val AbstractNodeDescriptor other = obj as AbstractNodeDescriptor;
153// if (other.dataHash != this.dataHash)
154// return false;
155// return true;
156// }
157
158// @Pure
159// override public boolean equals(Object obj) {
160// if (this === obj)
161// return true;
162// if (obj === null)
163// return false;
164// if (getClass() != obj.getClass())
165// return false;
166// if (!super.equals(obj))
167// return false;
168// val FurtherNodeDescriptor<?> other = obj as FurtherNodeDescriptor<?>;
169// if (this.previousRepresentation === null) {
170// if (other.previousRepresentation != null)
171// return false;
172//
173// }
174//// } else if (!this.previousRepresentation.equals(other.previousRepresentation))
175//// return false;
176// if (this.incomingEdges === null) {
177// if (other.incomingEdges != null)
178// return false;
179// } else if (!this.incomingEdges.equals(other.incomingEdges))
180// return false;
181// if (this.outgoingEdges === null) {
182// if (other.outgoingEdges != null)
183// return false;
184// } else if (!this.outgoingEdges.equals(other.outgoingEdges))
185// return false;
186// if (this.attributeValues === null) {
187// if (other.attributeValues != null)
188// return false;
189// } else if (!this.attributeValues.equals(other.attributeValues))
190// return false;
191// return true;
192// }
193}
194 144
195/* 145 override hashCode() {
196@Data 146 return this.dataHash
197class ModelDescriptor { 147 }
198 int dataHash 148
199 int unknownElements 149 override equals(Object other) {
200 Map<? extends AbstractNodeDescriptor,Integer> knownElements 150 other.class == FurtherNodeDescriptor && (other as AbstractNodeDescriptor).hashCode == hashCode
151 }
152
153 override prettyPrint() {
154 '''
155 («dataHash»)[
156 PREV = «previousRepresentation?.prettyPrint»
157 «IF incomingEdges === null»
158 IN null
159 «ELSE»
160 «FOR edge : incomingEdges.entrySet»
161 IN «edge.value» «edge.key.type» = «edge.key.from.prettyPrint»
162 «ENDFOR»
163 «ENDIF»
164 «IF outgoingEdges === null»
165 OUT null
166 «ELSE»
167 «FOR edge : outgoingEdges.entrySet»
168 OUT «edge.value» «edge.key.type» = «edge.key.to.prettyPrint»
169 «ENDFOR»
170 «ENDIF»
171 ]'''
172 }
173
174 private def StringConcatenationClient prettyPrint(NodeRep rep) {
175 if (rep instanceof AbstractNodeDescriptor) {
176 rep.prettyPrint
177 } else {
178 '''«rep»'''
179 }
180 }
201 181
202 public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) { 182 private static def <NodeRep> hashIncomingNeighborhood(Map<IncomingRelation<NodeRep>, Integer> neighborhood) {
203 this.dataHash = calculateDataHash(knownElements,unknownElements) 183 val int prime = 31
204 this.unknownElements = unknownElements 184 var int hash = 0
205 this.knownElements = knownElements 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
206 } 190 }
207 191
208 def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) 192 private static def <NodeRep> hashOutgoingNeighborhood(Map<OutgoingRelation<NodeRep>, Integer> neighborhood) {
209 { 193 val int prime = 31
210 val int prime = 31; 194 var int hash = 0
211 return knownElements.hashCode * prime + unknownElements.hashCode 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 }
201
202 override toString() {
203 '''
204 «prettyPrint»
205 '''
212 } 206 }
213} 207}
214*/ \ No newline at end of file 208