diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/AbstractThreeValuedObjective.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/AbstractThreeValuedObjective.xtend | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/AbstractThreeValuedObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/AbstractThreeValuedObjective.xtend new file mode 100644 index 00000000..241bef2a --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/AbstractThreeValuedObjective.xtend | |||
@@ -0,0 +1,102 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization | ||
2 | |||
3 | import java.util.Comparator | ||
4 | import org.eclipse.viatra.dse.base.ThreadContext | ||
5 | import org.eclipse.xtend.lib.annotations.Accessors | ||
6 | import org.eclipse.xtend.lib.annotations.Data | ||
7 | |||
8 | abstract class ObjectiveThreshold { | ||
9 | public static val NO_THRESHOLD = new hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold { | ||
10 | override isHard() { | ||
11 | false | ||
12 | } | ||
13 | |||
14 | override satisfiesThreshold(double cost, Comparator<Double> comparator) { | ||
15 | true | ||
16 | } | ||
17 | } | ||
18 | |||
19 | private new() { | ||
20 | } | ||
21 | |||
22 | def boolean isHard() { | ||
23 | true | ||
24 | } | ||
25 | |||
26 | def boolean satisfiesThreshold(double cost, Comparator<Double> comparator) | ||
27 | |||
28 | @Data | ||
29 | static class Exclusive extends ObjectiveThreshold { | ||
30 | val double threshold | ||
31 | |||
32 | override satisfiesThreshold(double cost, Comparator<Double> comparator) { | ||
33 | comparator.compare(threshold, cost) > 0 | ||
34 | } | ||
35 | } | ||
36 | |||
37 | @Data | ||
38 | static class Inclusive extends ObjectiveThreshold { | ||
39 | val double threshold | ||
40 | |||
41 | override satisfiesThreshold(double cost, Comparator<Double> comparator) { | ||
42 | comparator.compare(threshold, cost) >= 0 | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | |||
47 | abstract class AbstractThreeValuedObjective implements IThreeValuedObjective { | ||
48 | @Accessors val String name | ||
49 | @Accessors ObjectiveKind kind | ||
50 | @Accessors ObjectiveThreshold threshold | ||
51 | @Accessors int level | ||
52 | |||
53 | protected new(String name, ObjectiveKind kind, ObjectiveThreshold threshold, int level) { | ||
54 | this.name = name | ||
55 | this.kind = kind | ||
56 | this.threshold = threshold | ||
57 | this.level = level | ||
58 | } | ||
59 | |||
60 | abstract def double getLowestPossibleFitness(ThreadContext threadContext) | ||
61 | |||
62 | abstract def double getHighestPossibleFitness(ThreadContext threadContext) | ||
63 | |||
64 | override getWorstPossibleFitness(ThreadContext threadContext) { | ||
65 | switch (kind) { | ||
66 | case LOWER_IS_BETTER: | ||
67 | getHighestPossibleFitness(threadContext) | ||
68 | case HIGHER_IS_BETTER: | ||
69 | getLowestPossibleFitness(threadContext) | ||
70 | default: | ||
71 | throw new IllegalStateException("Unknown three valued objective kind: " + kind) | ||
72 | } | ||
73 | } | ||
74 | |||
75 | override getBestPossibleFitness(ThreadContext threadContext) { | ||
76 | switch (kind) { | ||
77 | case LOWER_IS_BETTER: | ||
78 | getLowestPossibleFitness(threadContext) | ||
79 | case HIGHER_IS_BETTER: | ||
80 | getHighestPossibleFitness(threadContext) | ||
81 | default: | ||
82 | throw new IllegalStateException("Unknown three valued objective kind: " + kind) | ||
83 | } | ||
84 | } | ||
85 | |||
86 | override isHardObjective() { | ||
87 | threshold.hard | ||
88 | } | ||
89 | |||
90 | override satisifiesHardObjective(Double fitness) { | ||
91 | threshold.satisfiesThreshold(fitness, comparator) | ||
92 | } | ||
93 | |||
94 | override getComparator() { | ||
95 | kind.comparator | ||
96 | } | ||
97 | |||
98 | override setComparator(Comparator<Double> comparator) { | ||
99 | kind = ObjectiveKind.fromComparator(comparator) | ||
100 | } | ||
101 | |||
102 | } | ||