diff options
author | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2020-11-04 01:16:22 -0500 |
---|---|---|
committer | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2020-11-04 01:16:22 -0500 |
commit | 93243cb3faf1ccd733081fcf380559ac03c9ad35 (patch) | |
tree | 421f9f174eb77c387b5acaa05f01e64a62cab3a7 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend | |
parent | add realistic solver (diff) | |
parent | Optimizing generator with linear objective functions (diff) | |
download | VIATRA-Generator-93243cb3faf1ccd733081fcf380559ac03c9ad35.tar.gz VIATRA-Generator-93243cb3faf1ccd733081fcf380559ac03c9ad35.tar.zst VIATRA-Generator-93243cb3faf1ccd733081fcf380559ac03c9ad35.zip |
merge with current master, comment numerical solver related logging
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend new file mode 100644 index 00000000..bad8e4d1 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend | |||
@@ -0,0 +1,52 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.AbstractThreeValuedObjective | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold | ||
8 | import org.eclipse.viatra.dse.base.ThreadContext | ||
9 | |||
10 | class PunishSizeObjective extends AbstractThreeValuedObjective { | ||
11 | static val NAME = typeof(PunishSizeObjective).name | ||
12 | |||
13 | new(ObjectiveKind kind, int level) { | ||
14 | super(NAME, kind, ObjectiveThreshold.NO_THRESHOLD, level) | ||
15 | } | ||
16 | |||
17 | override createNew() { | ||
18 | new PunishSizeObjective(kind, level) | ||
19 | } | ||
20 | |||
21 | override init(ThreadContext context) { | ||
22 | // Nothing to initialize. | ||
23 | } | ||
24 | |||
25 | override getRawFitness(ThreadContext threadContext) { | ||
26 | val model = threadContext.model | ||
27 | if (model instanceof PartialInterpretation) { | ||
28 | val size = model.newObjectCount | ||
29 | // println('''size=«size»''') | ||
30 | size as double | ||
31 | } else { | ||
32 | throw new IllegalArgumentException("notifier must be a PartialInterpretation") | ||
33 | } | ||
34 | } | ||
35 | |||
36 | override getLowestPossibleFitness(ThreadContext threadContext) { | ||
37 | getRawFitness(threadContext) | ||
38 | } | ||
39 | |||
40 | override getHighestPossibleFitness(ThreadContext threadContext) { | ||
41 | val model = threadContext.model | ||
42 | if (model instanceof PartialInterpretation) { | ||
43 | (model.newObjectCount + model.maxNewElements) as double | ||
44 | } else { | ||
45 | throw new IllegalArgumentException("notifier must be a PartialInterpretation") | ||
46 | } | ||
47 | } | ||
48 | |||
49 | private def getNewObjectCount(PartialInterpretation interpretation) { | ||
50 | interpretation.newElements.reject[it instanceof PrimitiveElement].size | ||
51 | } | ||
52 | } \ No newline at end of file | ||