diff options
Diffstat (limited to 'subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java')
-rw-r--r-- | subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java index e7e26cb2..6cdb287d 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java | |||
@@ -5,10 +5,14 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.reasoning.translator; | 6 | package tools.refinery.store.reasoning.translator; |
7 | 7 | ||
8 | import org.jetbrains.annotations.Nullable; | ||
9 | import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder; | ||
10 | import tools.refinery.store.dse.transition.Rule; | ||
11 | import tools.refinery.store.dse.transition.objectives.Criterion; | ||
12 | import tools.refinery.store.dse.transition.objectives.Objective; | ||
8 | import tools.refinery.store.model.ModelStoreBuilder; | 13 | import tools.refinery.store.model.ModelStoreBuilder; |
9 | import tools.refinery.store.reasoning.ReasoningBuilder; | 14 | import tools.refinery.store.reasoning.ReasoningBuilder; |
10 | import tools.refinery.store.reasoning.interpretation.PartialInterpretation; | 15 | import tools.refinery.store.reasoning.interpretation.PartialInterpretation; |
11 | import tools.refinery.store.reasoning.literal.Concreteness; | ||
12 | import tools.refinery.store.reasoning.refinement.PartialInterpretationRefiner; | 16 | import tools.refinery.store.reasoning.refinement.PartialInterpretationRefiner; |
13 | import tools.refinery.store.reasoning.refinement.PartialModelInitializer; | 17 | import tools.refinery.store.reasoning.refinement.PartialModelInitializer; |
14 | import tools.refinery.store.reasoning.refinement.StorageRefiner; | 18 | import tools.refinery.store.reasoning.refinement.StorageRefiner; |
@@ -17,7 +21,8 @@ import tools.refinery.store.reasoning.seed.SeedInitializer; | |||
17 | import tools.refinery.store.representation.AnySymbol; | 21 | import tools.refinery.store.representation.AnySymbol; |
18 | import tools.refinery.store.representation.Symbol; | 22 | import tools.refinery.store.representation.Symbol; |
19 | 23 | ||
20 | import java.util.Set; | 24 | import java.util.ArrayList; |
25 | import java.util.List; | ||
21 | 26 | ||
22 | @SuppressWarnings("UnusedReturnValue") | 27 | @SuppressWarnings("UnusedReturnValue") |
23 | public abstract sealed class PartialSymbolTranslator<A, C> implements AnyPartialSymbolTranslator | 28 | public abstract sealed class PartialSymbolTranslator<A, C> implements AnyPartialSymbolTranslator |
@@ -29,6 +34,13 @@ public abstract sealed class PartialSymbolTranslator<A, C> implements AnyPartial | |||
29 | protected StorageRefiner.Factory<?> storageRefiner; | 34 | protected StorageRefiner.Factory<?> storageRefiner; |
30 | protected PartialInterpretation.Factory<A, C> interpretationFactory; | 35 | protected PartialInterpretation.Factory<A, C> interpretationFactory; |
31 | protected PartialModelInitializer initializer; | 36 | protected PartialModelInitializer initializer; |
37 | protected List<Rule> decisionRules = new ArrayList<>(); | ||
38 | protected boolean acceptWasSet; | ||
39 | protected @Nullable Criterion accept; | ||
40 | protected boolean excludeWasSet; | ||
41 | protected @Nullable Criterion exclude; | ||
42 | protected boolean objectiveWasSet; | ||
43 | protected @Nullable Objective objective; | ||
32 | 44 | ||
33 | PartialSymbolTranslator(PartialSymbol<A, C> partialSymbol) { | 45 | PartialSymbolTranslator(PartialSymbol<A, C> partialSymbol) { |
34 | this.partialSymbol = partialSymbol; | 46 | this.partialSymbol = partialSymbol; |
@@ -102,6 +114,38 @@ public abstract sealed class PartialSymbolTranslator<A, C> implements AnyPartial | |||
102 | return this; | 114 | return this; |
103 | } | 115 | } |
104 | 116 | ||
117 | public PartialSymbolTranslator<A, C> decision(Rule decisionRule) { | ||
118 | decisionRules.add(decisionRule); | ||
119 | return this; | ||
120 | } | ||
121 | |||
122 | public PartialSymbolTranslator<A, C> accept(@Nullable Criterion acceptanceCriterion) { | ||
123 | if (acceptWasSet) { | ||
124 | throw new IllegalStateException("Accept was already set"); | ||
125 | } | ||
126 | this.accept = acceptanceCriterion; | ||
127 | acceptWasSet = true; | ||
128 | return this; | ||
129 | } | ||
130 | |||
131 | public PartialSymbolTranslator<A, C> exclude(@Nullable Criterion exclusionCriterion) { | ||
132 | if (excludeWasSet) { | ||
133 | throw new IllegalStateException("Exclude was already set"); | ||
134 | } | ||
135 | this.exclude = exclusionCriterion; | ||
136 | excludeWasSet = true; | ||
137 | return this; | ||
138 | } | ||
139 | |||
140 | public PartialSymbolTranslator<A, C> objective(Objective objective) { | ||
141 | if (objectiveWasSet) { | ||
142 | throw new IllegalStateException("Objective was already set"); | ||
143 | } | ||
144 | this.objective = objective; | ||
145 | objectiveWasSet = true; | ||
146 | return this; | ||
147 | } | ||
148 | |||
105 | @Override | 149 | @Override |
106 | public void configure(ModelStoreBuilder storeBuilder) { | 150 | public void configure(ModelStoreBuilder storeBuilder) { |
107 | checkNotConfigured(); | 151 | checkNotConfigured(); |
@@ -124,6 +168,18 @@ public abstract sealed class PartialSymbolTranslator<A, C> implements AnyPartial | |||
124 | if (initializer != null) { | 168 | if (initializer != null) { |
125 | reasoningBuilder.initializer(initializer); | 169 | reasoningBuilder.initializer(initializer); |
126 | } | 170 | } |
171 | storeBuilder.tryGetAdapter(DesignSpaceExplorationBuilder.class).ifPresent(dseBuilder -> { | ||
172 | dseBuilder.transformations(decisionRules); | ||
173 | if (accept != null) { | ||
174 | dseBuilder.accept(accept); | ||
175 | } | ||
176 | if (exclude != null) { | ||
177 | dseBuilder.exclude(exclude); | ||
178 | } | ||
179 | }); | ||
180 | if (objective != null) { | ||
181 | reasoningBuilder.objective(objective); | ||
182 | } | ||
127 | } | 183 | } |
128 | 184 | ||
129 | private <T> void registerStorageRefiner(ReasoningBuilder reasoningBuilder, StorageRefiner.Factory<T> factory) { | 185 | private <T> void registerStorageRefiner(ReasoningBuilder reasoningBuilder, StorageRefiner.Factory<T> factory) { |