diff options
author | 2019-08-14 18:26:33 +0200 | |
---|---|---|
committer | 2019-08-14 18:26:33 +0200 | |
commit | fc84d3fe670331bc89fb1e4c44104bc1fc811438 (patch) | |
tree | 466da8333151c51d2e17075600f9452ed35835da /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit | |
parent | Be more lenient with rounding IP solver results (diff) | |
download | VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.tar.gz VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.tar.zst VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.zip |
Measurements WIP
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit')
8 files changed, 162 insertions, 22 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 1abde0a8..aa02cd30 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 | |||
@@ -12,12 +12,15 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage | |||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicresultFactory | 12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicresultFactory |
13 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | 13 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult |
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationMethodProvider | 14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationMethodProvider |
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.PartialInterpretationInitialiser | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.PartialInterpretationInitialiser |
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | 18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage |
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.AbstractNeighbourhoodBasedStateCoderFactory | 19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.AbstractNeighbourhoodBasedStateCoderFactory |
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.IdentifierBasedStateCoderFactory | 20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.IdentifierBasedStateCoderFactory |
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.NeighbourhoodBasedHashStateCoderFactory | ||
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.PairwiseNeighbourhoodBasedStateCoderFactory | 22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.PairwiseNeighbourhoodBasedStateCoderFactory |
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.BasicScopeGlobalConstraint | ||
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.BestFirstStrategyForModelGeneration | 24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.BestFirstStrategyForModelGeneration |
22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.DiversityChecker | 25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.DiversityChecker |
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.InconsistentScopeGlobalConstraint | 26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.InconsistentScopeGlobalConstraint |
@@ -39,7 +42,6 @@ import org.eclipse.viatra.dse.api.DesignSpaceExplorer | |||
39 | import org.eclipse.viatra.dse.api.DesignSpaceExplorer.DseLoggingLevel | 42 | import org.eclipse.viatra.dse.api.DesignSpaceExplorer.DseLoggingLevel |
40 | import org.eclipse.viatra.dse.solutionstore.SolutionStore | 43 | import org.eclipse.viatra.dse.solutionstore.SolutionStore |
41 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory | 44 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory |
42 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder.NeighbourhoodBasedStateCoderFactory | ||
43 | 45 | ||
44 | class ViatraReasoner extends LogicReasoner { | 46 | class ViatraReasoner extends LogicReasoner { |
45 | val PartialInterpretationInitialiser initialiser = new PartialInterpretationInitialiser() | 47 | val PartialInterpretationInitialiser initialiser = new PartialInterpretationInitialiser() |
@@ -71,6 +73,11 @@ class ViatraReasoner extends LogicReasoner { | |||
71 | workspace.writeModel(emptySolution, "init.partialmodel") | 73 | workspace.writeModel(emptySolution, "init.partialmodel") |
72 | } | 74 | } |
73 | emptySolution.problemConainer = problem | 75 | emptySolution.problemConainer = problem |
76 | var BasicScopeGlobalConstraint basicScopeGlobalConstraint = null | ||
77 | if (viatraConfig.scopePropagatorStrategy == ScopePropagatorStrategy.None) { | ||
78 | basicScopeGlobalConstraint = new BasicScopeGlobalConstraint(emptySolution) | ||
79 | emptySolution.scopes.clear | ||
80 | } | ||
74 | 81 | ||
75 | val method = modelGenerationMethodProvider.createModelGenerationMethod( | 82 | val method = modelGenerationMethodProvider.createModelGenerationMethod( |
76 | problem, | 83 | problem, |
@@ -79,11 +86,12 @@ class ViatraReasoner extends LogicReasoner { | |||
79 | viatraConfig.nameNewElements, | 86 | viatraConfig.nameNewElements, |
80 | viatraConfig.typeInferenceMethod, | 87 | viatraConfig.typeInferenceMethod, |
81 | viatraConfig.scopePropagatorStrategy, | 88 | viatraConfig.scopePropagatorStrategy, |
89 | viatraConfig.hints, | ||
82 | viatraConfig.documentationLevel | 90 | viatraConfig.documentationLevel |
83 | ) | 91 | ) |
84 | 92 | ||
85 | dse.addObjective(new ModelGenerationCompositeObjective( | 93 | dse.addObjective(new ModelGenerationCompositeObjective( |
86 | new ScopeObjective, | 94 | basicScopeGlobalConstraint ?: new ScopeObjective, |
87 | method.unfinishedMultiplicities.map[new UnfinishedMultiplicityObjective(it)], | 95 | method.unfinishedMultiplicities.map[new UnfinishedMultiplicityObjective(it)], |
88 | wf2ObjectiveConverter.createCompletenessObjective(method.unfinishedWF) | 96 | wf2ObjectiveConverter.createCompletenessObjective(method.unfinishedWF) |
89 | )) | 97 | )) |
@@ -132,6 +140,9 @@ class ViatraReasoner extends LogicReasoner { | |||
132 | dse.addGlobalConstraint(wf2ObjectiveConverter.createInvalidationGlobalConstraint(method.invalidWF)) | 140 | dse.addGlobalConstraint(wf2ObjectiveConverter.createInvalidationGlobalConstraint(method.invalidWF)) |
133 | dse.addGlobalConstraint(new SurelyViolatedObjectiveGlobalConstraint(solutionSaver)) | 141 | dse.addGlobalConstraint(new SurelyViolatedObjectiveGlobalConstraint(solutionSaver)) |
134 | dse.addGlobalConstraint(new InconsistentScopeGlobalConstraint) | 142 | dse.addGlobalConstraint(new InconsistentScopeGlobalConstraint) |
143 | if (basicScopeGlobalConstraint !== null) { | ||
144 | dse.addGlobalConstraint(basicScopeGlobalConstraint) | ||
145 | } | ||
135 | for (additionalConstraint : viatraConfig.searchSpaceConstraints.additionalGlobalConstraints) { | 146 | for (additionalConstraint : viatraConfig.searchSpaceConstraints.additionalGlobalConstraints) { |
136 | dse.addGlobalConstraint(additionalConstraint.apply(method)) | 147 | dse.addGlobalConstraint(additionalConstraint.apply(method)) |
137 | } | 148 | } |
@@ -140,7 +151,7 @@ class ViatraReasoner extends LogicReasoner { | |||
140 | 151 | ||
141 | val IStateCoderFactory statecoder = switch (viatraConfig.stateCoderStrategy) { | 152 | val IStateCoderFactory statecoder = switch (viatraConfig.stateCoderStrategy) { |
142 | case Neighbourhood: | 153 | case Neighbourhood: |
143 | new NeighbourhoodBasedStateCoderFactory | 154 | new NeighbourhoodBasedHashStateCoderFactory |
144 | case PairwiseNeighbourhood: | 155 | case PairwiseNeighbourhood: |
145 | new PairwiseNeighbourhoodBasedStateCoderFactory | 156 | new PairwiseNeighbourhoodBasedStateCoderFactory |
146 | default: | 157 | default: |
@@ -216,9 +227,17 @@ class ViatraReasoner extends LogicReasoner { | |||
216 | it.value = method.statistics.decisionsTried | 227 | it.value = method.statistics.decisionsTried |
217 | ] | 228 | ] |
218 | it.entries += createIntStatisticEntry => [ | 229 | it.entries += createIntStatisticEntry => [ |
230 | it.name = "Transformations" | ||
231 | it.value = method.statistics.transformationInvocations | ||
232 | ] | ||
233 | it.entries += createIntStatisticEntry => [ | ||
219 | it.name = "ScopePropagations" | 234 | it.name = "ScopePropagations" |
220 | it.value = method.statistics.scopePropagatorInvocations | 235 | it.value = method.statistics.scopePropagatorInvocations |
221 | ] | 236 | ] |
237 | it.entries += createIntStatisticEntry => [ | ||
238 | it.name = "ScopePropagationsSolverCalls" | ||
239 | it.value = method.statistics.scopePropagatorSolverInvocations | ||
240 | ] | ||
222 | if (diversityChecker.isActive) { | 241 | if (diversityChecker.isActive) { |
223 | it.entries += createIntStatisticEntry => [ | 242 | it.entries += createIntStatisticEntry => [ |
224 | it.name = "SolutionDiversityCheckTime" | 243 | it.name = "SolutionDiversityCheckTime" |
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 a5f42a5f..6f38d261 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 | |||
@@ -16,6 +16,7 @@ import java.util.LinkedList | |||
16 | import java.util.List | 16 | import java.util.List |
17 | import java.util.Set | 17 | import java.util.Set |
18 | import org.eclipse.xtext.xbase.lib.Functions.Function1 | 18 | import org.eclipse.xtext.xbase.lib.Functions.Function1 |
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeConstraintHint | ||
19 | 20 | ||
20 | enum StateCoderStrategy { | 21 | enum StateCoderStrategy { |
21 | Neighbourhood, | 22 | Neighbourhood, |
@@ -56,6 +57,8 @@ class ViatraReasonerConfiguration extends LogicSolverConfiguration { | |||
56 | 57 | ||
57 | public var ScopePropagatorStrategy scopePropagatorStrategy = new ScopePropagatorStrategy.Polyhedral( | 58 | public var ScopePropagatorStrategy scopePropagatorStrategy = new ScopePropagatorStrategy.Polyhedral( |
58 | PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp) | 59 | PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp) |
60 | |||
61 | public var List<LinearTypeConstraintHint> hints = newArrayList | ||
59 | 62 | ||
60 | public var List<CostObjectiveConfiguration> costObjectives = newArrayList | 63 | public var List<CostObjectiveConfiguration> costObjectives = newArrayList |
61 | } | 64 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BasicScopeGlobalConstraint.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BasicScopeGlobalConstraint.xtend new file mode 100644 index 00000000..67f447ed --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BasicScopeGlobalConstraint.xtend | |||
@@ -0,0 +1,103 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse | ||
2 | |||
3 | import com.google.common.collect.ImmutableList | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
6 | import java.util.Comparator | ||
7 | import java.util.List | ||
8 | import org.eclipse.viatra.dse.base.ThreadContext | ||
9 | import org.eclipse.viatra.dse.objectives.Comparators | ||
10 | import org.eclipse.viatra.dse.objectives.IGlobalConstraint | ||
11 | import org.eclipse.viatra.dse.objectives.IObjective | ||
12 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
13 | |||
14 | class BasicScopeGlobalConstraint implements IGlobalConstraint, IObjective { | ||
15 | val PartialInterpretation p | ||
16 | val List<ScopeAssertion> assertions | ||
17 | |||
18 | new(PartialInterpretation p) { | ||
19 | this.p = p | ||
20 | assertions = ImmutableList.copyOf(p.scopes.map [ | ||
21 | val currentSize = targetTypeInterpretation.elements.size | ||
22 | val minElements = minNewElements + currentSize | ||
23 | val maxElements = if (maxNewElements < 0) { | ||
24 | -1 | ||
25 | } else { | ||
26 | maxNewElements + currentSize | ||
27 | } | ||
28 | new ScopeAssertion(minElements, maxElements, targetTypeInterpretation) | ||
29 | ]) | ||
30 | } | ||
31 | |||
32 | override init(ThreadContext context) { | ||
33 | if (context.model != p) { | ||
34 | throw new IllegalArgumentException( | ||
35 | "Partial model must be passed to the constructor of BasicScopeGlobalConstraint") | ||
36 | } | ||
37 | } | ||
38 | |||
39 | override checkGlobalConstraint(ThreadContext context) { | ||
40 | assertions.forall[upperBoundSatisfied] | ||
41 | } | ||
42 | |||
43 | override getFitness(ThreadContext context) { | ||
44 | var double fitness = p.minNewElements | ||
45 | for (assertion : assertions) { | ||
46 | if (!assertion.lowerBoundSatisfied) { | ||
47 | fitness += 1 | ||
48 | } | ||
49 | } | ||
50 | fitness | ||
51 | } | ||
52 | |||
53 | override satisifiesHardObjective(Double fitness) { | ||
54 | fitness <= 0.01 | ||
55 | } | ||
56 | |||
57 | override BasicScopeGlobalConstraint createNew() { | ||
58 | this | ||
59 | } | ||
60 | |||
61 | override getName() { | ||
62 | class.name | ||
63 | } | ||
64 | |||
65 | override getComparator() { | ||
66 | Comparators.LOWER_IS_BETTER | ||
67 | } | ||
68 | |||
69 | override getLevel() { | ||
70 | 2 | ||
71 | } | ||
72 | |||
73 | override isHardObjective() { | ||
74 | true | ||
75 | } | ||
76 | |||
77 | override setComparator(Comparator<Double> comparator) { | ||
78 | throw new UnsupportedOperationException | ||
79 | } | ||
80 | |||
81 | override setLevel(int level) { | ||
82 | throw new UnsupportedOperationException | ||
83 | } | ||
84 | |||
85 | @FinalFieldsConstructor | ||
86 | private static class ScopeAssertion { | ||
87 | val int lowerBound | ||
88 | val int upperBound | ||
89 | val PartialTypeInterpratation typeDefinitions | ||
90 | |||
91 | private def getCount() { | ||
92 | typeDefinitions.elements.size | ||
93 | } | ||
94 | |||
95 | private def isLowerBoundSatisfied() { | ||
96 | count >= lowerBound | ||
97 | } | ||
98 | |||
99 | private def isUpperBoundSatisfied() { | ||
100 | upperBound < 0 || count <= upperBound | ||
101 | } | ||
102 | } | ||
103 | } | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java index 5af7fc69..081e48fa 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | |||
@@ -255,7 +255,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
255 | activationIds = new ArrayList<Object>(context.getUntraversedActivationIds()); | 255 | activationIds = new ArrayList<Object>(context.getUntraversedActivationIds()); |
256 | Collections.shuffle(activationIds); | 256 | Collections.shuffle(activationIds); |
257 | } catch (NullPointerException e) { | 257 | } catch (NullPointerException e) { |
258 | logger.warn("Unexpected state code: " + context.getDesignSpaceManager().getCurrentState()); | 258 | // logger.warn("Unexpected state code: " + context.getDesignSpaceManager().getCurrentState()); |
259 | numberOfStatecoderFail++; | 259 | numberOfStatecoderFail++; |
260 | activationIds = Collections.emptyList(); | 260 | activationIds = Collections.emptyList(); |
261 | } | 261 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend index 9a33753c..2976bebe 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend | |||
@@ -59,7 +59,7 @@ class ModelGenerationCompositeObjective implements IThreeValuedObjective { | |||
59 | } | 59 | } |
60 | sum += multiplicity | 60 | sum += multiplicity |
61 | sum += unfinishedWFsFitness // *0.5 | 61 | sum += unfinishedWFsFitness // *0.5 |
62 | // println('''Sum=«sum»|Scope=«scopeFitnes»|Multiplicity=«multiplicity»|WFs=«unfinishedWFsFitness»''') | 62 | // println('''Sum=«sum»|Scope=«scopeFitnes»|Multiplicity=«multiplicity»|WFs=«unfinishedWFsFitness»''') |
63 | return sum | 63 | return sum |
64 | } | 64 | } |
65 | 65 | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ScopeObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ScopeObjective.xtend index 69efe0d7..e7967b00 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ScopeObjective.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ScopeObjective.xtend | |||
@@ -23,9 +23,9 @@ class ScopeObjective implements IObjective{ | |||
23 | 23 | ||
24 | override getFitness(ThreadContext context) { | 24 | override getFitness(ThreadContext context) { |
25 | val interpretation = context.model as PartialInterpretation | 25 | val interpretation = context.model as PartialInterpretation |
26 | var res = interpretation.minNewElements.doubleValue | 26 | var res = interpretation.minNewElementsHeuristic.doubleValue |
27 | for(scope : interpretation.scopes) { | 27 | for(scope : interpretation.scopes) { |
28 | res += scope.minNewElements*2 | 28 | res += scope.minNewElementsHeuristic*2 |
29 | } | 29 | } |
30 | return res | 30 | return res |
31 | } | 31 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend index bf34aeeb..1b61ffa5 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/UnfinishedWFObjective.xtend | |||
@@ -14,41 +14,51 @@ import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | |||
14 | class UnfinishedWFObjective implements IObjective { | 14 | class UnfinishedWFObjective implements IObjective { |
15 | Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFs | 15 | Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFs |
16 | val List<ViatraQueryMatcher<?>> matchers | 16 | val List<ViatraQueryMatcher<?>> matchers |
17 | 17 | ||
18 | new(Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFs) { | 18 | new( |
19 | Collection<? extends IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> unfinishedWFs) { | ||
19 | this.unfinishedWFs = unfinishedWFs | 20 | this.unfinishedWFs = unfinishedWFs |
20 | matchers = new ArrayList(unfinishedWFs.size) | 21 | matchers = new ArrayList(unfinishedWFs.size) |
21 | } | 22 | } |
23 | |||
22 | override getName() '''unfinishedWFs''' | 24 | override getName() '''unfinishedWFs''' |
25 | |||
23 | override createNew() { | 26 | override createNew() { |
24 | return new UnfinishedWFObjective(unfinishedWFs) | 27 | return new UnfinishedWFObjective(unfinishedWFs) |
25 | } | 28 | } |
29 | |||
26 | override init(ThreadContext context) { | 30 | override init(ThreadContext context) { |
27 | val engine = context.queryEngine//ViatraQueryEngine.on(new EMFScope(context.model)) | 31 | val engine = context.queryEngine // ViatraQueryEngine.on(new EMFScope(context.model)) |
28 | for(unfinishedWF : unfinishedWFs) { | 32 | for (unfinishedWF : unfinishedWFs) { |
29 | matchers += unfinishedWF.getMatcher(engine) | 33 | matchers += unfinishedWF.getMatcher(engine) |
30 | } | 34 | } |
31 | } | 35 | } |
32 | 36 | ||
33 | override getComparator() { Comparators.LOWER_IS_BETTER } | 37 | override getComparator() { Comparators.LOWER_IS_BETTER } |
38 | |||
34 | override getFitness(ThreadContext context) { | 39 | override getFitness(ThreadContext context) { |
35 | var sumOfMatches = 0 | 40 | var sumOfMatches = 0 |
36 | for(matcher : matchers) { | 41 | for (matcher : matchers) { |
37 | val number = matcher.countMatches | 42 | val number = matcher.countMatches |
38 | //println('''«matcher.patternName» = «number»''') | 43 | // if (number > 0) { |
39 | sumOfMatches+=number | 44 | // println('''«matcher.patternName» = «number»''') |
45 | // } | ||
46 | sumOfMatches += number | ||
40 | } | 47 | } |
41 | return sumOfMatches.doubleValue | 48 | return sumOfMatches.doubleValue |
42 | } | 49 | } |
43 | 50 | ||
44 | override getLevel() { 2 } | 51 | override getLevel() { 2 } |
52 | |||
45 | override isHardObjective() { true } | 53 | override isHardObjective() { true } |
46 | override satisifiesHardObjective(Double fitness) { return fitness <=0.01 } | 54 | |
47 | 55 | override satisifiesHardObjective(Double fitness) { return fitness <= 0.01 } | |
56 | |||
48 | override setComparator(Comparator<Double> comparator) { | 57 | override setComparator(Comparator<Double> comparator) { |
49 | throw new UnsupportedOperationException() | 58 | throw new UnsupportedOperationException() |
50 | } | 59 | } |
60 | |||
51 | override setLevel(int level) { | 61 | override setLevel(int level) { |
52 | throw new UnsupportedOperationException() | 62 | throw new UnsupportedOperationException() |
53 | } | 63 | } |
54 | } \ No newline at end of file | 64 | } |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ViatraReasonerSolutionSaver.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ViatraReasonerSolutionSaver.xtend index 6bffeb59..74500cc2 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ViatraReasonerSolutionSaver.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ViatraReasonerSolutionSaver.xtend | |||
@@ -42,7 +42,7 @@ class ViatraReasonerSolutionSaver implements ISolutionSaver { | |||
42 | 42 | ||
43 | private def saveBestSolutionOnly(ThreadContext context, Object id, SolutionTrajectory solutionTrajectory) { | 43 | private def saveBestSolutionOnly(ThreadContext context, Object id, SolutionTrajectory solutionTrajectory) { |
44 | val fitness = context.lastFitness | 44 | val fitness = context.lastFitness |
45 | if (!fitness.satisifiesHardObjectives) { | 45 | if (!shouldSaveSolution(fitness, context)) { |
46 | return false | 46 | return false |
47 | } | 47 | } |
48 | val dominatedTrajectories = newArrayList | 48 | val dominatedTrajectories = newArrayList |
@@ -83,7 +83,7 @@ class ViatraReasonerSolutionSaver implements ISolutionSaver { | |||
83 | 83 | ||
84 | private def saveAnyDiverseSolution(ThreadContext context, Object id, SolutionTrajectory solutionTrajectory) { | 84 | private def saveAnyDiverseSolution(ThreadContext context, Object id, SolutionTrajectory solutionTrajectory) { |
85 | val fitness = context.lastFitness | 85 | val fitness = context.lastFitness |
86 | if (!fitness.satisifiesHardObjectives) { | 86 | if (!shouldSaveSolution(fitness, context)) { |
87 | return false | 87 | return false |
88 | } | 88 | } |
89 | if (!diversityChecker.newSolution(context, id, emptyList)) { | 89 | if (!diversityChecker.newSolution(context, id, emptyList)) { |
@@ -92,7 +92,12 @@ class ViatraReasonerSolutionSaver implements ISolutionSaver { | |||
92 | basicSaveSolution(context, id, solutionTrajectory, fitness) | 92 | basicSaveSolution(context, id, solutionTrajectory, fitness) |
93 | } | 93 | } |
94 | 94 | ||
95 | private def basicSaveSolution(ThreadContext context, Object id, SolutionTrajectory solutionTrajectory, Fitness fitness) { | 95 | private def shouldSaveSolution(Fitness fitness, ThreadContext context) { |
96 | return fitness.satisifiesHardObjectives | ||
97 | } | ||
98 | |||
99 | private def basicSaveSolution(ThreadContext context, Object id, SolutionTrajectory solutionTrajectory, | ||
100 | Fitness fitness) { | ||
96 | var boolean solutionSaved = false | 101 | var boolean solutionSaved = false |
97 | var dseSolution = solutionsCollection.get(id) | 102 | var dseSolution = solutionsCollection.get(id) |
98 | if (dseSolution === null) { | 103 | if (dseSolution === null) { |