aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend
blob: bad8e4d13896435106c466aa54d9a001a20fcec6 (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
package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse

import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement
import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.AbstractThreeValuedObjective
import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind
import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold
import org.eclipse.viatra.dse.base.ThreadContext

class PunishSizeObjective extends AbstractThreeValuedObjective {
	static val NAME = typeof(PunishSizeObjective).name
	
	new(ObjectiveKind kind, int level) {
		super(NAME, kind, ObjectiveThreshold.NO_THRESHOLD, level)
	}
	
	override createNew() {
		new PunishSizeObjective(kind, level)
	}
	
	override init(ThreadContext context) {
		// Nothing to initialize.
	}
	
	override getRawFitness(ThreadContext threadContext) {
		val model = threadContext.model
		if (model instanceof PartialInterpretation) {
			val size = model.newObjectCount
//			println('''size=«size»''')
			size as double
		} else {
			throw new IllegalArgumentException("notifier must be a PartialInterpretation")
		}
	}
	
	override getLowestPossibleFitness(ThreadContext threadContext) {
		getRawFitness(threadContext)
	}
	
	override getHighestPossibleFitness(ThreadContext threadContext) {
		val model = threadContext.model
		if (model instanceof PartialInterpretation) {
			(model.newObjectCount + model.maxNewElements) as double
		} else {
			throw new IllegalArgumentException("notifier must be a PartialInterpretation")
		}
	}
	
	private def getNewObjectCount(PartialInterpretation interpretation) {
		interpretation.newElements.reject[it instanceof PrimitiveElement].size
	}
}