diff options
Diffstat (limited to 'subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/statespace/internal/ActivationStoreWorker.java')
-rw-r--r-- | subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/statespace/internal/ActivationStoreWorker.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/statespace/internal/ActivationStoreWorker.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/statespace/internal/ActivationStoreWorker.java new file mode 100644 index 00000000..1d7c5ce5 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/statespace/internal/ActivationStoreWorker.java | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.dse.transition.statespace.internal; | ||
7 | |||
8 | import tools.refinery.store.dse.transition.Transformation; | ||
9 | import tools.refinery.store.dse.transition.VersionWithObjectiveValue; | ||
10 | import tools.refinery.store.dse.transition.statespace.ActivationStore; | ||
11 | |||
12 | import java.util.List; | ||
13 | import java.util.Random; | ||
14 | |||
15 | public class ActivationStoreWorker { | ||
16 | final ActivationStore store; | ||
17 | final List<Transformation> transformations; | ||
18 | |||
19 | public ActivationStoreWorker(ActivationStore store, List<Transformation> transformations) { | ||
20 | this.store = store; | ||
21 | this.transformations = transformations; | ||
22 | } | ||
23 | |||
24 | public int[] calculateEmptyActivationSize() { | ||
25 | int[] result = new int[transformations.size()]; | ||
26 | for (int i = 0; i < result.length; i++) { | ||
27 | result[i] = transformations.get(i).getAllActivationsAsResultSet().size(); | ||
28 | } | ||
29 | return result; | ||
30 | } | ||
31 | |||
32 | |||
33 | public ActivationStore.VisitResult fireRandomActivation(VersionWithObjectiveValue thisVersion, Random random) { | ||
34 | var result = store.getRandomAndMarkAsVisited(thisVersion, random); | ||
35 | if (result.successfulVisit()) { | ||
36 | int selectedTransformation = result.transformation(); | ||
37 | int selectedActivation = result.activation(); | ||
38 | |||
39 | Transformation transformation = transformations.get(selectedTransformation); | ||
40 | var tuple = transformation.getActivation(selectedActivation); | ||
41 | |||
42 | boolean success = transformation.fireActivation(tuple); | ||
43 | if (success) { | ||
44 | return result; | ||
45 | } else { | ||
46 | return new ActivationStore.VisitResult( | ||
47 | false, | ||
48 | result.mayHaveMore(), | ||
49 | selectedTransformation, | ||
50 | selectedActivation); | ||
51 | } | ||
52 | } | ||
53 | return result; | ||
54 | } | ||
55 | } | ||