diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-07-07 15:00:13 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-07-07 15:00:13 +0200 |
commit | a7b9a3eef14fc165909d00c65bb6fc1744a8ebd8 (patch) | |
tree | dd816939088926b3009432afa22be0e2a116436f /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/PunishSizeObjective.xtend | |
parent | Add modified VIATRA-DSE version (diff) | |
download | VIATRA-Generator-a7b9a3eef14fc165909d00c65bb6fc1744a8ebd8.tar.gz VIATRA-Generator-a7b9a3eef14fc165909d00c65bb6fc1744a8ebd8.tar.zst VIATRA-Generator-a7b9a3eef14fc165909d00c65bb6fc1744a8ebd8.zip |
Trying to fix performance regressions
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 | 70 |
1 files changed, 70 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..8505661c --- /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,70 @@ | |||
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.IThreeValuedObjective | ||
6 | import java.util.Comparator | ||
7 | import org.eclipse.viatra.dse.base.ThreadContext | ||
8 | import org.eclipse.viatra.dse.objectives.Comparators | ||
9 | import org.eclipse.xtend.lib.annotations.Accessors | ||
10 | |||
11 | class PunishSizeObjective implements IThreeValuedObjective { | ||
12 | @Accessors int level = 3 | ||
13 | |||
14 | override createNew() { | ||
15 | this | ||
16 | } | ||
17 | |||
18 | override init(ThreadContext context) { | ||
19 | // Nothing to initialize. | ||
20 | } | ||
21 | |||
22 | override getComparator() { | ||
23 | Comparators.LOWER_IS_BETTER | ||
24 | } | ||
25 | |||
26 | override getFitness(ThreadContext threadContext) { | ||
27 | val model = threadContext.model | ||
28 | if (model instanceof PartialInterpretation) { | ||
29 | val size = model.newObjectCount | ||
30 | // println('''size=«size»''') | ||
31 | size as double | ||
32 | } else { | ||
33 | throw new IllegalArgumentException("notifier must be a PartialInterpretation") | ||
34 | } | ||
35 | } | ||
36 | |||
37 | override getBestPossibleFitness(ThreadContext threadContext) { | ||
38 | getFitness(threadContext) | ||
39 | } | ||
40 | |||
41 | override getWorstPossibleFitness(ThreadContext threadContext) { | ||
42 | val model = threadContext.model | ||
43 | if (model instanceof PartialInterpretation) { | ||
44 | (model.newObjectCount + model.maxNewElements) as double | ||
45 | } else { | ||
46 | throw new IllegalArgumentException("notifier must be a PartialInterpretation") | ||
47 | } | ||
48 | } | ||
49 | |||
50 | private def getNewObjectCount(PartialInterpretation interpretation) { | ||
51 | interpretation.newElements.reject[it instanceof PrimitiveElement].size | ||
52 | } | ||
53 | |||
54 | override getName() { | ||
55 | typeof(PunishSizeObjective).name | ||
56 | } | ||
57 | |||
58 | override isHardObjective() { | ||
59 | false | ||
60 | } | ||
61 | |||
62 | override satisifiesHardObjective(Double fitness) { | ||
63 | true | ||
64 | } | ||
65 | |||
66 | override setComparator(Comparator<Double> comparator) { | ||
67 | throw new UnsupportedOperationException("Model generation objective comparator cannot be set.") | ||
68 | } | ||
69 | |||
70 | } \ No newline at end of file | ||