aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/MultiplicityGoalConstraintCalculator.xtend
blob: 4b9629dffe2c6baebcbe60f9de5f99ca9facb864 (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
package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra

import org.eclipse.emf.common.notify.Notifier
import org.eclipse.viatra.query.runtime.api.IQuerySpecification
import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher
import org.eclipse.viatra.query.runtime.emf.EMFScope

class MultiplicityGoalConstraintCalculator {
	val String targetRelationName;
	val IQuerySpecification<?> querySpecification;
	var ViatraQueryMatcher<?> matcher;
		
	new(String targetRelationName, IQuerySpecification<?> querySpecification) {
		this.targetRelationName = targetRelationName
		this.querySpecification = querySpecification
		this.matcher = null
	}
	
	new(MultiplicityGoalConstraintCalculator other) {
		this.targetRelationName = other.targetRelationName
		this.querySpecification = other.querySpecification
		this.matcher = null
	}
	
	def getName() {
		targetRelationName
	}
	
	def init(Notifier notifier) {
		val engine = ViatraQueryEngine.on(new EMFScope(notifier))
		matcher = querySpecification.getMatcher(engine)
	}
	
	def calculateValue() {
		var res = 0
		val allMatches = this.matcher.allMatches
		for(match : allMatches) {
			//println(targetRelationName+ " missing multiplicity: "+match.get(3))
			val missingMultiplicity = match.get(4) as Integer
			res += missingMultiplicity
		}
		//println(targetRelationName+ " all missing multiplicities: "+res)
		return res
	}
}