diff options
5 files changed, 31 insertions, 66 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/DesignSpaceExplorationBuilder.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/DesignSpaceExplorationBuilder.java index 0ec6f599..58eac681 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/DesignSpaceExplorationBuilder.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/DesignSpaceExplorationBuilder.java | |||
@@ -10,15 +10,6 @@ import java.util.Collection; | |||
10 | import java.util.List; | 10 | import java.util.List; |
11 | 11 | ||
12 | public interface DesignSpaceExplorationBuilder extends ModelAdapterBuilder { | 12 | public interface DesignSpaceExplorationBuilder extends ModelAdapterBuilder { |
13 | default DesignSpaceExplorationBuilder stopConditions(AnyQuery... stopConditions) { | ||
14 | return stopConditions(List.of(stopConditions)); | ||
15 | } | ||
16 | |||
17 | default DesignSpaceExplorationBuilder stopConditions(Collection<? extends AnyQuery> stopConditions) { | ||
18 | stopConditions.forEach(this::stopCondition); | ||
19 | return this; | ||
20 | } | ||
21 | |||
22 | default DesignSpaceExplorationBuilder transformations(TransformationRule... transformationRules) { | 13 | default DesignSpaceExplorationBuilder transformations(TransformationRule... transformationRules) { |
23 | return transformations(List.of(transformationRules)); | 14 | return transformations(List.of(transformationRules)); |
24 | } | 15 | } |
@@ -46,8 +37,6 @@ public interface DesignSpaceExplorationBuilder extends ModelAdapterBuilder { | |||
46 | return this; | 37 | return this; |
47 | } | 38 | } |
48 | 39 | ||
49 | DesignSpaceExplorationBuilder stopCondition(AnyQuery stopCondition); | ||
50 | |||
51 | DesignSpaceExplorationBuilder transformation(TransformationRule transformationRule); | 40 | DesignSpaceExplorationBuilder transformation(TransformationRule transformationRule); |
52 | DesignSpaceExplorationBuilder globalConstraint(RelationalQuery globalConstraint); | 41 | DesignSpaceExplorationBuilder globalConstraint(RelationalQuery globalConstraint); |
53 | DesignSpaceExplorationBuilder objective(Objective objective); | 42 | DesignSpaceExplorationBuilder objective(Objective objective); |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationAdapterImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationAdapterImpl.java index 0fcc719d..35f94dce 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationAdapterImpl.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationAdapterImpl.java | |||
@@ -24,20 +24,19 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
24 | private final Model model; | 24 | private final Model model; |
25 | private final ModelQueryAdapter queryEngine; | 25 | private final ModelQueryAdapter queryEngine; |
26 | private final DesignSpaceExplorationStoreAdapterImpl storeAdapter; | 26 | private final DesignSpaceExplorationStoreAdapterImpl storeAdapter; |
27 | private final Set<TransformationRule> transformationRules; | 27 | private final LinkedHashSet<TransformationRule> transformationRules; |
28 | private final Set<RelationalQuery> globalConstraints; | 28 | private final LinkedHashSet<RelationalQuery> globalConstraints; |
29 | private final List<Objective> objectives; | 29 | private final List<Objective> objectives; |
30 | private final Set<ResultSet<Boolean>> globalConstraintResultSets = new HashSet<>(); | 30 | private final LinkedHashSet<ResultSet<Boolean>> globalConstraintResultSets = new LinkedHashSet<>(); |
31 | private final Interpretation<Integer> sizeInterpretation; | 31 | private final Interpretation<Integer> sizeInterpretation; |
32 | private final Strategy strategy; | 32 | private final Strategy strategy; |
33 | 33 | ||
34 | private ObjectiveComparatorHelper objectiveComparatorHelper; | 34 | private ObjectiveComparatorHelper objectiveComparatorHelper; |
35 | private List<Long> trajectory = new LinkedList<>(); | 35 | private List<Long> trajectory = new LinkedList<>(); |
36 | private Fitness lastFitness; | 36 | private Fitness lastFitness; |
37 | private final Set<Long> solutions = new HashSet<>(); | 37 | private final LinkedHashSet<Long> solutions = new LinkedHashSet<>(); |
38 | // private Map<Long, Collection<Activation>> statesAndActivations; | 38 | private Map<Long, LinkedHashSet<Activation>> statesAndUntraversedActivations; |
39 | private Map<Long, Collection<Activation>> statesAndUntraversedActivations; | 39 | private Map<Long, LinkedHashSet<Activation>> statesAndTraversedActivations; |
40 | private Map<Long, Collection<Activation>> statesAndTraversedActivations; | ||
41 | private Random random = new Random(); | 40 | private Random random = new Random(); |
42 | private Objective[][] leveledObjectives; | 41 | private Objective[][] leveledObjectives; |
43 | private boolean isNewState = false; | 42 | private boolean isNewState = false; |
@@ -85,11 +84,11 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
85 | } | 84 | } |
86 | 85 | ||
87 | @Override | 86 | @Override |
88 | public Collection<Long> explore() { | 87 | public LinkedHashSet<Long> explore() { |
89 | var state = model.commit(); | 88 | var state = model.commit(); |
90 | trajectory.add(state); | 89 | trajectory.add(state); |
91 | statesAndUntraversedActivations.put(state, getAllActivations()); | 90 | statesAndUntraversedActivations.put(state, getAllActivations()); |
92 | statesAndTraversedActivations.put(state, new HashSet<>()); | 91 | statesAndTraversedActivations.put(state, new LinkedHashSet<>()); |
93 | strategy.initStrategy(this); | 92 | strategy.initStrategy(this); |
94 | strategy.explore(); | 93 | strategy.explore(); |
95 | return solutions; | 94 | return solutions; |
@@ -196,9 +195,9 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
196 | return trajectory.size() - 1; | 195 | return trajectory.size() - 1; |
197 | } | 196 | } |
198 | 197 | ||
199 | public Collection<Activation> getUntraversedActivations() { | 198 | public LinkedHashSet<Activation> getUntraversedActivations() { |
200 | // return statesAndUntraversedActivations.get(model.getState()); | 199 | // return statesAndUntraversedActivations.get(model.getState()); |
201 | List<Activation> untraversedActivations = new ArrayList<>(); | 200 | LinkedHashSet<Activation> untraversedActivations = new LinkedHashSet<>(); |
202 | for (Activation activation : getAllActivations()) { | 201 | for (Activation activation : getAllActivations()) { |
203 | if (!statesAndTraversedActivations.get(model.getState()).contains(activation)) { | 202 | if (!statesAndTraversedActivations.get(model.getState()).contains(activation)) { |
204 | untraversedActivations.add(activation); | 203 | untraversedActivations.add(activation); |
@@ -227,7 +226,7 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
227 | trajectory.add(newState); | 226 | trajectory.add(newState); |
228 | isNewState = !statesAndUntraversedActivations.containsKey(newState); | 227 | isNewState = !statesAndUntraversedActivations.containsKey(newState); |
229 | statesAndUntraversedActivations.put(newState, getAllActivations()); | 228 | statesAndUntraversedActivations.put(newState, getAllActivations()); |
230 | statesAndTraversedActivations.put(newState, new HashSet<>()); | 229 | statesAndTraversedActivations.put(newState, new LinkedHashSet<>()); |
231 | if (isVisualizationEnabled) { | 230 | if (isVisualizationEnabled) { |
232 | modelVisualizerAdapter.addTransition(trajectory.get(trajectory.size() - 2), | 231 | modelVisualizerAdapter.addTransition(trajectory.get(trajectory.size() - 2), |
233 | trajectory.get(trajectory.size() - 1), activation.transformationRule().getName(), | 232 | trajectory.get(trajectory.size() - 1), activation.transformationRule().getName(), |
@@ -257,8 +256,8 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
257 | return trajectory.contains(model.getState()); | 256 | return trajectory.contains(model.getState()); |
258 | } | 257 | } |
259 | 258 | ||
260 | public Collection<Activation> getAllActivations() { | 259 | public LinkedHashSet<Activation> getAllActivations() { |
261 | Collection<Activation> result = new HashSet<>(); | 260 | LinkedHashSet<Activation> result = new LinkedHashSet<>(); |
262 | for (var rule : transformationRules) { | 261 | for (var rule : transformationRules) { |
263 | result.addAll(rule.getAllActivations()); | 262 | result.addAll(rule.getAllActivations()); |
264 | } | 263 | } |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationBuilderImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationBuilderImpl.java index 79864de0..638ec641 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationBuilderImpl.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationBuilderImpl.java | |||
@@ -3,7 +3,6 @@ package tools.refinery.store.query.dse.internal; | |||
3 | import tools.refinery.store.adapter.AbstractModelAdapterBuilder; | 3 | import tools.refinery.store.adapter.AbstractModelAdapterBuilder; |
4 | import tools.refinery.store.model.ModelStore; | 4 | import tools.refinery.store.model.ModelStore; |
5 | import tools.refinery.store.model.ModelStoreBuilder; | 5 | import tools.refinery.store.model.ModelStoreBuilder; |
6 | import tools.refinery.store.query.dnf.AnyQuery; | ||
7 | import tools.refinery.store.query.dnf.RelationalQuery; | 6 | import tools.refinery.store.query.dnf.RelationalQuery; |
8 | import tools.refinery.store.query.dse.DesignSpaceExplorationBuilder; | 7 | import tools.refinery.store.query.dse.DesignSpaceExplorationBuilder; |
9 | import tools.refinery.store.query.dse.Strategy; | 8 | import tools.refinery.store.query.dse.Strategy; |
@@ -12,29 +11,19 @@ import tools.refinery.store.query.dse.objectives.Objective; | |||
12 | import java.util.LinkedHashSet; | 11 | import java.util.LinkedHashSet; |
13 | import java.util.LinkedList; | 12 | import java.util.LinkedList; |
14 | import java.util.List; | 13 | import java.util.List; |
15 | import java.util.Set; | ||
16 | 14 | ||
17 | public class DesignSpaceExplorationBuilderImpl | 15 | public class DesignSpaceExplorationBuilderImpl |
18 | extends AbstractModelAdapterBuilder<DesignSpaceExplorationStoreAdapterImpl> | 16 | extends AbstractModelAdapterBuilder<DesignSpaceExplorationStoreAdapterImpl> |
19 | implements DesignSpaceExplorationBuilder { | 17 | implements DesignSpaceExplorationBuilder { |
20 | 18 | private final LinkedHashSet<TransformationRule> transformationSpecifications = new LinkedHashSet<>(); | |
21 | private final Set<AnyQuery> stopConditionSpecifications = new LinkedHashSet<>(); | 19 | private final LinkedHashSet<RelationalQuery> globalConstraints = new LinkedHashSet<>(); |
22 | private final Set<TransformationRule> transformationSpecifications = new LinkedHashSet<>(); | ||
23 | private final Set<RelationalQuery> globalConstraints = new LinkedHashSet<>(); | ||
24 | private final List<Objective> objectives = new LinkedList<>(); | 20 | private final List<Objective> objectives = new LinkedList<>(); |
25 | private Strategy strategy; | 21 | private Strategy strategy; |
26 | 22 | ||
27 | @Override | 23 | @Override |
28 | protected DesignSpaceExplorationStoreAdapterImpl doBuild(ModelStore store) { | 24 | protected DesignSpaceExplorationStoreAdapterImpl doBuild(ModelStore store) { |
29 | return new DesignSpaceExplorationStoreAdapterImpl(store, stopConditionSpecifications, | 25 | return new DesignSpaceExplorationStoreAdapterImpl(store, transformationSpecifications, globalConstraints, |
30 | transformationSpecifications, globalConstraints, objectives, strategy); | 26 | objectives, strategy); |
31 | } | ||
32 | |||
33 | @Override | ||
34 | public DesignSpaceExplorationBuilder stopCondition(AnyQuery stopCondition) { | ||
35 | checkNotConfigured(); | ||
36 | stopConditionSpecifications.add(stopCondition); | ||
37 | return this; | ||
38 | } | 27 | } |
39 | 28 | ||
40 | @Override | 29 | @Override |
@@ -65,10 +54,6 @@ public class DesignSpaceExplorationBuilderImpl | |||
65 | return this; | 54 | return this; |
66 | } | 55 | } |
67 | 56 | ||
68 | public Set<AnyQuery> getStopConditionSpecifications() { | ||
69 | return stopConditionSpecifications; | ||
70 | } | ||
71 | |||
72 | @Override | 57 | @Override |
73 | protected void doConfigure(ModelStoreBuilder storeBuilder) { | 58 | protected void doConfigure(ModelStoreBuilder storeBuilder) { |
74 | storeBuilder.symbols(DesignSpaceExplorationAdapterImpl.NODE_COUNT_SYMBOL); | 59 | storeBuilder.symbols(DesignSpaceExplorationAdapterImpl.NODE_COUNT_SYMBOL); |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationStoreAdapterImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationStoreAdapterImpl.java index 9c2fa4d6..f58715b7 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationStoreAdapterImpl.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/DesignSpaceExplorationStoreAdapterImpl.java | |||
@@ -1,31 +1,28 @@ | |||
1 | package tools.refinery.store.query.dse.internal; | 1 | package tools.refinery.store.query.dse.internal; |
2 | 2 | ||
3 | import tools.refinery.store.adapter.ModelAdapter; | 3 | import tools.refinery.store.adapter.ModelAdapter; |
4 | import tools.refinery.store.query.dnf.AnyQuery; | ||
5 | import tools.refinery.store.query.dnf.RelationalQuery; | ||
6 | import tools.refinery.store.query.dse.DesignSpaceExplorationStoreAdapter; | ||
7 | import tools.refinery.store.model.Model; | 4 | import tools.refinery.store.model.Model; |
8 | import tools.refinery.store.model.ModelStore; | 5 | import tools.refinery.store.model.ModelStore; |
6 | import tools.refinery.store.query.dnf.RelationalQuery; | ||
7 | import tools.refinery.store.query.dse.DesignSpaceExplorationStoreAdapter; | ||
9 | import tools.refinery.store.query.dse.Strategy; | 8 | import tools.refinery.store.query.dse.Strategy; |
10 | import tools.refinery.store.query.dse.objectives.Objective; | 9 | import tools.refinery.store.query.dse.objectives.Objective; |
11 | 10 | ||
11 | import java.util.LinkedHashSet; | ||
12 | import java.util.List; | 12 | import java.util.List; |
13 | import java.util.Set; | ||
14 | 13 | ||
15 | public class DesignSpaceExplorationStoreAdapterImpl implements DesignSpaceExplorationStoreAdapter { | 14 | public class DesignSpaceExplorationStoreAdapterImpl implements DesignSpaceExplorationStoreAdapter { |
16 | private final ModelStore store; | 15 | private final ModelStore store; |
17 | private final Set<AnyQuery> stopConditionSpecifications; | 16 | private final LinkedHashSet<TransformationRule> transformationSpecifications; |
18 | private final Set<TransformationRule> transformationSpecifications; | 17 | private final LinkedHashSet<RelationalQuery> globalConstraints; |
19 | private final Set<RelationalQuery> globalConstraints; | ||
20 | private final List<Objective> objectives; | 18 | private final List<Objective> objectives; |
21 | private final Strategy strategy; | 19 | private final Strategy strategy; |
22 | 20 | ||
23 | public DesignSpaceExplorationStoreAdapterImpl(ModelStore store, Set<AnyQuery> stopConditionSpecifications, | 21 | public DesignSpaceExplorationStoreAdapterImpl(ModelStore store, |
24 | Set<TransformationRule> transformationSpecifications, | 22 | LinkedHashSet<TransformationRule> transformationSpecifications, |
25 | Set<RelationalQuery> globalConstraints, List<Objective> objectives, | 23 | LinkedHashSet<RelationalQuery> globalConstraints, |
26 | Strategy strategy) { | 24 | List<Objective> objectives, Strategy strategy) { |
27 | this.store = store; | 25 | this.store = store; |
28 | this.stopConditionSpecifications = stopConditionSpecifications; | ||
29 | this.transformationSpecifications = transformationSpecifications; | 26 | this.transformationSpecifications = transformationSpecifications; |
30 | this.globalConstraints = globalConstraints; | 27 | this.globalConstraints = globalConstraints; |
31 | this.objectives = objectives; | 28 | this.objectives = objectives; |
@@ -42,15 +39,11 @@ public class DesignSpaceExplorationStoreAdapterImpl implements DesignSpaceExplor | |||
42 | return new DesignSpaceExplorationAdapterImpl(model, this); | 39 | return new DesignSpaceExplorationAdapterImpl(model, this); |
43 | } | 40 | } |
44 | 41 | ||
45 | public Set<AnyQuery> getStopConditionSpecifications() { | 42 | public LinkedHashSet<TransformationRule> getTransformationSpecifications() { |
46 | return stopConditionSpecifications; | ||
47 | } | ||
48 | |||
49 | public Set<TransformationRule> getTransformationSpecifications() { | ||
50 | return transformationSpecifications; | 43 | return transformationSpecifications; |
51 | } | 44 | } |
52 | 45 | ||
53 | public Set<RelationalQuery> getGlobalConstraints() { | 46 | public LinkedHashSet<RelationalQuery> getGlobalConstraints() { |
54 | return globalConstraints; | 47 | return globalConstraints; |
55 | } | 48 | } |
56 | 49 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/TransformationRule.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/TransformationRule.java index c46ff712..950ca930 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/TransformationRule.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/dse/internal/TransformationRule.java | |||
@@ -9,9 +9,8 @@ import tools.refinery.store.query.resultset.OrderedResultSet; | |||
9 | import tools.refinery.store.query.resultset.ResultSet; | 9 | import tools.refinery.store.query.resultset.ResultSet; |
10 | import tools.refinery.store.tuple.Tuple; | 10 | import tools.refinery.store.tuple.Tuple; |
11 | 11 | ||
12 | import java.util.HashSet; | 12 | import java.util.LinkedHashSet; |
13 | import java.util.Random; | 13 | import java.util.Random; |
14 | import java.util.Set; | ||
15 | 14 | ||
16 | public class TransformationRule { | 15 | public class TransformationRule { |
17 | 16 | ||
@@ -66,8 +65,8 @@ public class TransformationRule { | |||
66 | return activations; | 65 | return activations; |
67 | } | 66 | } |
68 | 67 | ||
69 | public Set<Activation> getAllActivations() { | 68 | public LinkedHashSet<Activation> getAllActivations() { |
70 | var result = new HashSet<Activation>(); | 69 | var result = new LinkedHashSet<Activation>(); |
71 | var cursor = activations.getAll(); | 70 | var cursor = activations.getAll(); |
72 | while (cursor.move()) { | 71 | while (cursor.move()) { |
73 | result.add(new Activation(this, cursor.getKey())); | 72 | result.add(new Activation(this, cursor.getKey())); |