aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend
blob: e4bdb086063bc78897392ebf798072e398c01bda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood

import java.util.HashMap
import java.util.Map
import java.util.Set
import org.eclipse.xtend.lib.annotations.Data
import org.eclipse.xtend2.lib.StringConcatenationClient

@Data abstract class AbstractNodeDescriptor {
	long dataHash

	protected def StringConcatenationClient prettyPrint() {
		'''(«dataHash»)[«class.simpleName»]'''
	}

	override toString() {
		'''
			«prettyPrint»
		'''
	}

//	@Pure
//	@Override
//	override public boolean equals(Object obj) {
//		if (this === obj)
//			return true;
//		if (obj === null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		val AbstractNodeDescriptor other = obj as AbstractNodeDescriptor;
//		if (other.dataHash != this.dataHash)
//			return false;
//		return true;
//	}
}

@Data class LocalNodeDescriptor extends AbstractNodeDescriptor {
	Set<String> types
	String id;

	new(String id, Set<String> types) {
		super(calcualteDataHash(id, types))
		this.types = types
		this.id = id
	}

	def private static calcualteDataHash(String id, Set<String> types) {
		val int prime = 31;
		var result = 0
		if (id !== null)
			result = id.hashCode();
		if (types !== null) {
			result = prime * result + types.hashCode
		}
		return result
	}

	override hashCode() {
		return this.dataHash.hashCode
	}

	override equals(Object other) {
		other.class == LocalNodeDescriptor && (other as AbstractNodeDescriptor).hashCode == hashCode
	}

	override protected prettyPrint() {
		'''(«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»]'''
	}

	override toString() {
		'''
			«prettyPrint»
		'''
	}

//	@Pure
//	@Override
//	override public boolean equals(Object obj) {
//		if (this === obj)
//			return true;
//		if (obj === null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		val AbstractNodeDescriptor other = obj as AbstractNodeDescriptor;
//		if (other.dataHash != this.dataHash)
//			return false;
//		return true;
//	}
//	@Pure
//	override public boolean equals(Object obj) {
//		if (this === obj)
//			return true;
//		if (obj === null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		if (!super.equals(obj))
//			return false;
//		val LocalNodeDescriptor other = obj as LocalNodeDescriptor;
//		if (this.clazz === null) {
//			if (other.clazz != null)
//				return false;
//		} else if (!this.clazz.equals(other.clazz))
//			return false;
//		return true;
//	}
}

@Data class IncomingRelation<FROM> {
	FROM from
	String type
}

@Data class OutgoingRelation<TO> {
	TO to
	String type
}

@Data class FurtherNodeDescriptor<NodeRep> extends AbstractNodeDescriptor {

	NodeRep previousRepresentation
	Map<IncomingRelation<NodeRep>, Integer> incomingEdges
	Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges

	new(NodeRep previousRepresentation, Map<IncomingRelation<NodeRep>, Integer> incomingEdges,
		Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) {
		super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges))
		this.previousRepresentation = previousRepresentation
		this.incomingEdges = new HashMap(incomingEdges)
		this.outgoingEdges = new HashMap(outgoingEdges)
	}

	static def private <NodeRep> int calculateDataHash(NodeRep previousRepresentation,
		Map<IncomingRelation<NodeRep>, Integer> incomingEdges, Map<OutgoingRelation<NodeRep>, Integer> outgoingEdges) {
		val int prime = 31;
		var int result = previousRepresentation.hashCode;
		if (incomingEdges !== null)
			result = prime * result + incomingEdges.hashCode();
		if (outgoingEdges !== null)
			result = prime * result + outgoingEdges.hashCode();
		return result;
	}

	override hashCode() {
		return this.dataHash.hashCode
	}

	override equals(Object other) {
		other.class == FurtherNodeDescriptor && (other as AbstractNodeDescriptor).hashCode == hashCode
	}

	override prettyPrint() {
		'''
dataHash»)[
			PREV = «previousRepresentation?.prettyPrint»
			«IF incomingEdges === null»
				IN null
			«ELSE»
				«FOR edge : incomingEdges.entrySet»
					IN «edge.value» «edge.key.type» = «edge.key.from.prettyPrint»
				«ENDFOR»
			«ENDIF»
			«IF outgoingEdges === null»
				OUT null
			«ELSE»
				«FOR edge : outgoingEdges.entrySet»
					OUT «edge.value» «edge.key.type» = «edge.key.to.prettyPrint»
				«ENDFOR»
			«ENDIF»
		]'''
	}

	private def StringConcatenationClient prettyPrint(NodeRep rep) {
		if (rep instanceof AbstractNodeDescriptor) {
			rep.prettyPrint
		} else {
			'''«rep»'''
		}
	}

	override toString() {
		'''
			«prettyPrint»
		'''
	}

//	@Pure
//	@Override
//	override public boolean equals(Object obj) {
//		if (this === obj)
//			return true;
//		if (obj === null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		val AbstractNodeDescriptor other = obj as AbstractNodeDescriptor;
//		if (other.dataHash != this.dataHash)
//			return false;
//		return true;
//	}
//	@Pure
//	override public boolean equals(Object obj) {
//		if (this === obj)
//			return true;
//		if (obj === null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		if (!super.equals(obj))
//			return false;
//		val FurtherNodeDescriptor<?> other = obj as FurtherNodeDescriptor<?>;
//		if (this.previousRepresentation === null) {
//			if (other.previousRepresentation != null)
//				return false;
//			
//		}
////		} else if (!this.previousRepresentation.equals(other.previousRepresentation))
////			return false;
//		if (this.incomingEdges === null) {
//			if (other.incomingEdges != null)
//				return false;
//		} else if (!this.incomingEdges.equals(other.incomingEdges))
//			return false;
//		if (this.outgoingEdges === null) {
//			if (other.outgoingEdges != null)
//				return false;
//		} else if (!this.outgoingEdges.equals(other.outgoingEdges))
//			return false;
//		if (this.attributeValues === null) {
//			if (other.attributeValues != null)
//				return false;
//		} else if (!this.attributeValues.equals(other.attributeValues))
//			return false;
//		return true;
//	}
}
/*
 * @Data
 * class ModelDescriptor {
 * 	int dataHash
 * 	int unknownElements
 * 	Map<? extends AbstractNodeDescriptor,Integer> knownElements
 * 	
 * 	public new(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements) {
 * 		this.dataHash = calculateDataHash(knownElements,unknownElements)
 * 		this.unknownElements = unknownElements
 * 		this.knownElements = knownElements
 * 	}
 * 	
 * 	def private static calculateDataHash(Map<? extends AbstractNodeDescriptor,Integer> knownElements, int unknownElements)
 * 	{
 * 		val int prime = 31;
 * 		return knownElements.hashCode * prime + unknownElements.hashCode 
 * 	}
 * }
 */