diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend | 33 |
1 files changed, 32 insertions, 1 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 8831b0ff..6898550d 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 | |||
@@ -1,5 +1,7 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner |
2 | 2 | ||
3 | import com.google.common.collect.ImmutableList | ||
4 | import com.google.common.collect.Lists | ||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | 5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel |
4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner | 6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasonerException | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasonerException |
@@ -25,6 +27,8 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.SurelyViolatedObject | |||
25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.UnfinishedMultiplicityObjective | 27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.UnfinishedMultiplicityObjective |
26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ViatraReasonerSolutionSaver | 28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.ViatraReasonerSolutionSaver |
27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.WF2ObjectiveConverter | 29 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.WF2ObjectiveConverter |
30 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ThreeValuedCostElement | ||
31 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ThreeValuedCostObjective | ||
28 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | 32 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace |
29 | import java.util.List | 33 | import java.util.List |
30 | import java.util.Map | 34 | import java.util.Map |
@@ -84,9 +88,36 @@ class ViatraReasoner extends LogicReasoner { | |||
84 | wf2ObjectiveConverter.createCompletenessObjective(method.unfinishedWF) | 88 | wf2ObjectiveConverter.createCompletenessObjective(method.unfinishedWF) |
85 | )) | 89 | )) |
86 | 90 | ||
91 | val extermalObjectives = Lists.newArrayListWithExpectedSize(viatraConfig.costObjectives.size) | ||
92 | for (entry : viatraConfig.costObjectives.indexed) { | ||
93 | val objectiveName = '''costObjective«entry.key»''' | ||
94 | val objectiveConfig = entry.value | ||
95 | val elementsBuilder = ImmutableList.builder | ||
96 | for (elementConfig : objectiveConfig.elements) { | ||
97 | val relationName = elementConfig.patternQualifiedName | ||
98 | val modalQueries = method.modalRelationQueries.get(relationName) | ||
99 | if (modalQueries === null) { | ||
100 | throw new IllegalArgumentException("Unknown relation: " + relationName) | ||
101 | } | ||
102 | elementsBuilder.add(new ThreeValuedCostElement( | ||
103 | modalQueries.currentQuery, | ||
104 | modalQueries.mayQuery, | ||
105 | modalQueries.mustQuery, | ||
106 | elementConfig.weight | ||
107 | )) | ||
108 | } | ||
109 | val costElements = elementsBuilder.build | ||
110 | val costObjective = new ThreeValuedCostObjective(objectiveName, costElements, objectiveConfig.kind, | ||
111 | objectiveConfig.threshold, 3) | ||
112 | dse.addObjective(costObjective) | ||
113 | if (objectiveConfig.findExtremum) { | ||
114 | extermalObjectives += costObjective | ||
115 | } | ||
116 | } | ||
117 | |||
87 | val solutionStore = new SolutionStore(configuration.solutionScope.numberOfRequiredSolutions) | 118 | val solutionStore = new SolutionStore(configuration.solutionScope.numberOfRequiredSolutions) |
88 | solutionStore.registerSolutionFoundHandler(new LoggerSolutionFoundHandler(viatraConfig)) | 119 | solutionStore.registerSolutionFoundHandler(new LoggerSolutionFoundHandler(viatraConfig)) |
89 | val solutionSaver = new ViatraReasonerSolutionSaver(newArrayOfSize(0, 0)) | 120 | val solutionSaver = new ViatraReasonerSolutionSaver(newArrayList(extermalObjectives)) |
90 | val solutionCopier = solutionSaver.solutionCopier | 121 | val solutionCopier = solutionSaver.solutionCopier |
91 | solutionStore.withSolutionSaver(solutionSaver) | 122 | solutionStore.withSolutionSaver(solutionSaver) |
92 | dse.solutionStore = solutionStore | 123 | dse.solutionStore = solutionStore |