diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-06-25 19:55:10 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-06-25 19:55:10 +0200 |
commit | c3a6d4b9cf3657070d180aa65ddbf0459e880329 (patch) | |
tree | 780c4fc61578dcb309af53fb0c164c7627e51676 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionCopier.xtend | |
parent | New configuration language parser WIP (diff) | |
parent | Scope unsat benchmarks (diff) | |
download | VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.gz VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.zst VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.zip |
Merge branch 'kris'
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionCopier.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionCopier.xtend | 86 |
1 files changed, 86 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/SolutionCopier.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionCopier.xtend new file mode 100644 index 00000000..38c8f5a1 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionCopier.xtend | |||
@@ -0,0 +1,86 @@ | |||
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 java.util.LinkedHashMap | ||
6 | import java.util.List | ||
7 | import java.util.Map | ||
8 | import org.eclipse.emf.ecore.EObject | ||
9 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
10 | import org.eclipse.viatra.dse.base.ThreadContext | ||
11 | import org.eclipse.xtend.lib.annotations.Accessors | ||
12 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
13 | |||
14 | @FinalFieldsConstructor | ||
15 | class CopiedSolution { | ||
16 | @Accessors val PartialInterpretation partialInterpretations | ||
17 | @Accessors val Map<EObject, EObject> trace | ||
18 | @Accessors val long copierRuntime | ||
19 | @Accessors var boolean current = true | ||
20 | } | ||
21 | |||
22 | /** | ||
23 | * Based on {@link SolutionStore.BestSolutionSaver}. | ||
24 | * | ||
25 | * Will also automatically fill any missing numerical values in the saved solutions | ||
26 | * using the supplied {@link NumericSolver}. | ||
27 | */ | ||
28 | class SolutionCopier { | ||
29 | val NumericSolver numericSolver | ||
30 | val copiedSolutions = new LinkedHashMap<Object, CopiedSolution> | ||
31 | |||
32 | long startTime = System.nanoTime | ||
33 | @Accessors(PUBLIC_GETTER) long totalCopierRuntime = 0 | ||
34 | |||
35 | new(NumericSolver numericSolver) { | ||
36 | this.numericSolver = numericSolver | ||
37 | } | ||
38 | |||
39 | def void copySolution(ThreadContext context, Object solutionId) { | ||
40 | val existingCopy = copiedSolutions.get(solutionId) | ||
41 | if (existingCopy === null) { | ||
42 | val copyStart = System.nanoTime | ||
43 | val solution = context.model as PartialInterpretation | ||
44 | val copier = new EcoreUtil.Copier | ||
45 | val copiedPartialInterpretation = copier.copy(solution) as PartialInterpretation | ||
46 | copier.copyReferences | ||
47 | totalCopierRuntime += System.nanoTime - copyStart | ||
48 | val copierRuntime = System.nanoTime - startTime | ||
49 | val copiedSolution = new CopiedSolution(copiedPartialInterpretation, copier, copierRuntime) | ||
50 | numericSolver.fillSolutionCopy(copiedSolution.trace) | ||
51 | copiedSolutions.put(solutionId, copiedSolution) | ||
52 | } else { | ||
53 | existingCopy.current = true | ||
54 | } | ||
55 | } | ||
56 | |||
57 | def void markAsObsolete(Object solutionId) { | ||
58 | val copiedSolution = copiedSolutions.get(solutionId) | ||
59 | if (copiedSolution === null) { | ||
60 | throw new IllegalStateException("No solution to mark as obsolete for state code: " + solutionId) | ||
61 | } | ||
62 | copiedSolution.current = false | ||
63 | } | ||
64 | |||
65 | def List<PartialInterpretation> getPartialInterpretations(boolean currentOnly) { | ||
66 | getListOfCopiedSolutions(currentOnly).map[partialInterpretations] | ||
67 | } | ||
68 | |||
69 | def List<Map<EObject, EObject>> getTraces(boolean currentOnly) { | ||
70 | getListOfCopiedSolutions(currentOnly).map[trace] | ||
71 | } | ||
72 | |||
73 | def List<Long> getAllCopierRuntimes(boolean currentOnly) { | ||
74 | getListOfCopiedSolutions(currentOnly).map[copierRuntime] | ||
75 | } | ||
76 | |||
77 | def List<CopiedSolution> getListOfCopiedSolutions(boolean currentOnly) { | ||
78 | val values = copiedSolutions.values | ||
79 | val filteredSolutions = if (currentOnly) { | ||
80 | values.filter[current] | ||
81 | } else { | ||
82 | values | ||
83 | } | ||
84 | ImmutableList.copyOf(filteredSolutions) | ||
85 | } | ||
86 | } | ||