diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/DseUtils.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/DseUtils.xtend | 65 |
1 files changed, 65 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/DseUtils.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/DseUtils.xtend new file mode 100644 index 00000000..3a897aa3 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/DseUtils.xtend | |||
@@ -0,0 +1,65 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse | ||
2 | |||
3 | import org.eclipse.viatra.dse.base.ThreadContext | ||
4 | import org.eclipse.viatra.dse.objectives.Comparators | ||
5 | import org.eclipse.viatra.dse.objectives.Fitness | ||
6 | import org.eclipse.viatra.dse.objectives.IObjective | ||
7 | |||
8 | final class DseUtils { | ||
9 | private new() { | ||
10 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly.") | ||
11 | } | ||
12 | |||
13 | static def calculateFitness(ThreadContext it, (IObjective)=>Double getFitness) { | ||
14 | val result = new Fitness | ||
15 | var boolean satisifiesHardObjectives = true | ||
16 | for (objective : objectives) { | ||
17 | val fitness = getFitness.apply(objective) | ||
18 | result.put(objective.name, fitness) | ||
19 | if (objective.isHardObjective() && !objective.satisifiesHardObjective(fitness)) { | ||
20 | satisifiesHardObjectives = false | ||
21 | } | ||
22 | } | ||
23 | result.satisifiesHardObjectives = satisifiesHardObjectives | ||
24 | result | ||
25 | } | ||
26 | |||
27 | static def caclulateBestPossibleFitness(ThreadContext threadContext) { | ||
28 | threadContext.calculateFitness [ objective | | ||
29 | if (objective instanceof IThreeValuedObjective) { | ||
30 | objective.getBestPossibleFitness(threadContext) | ||
31 | } else { | ||
32 | switch (objective.comparator) { | ||
33 | case Comparators.LOWER_IS_BETTER: | ||
34 | Double.NEGATIVE_INFINITY | ||
35 | case Comparators.HIGHER_IS_BETTER: | ||
36 | Double.POSITIVE_INFINITY | ||
37 | case Comparators.DIFFERENCE_TO_ZERO_IS_BETTER: | ||
38 | 0.0 | ||
39 | default: | ||
40 | throw new IllegalArgumentException("Unknown comparator for non-three-valued objective: " + | ||
41 | objective.name) | ||
42 | } | ||
43 | } | ||
44 | ] | ||
45 | } | ||
46 | |||
47 | static def caclulateWorstPossibleFitness(ThreadContext threadContext) { | ||
48 | threadContext.calculateFitness [ objective | | ||
49 | if (objective instanceof IThreeValuedObjective) { | ||
50 | objective.getWorstPossibleFitness(threadContext) | ||
51 | } else { | ||
52 | switch (objective.comparator) { | ||
53 | case Comparators.LOWER_IS_BETTER, | ||
54 | case Comparators.DIFFERENCE_TO_ZERO_IS_BETTER: | ||
55 | Double.POSITIVE_INFINITY | ||
56 | case Comparators.HIGHER_IS_BETTER: | ||
57 | Double.NEGATIVE_INFINITY | ||
58 | default: | ||
59 | throw new IllegalArgumentException("Unknown comparator for non-three-valued objective: " + | ||
60 | objective.name) | ||
61 | } | ||
62 | } | ||
63 | ] | ||
64 | } | ||
65 | } | ||