diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver')
3 files changed, 30 insertions, 37 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend index b58033d7..fd871615 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend | |||
@@ -28,11 +28,13 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.LoggerSolutionFoundH | |||
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ModelGenerationCompositeObjective | 28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ModelGenerationCompositeObjective |
29 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.NumericSolver | 29 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.NumericSolver |
30 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PartialModelAsLogicInterpretation | 30 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PartialModelAsLogicInterpretation |
31 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PunishSizeObjective | ||
31 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ScopeObjective | 32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ScopeObjective |
32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.SurelyViolatedObjectiveGlobalConstraint | 33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.SurelyViolatedObjectiveGlobalConstraint |
33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.UnfinishedMultiplicityObjective | 34 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.UnfinishedMultiplicityObjective |
34 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ViatraReasonerSolutionSaver | 35 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ViatraReasonerSolutionSaver |
35 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.WF2ObjectiveConverter | 36 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.WF2ObjectiveConverter |
37 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind | ||
36 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ThreeValuedCostElement | 38 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ThreeValuedCostElement |
37 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ThreeValuedCostObjective | 39 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ThreeValuedCostObjective |
38 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | 40 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace |
@@ -43,7 +45,6 @@ import org.eclipse.viatra.dse.api.DesignSpaceExplorer | |||
43 | import org.eclipse.viatra.dse.api.DesignSpaceExplorer.DseLoggingLevel | 45 | import org.eclipse.viatra.dse.api.DesignSpaceExplorer.DseLoggingLevel |
44 | import org.eclipse.viatra.dse.solutionstore.SolutionStore | 46 | import org.eclipse.viatra.dse.solutionstore.SolutionStore |
45 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory | 47 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory |
46 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PunishSizeObjective | ||
47 | 48 | ||
48 | class ViatraReasoner extends LogicReasoner { | 49 | class ViatraReasoner extends LogicReasoner { |
49 | val PartialInterpretationInitialiser initialiser = new PartialInterpretationInitialiser() | 50 | val PartialInterpretationInitialiser initialiser = new PartialInterpretationInitialiser() |
@@ -100,9 +101,13 @@ class ViatraReasoner extends LogicReasoner { | |||
100 | viatraConfig | 101 | viatraConfig |
101 | ) | 102 | ) |
102 | dse.addObjective(compositeObjective) | 103 | dse.addObjective(compositeObjective) |
103 | if (viatraConfig.punishSize) { | 104 | if (viatraConfig.punishSize != PunishSizeStrategy.NONE) { |
104 | val punishObjective = new PunishSizeObjective | 105 | val punishSizeStrategy = switch (viatraConfig.punishSize) { |
105 | punishObjective.level = compositeObjective.level + 1 | 106 | case SMALLER_IS_BETTER: ObjectiveKind.LOWER_IS_BETTER |
107 | case LARGER_IS_BETTER: ObjectiveKind.HIGHER_IS_BETTER | ||
108 | default: throw new IllegalArgumentException("Unknown PunishSizeStrategy: " + viatraConfig.punishSize) | ||
109 | } | ||
110 | val punishObjective = new PunishSizeObjective(punishSizeStrategy, compositeObjective.level + 1) | ||
106 | dse.addObjective(punishObjective) | 111 | dse.addObjective(punishObjective) |
107 | } | 112 | } |
108 | 113 | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend index a2f6de22..0173124c 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend | |||
@@ -26,6 +26,12 @@ enum StateCoderStrategy { | |||
26 | DefinedByDiversity | 26 | DefinedByDiversity |
27 | } | 27 | } |
28 | 28 | ||
29 | enum PunishSizeStrategy { | ||
30 | NONE, | ||
31 | SMALLER_IS_BETTER, | ||
32 | LARGER_IS_BETTER | ||
33 | } | ||
34 | |||
29 | class ViatraReasonerConfiguration extends LogicSolverConfiguration { | 35 | class ViatraReasonerConfiguration extends LogicSolverConfiguration { |
30 | // public var Iterable<PQuery> existingQueries | 36 | // public var Iterable<PQuery> existingQueries |
31 | public var nameNewElements = false | 37 | public var nameNewElements = false |
@@ -57,7 +63,7 @@ class ViatraReasonerConfiguration extends LogicSolverConfiguration { | |||
57 | 63 | ||
58 | public var runIntermediateNumericalConsistencyChecks = true | 64 | public var runIntermediateNumericalConsistencyChecks = true |
59 | 65 | ||
60 | public var punishSize = false | 66 | public var punishSize = PunishSizeStrategy.NONE |
61 | public var scopeWeight = 1 | 67 | public var scopeWeight = 1 |
62 | public var conaintmentWeight = 2 | 68 | public var conaintmentWeight = 2 |
63 | public var nonContainmentWeight = 1 | 69 | public var nonContainmentWeight = 1 |
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 index 8505661c..bad8e4d1 100644 --- 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 | |||
@@ -2,28 +2,27 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse | |||
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement | 4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement |
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.IThreeValuedObjective | 5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.AbstractThreeValuedObjective |
6 | import java.util.Comparator | 6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind |
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold | ||
7 | import org.eclipse.viatra.dse.base.ThreadContext | 8 | import org.eclipse.viatra.dse.base.ThreadContext |
8 | import org.eclipse.viatra.dse.objectives.Comparators | ||
9 | import org.eclipse.xtend.lib.annotations.Accessors | ||
10 | 9 | ||
11 | class PunishSizeObjective implements IThreeValuedObjective { | 10 | class PunishSizeObjective extends AbstractThreeValuedObjective { |
12 | @Accessors int level = 3 | 11 | static val NAME = typeof(PunishSizeObjective).name |
12 | |||
13 | new(ObjectiveKind kind, int level) { | ||
14 | super(NAME, kind, ObjectiveThreshold.NO_THRESHOLD, level) | ||
15 | } | ||
13 | 16 | ||
14 | override createNew() { | 17 | override createNew() { |
15 | this | 18 | new PunishSizeObjective(kind, level) |
16 | } | 19 | } |
17 | 20 | ||
18 | override init(ThreadContext context) { | 21 | override init(ThreadContext context) { |
19 | // Nothing to initialize. | 22 | // Nothing to initialize. |
20 | } | 23 | } |
21 | 24 | ||
22 | override getComparator() { | 25 | override getRawFitness(ThreadContext threadContext) { |
23 | Comparators.LOWER_IS_BETTER | ||
24 | } | ||
25 | |||
26 | override getFitness(ThreadContext threadContext) { | ||
27 | val model = threadContext.model | 26 | val model = threadContext.model |
28 | if (model instanceof PartialInterpretation) { | 27 | if (model instanceof PartialInterpretation) { |
29 | val size = model.newObjectCount | 28 | val size = model.newObjectCount |
@@ -34,11 +33,11 @@ class PunishSizeObjective implements IThreeValuedObjective { | |||
34 | } | 33 | } |
35 | } | 34 | } |
36 | 35 | ||
37 | override getBestPossibleFitness(ThreadContext threadContext) { | 36 | override getLowestPossibleFitness(ThreadContext threadContext) { |
38 | getFitness(threadContext) | 37 | getRawFitness(threadContext) |
39 | } | 38 | } |
40 | 39 | ||
41 | override getWorstPossibleFitness(ThreadContext threadContext) { | 40 | override getHighestPossibleFitness(ThreadContext threadContext) { |
42 | val model = threadContext.model | 41 | val model = threadContext.model |
43 | if (model instanceof PartialInterpretation) { | 42 | if (model instanceof PartialInterpretation) { |
44 | (model.newObjectCount + model.maxNewElements) as double | 43 | (model.newObjectCount + model.maxNewElements) as double |
@@ -50,21 +49,4 @@ class PunishSizeObjective implements IThreeValuedObjective { | |||
50 | private def getNewObjectCount(PartialInterpretation interpretation) { | 49 | private def getNewObjectCount(PartialInterpretation interpretation) { |
51 | interpretation.newElements.reject[it instanceof PrimitiveElement].size | 50 | interpretation.newElements.reject[it instanceof PrimitiveElement].size |
52 | } | 51 | } |
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 | 52 | } \ No newline at end of file |