aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/DepthFirstStrategy.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/DepthFirstStrategy.java')
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/DepthFirstStrategy.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/DepthFirstStrategy.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/DepthFirstStrategy.java
index 1405789b..f4a0747a 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/DepthFirstStrategy.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/DepthFirstStrategy.java
@@ -21,6 +21,7 @@ public class DepthFirstStrategy implements Strategy {
21 private DesignSpaceExplorationAdapter dseAdapter; 21 private DesignSpaceExplorationAdapter dseAdapter;
22 22
23 private int maxDepth; 23 private int maxDepth;
24 private int maxSolutions;
24 private boolean backTrackIfSolution = true; 25 private boolean backTrackIfSolution = true;
25 26
26 public DepthFirstStrategy() { 27 public DepthFirstStrategy() {
@@ -28,11 +29,20 @@ public class DepthFirstStrategy implements Strategy {
28 } 29 }
29 30
30 public DepthFirstStrategy(int maxDepth) { 31 public DepthFirstStrategy(int maxDepth) {
32 this(maxDepth, -1);
33 }
34
35 public DepthFirstStrategy(int maxDepth, int maxSolutions) {
31 if (maxDepth < 0) { 36 if (maxDepth < 0) {
32 this.maxDepth = Integer.MAX_VALUE; 37 this.maxDepth = Integer.MAX_VALUE;
33 } else { 38 } else {
34 this.maxDepth = maxDepth; 39 this.maxDepth = maxDepth;
35 } 40 }
41 if (maxSolutions < 0) {
42 this.maxSolutions = Integer.MAX_VALUE;
43 } else {
44 this.maxSolutions = maxSolutions;
45 }
36 } 46 }
37 47
38 public DepthFirstStrategy continueIfHardObjectivesFulfilled() { 48 public DepthFirstStrategy continueIfHardObjectivesFulfilled() {
@@ -47,6 +57,9 @@ public class DepthFirstStrategy implements Strategy {
47 57
48 @Override 58 @Override
49 public void explore() { 59 public void explore() {
60 if (maxSolutions == 0) {
61 return;
62 }
50 mainloop: while (true) { 63 mainloop: while (true) {
51 var globalConstraintsAreSatisfied = dseAdapter.checkGlobalConstraints(); 64 var globalConstraintsAreSatisfied = dseAdapter.checkGlobalConstraints();
52 if (!globalConstraintsAreSatisfied) { 65 if (!globalConstraintsAreSatisfied) {
@@ -61,9 +74,13 @@ public class DepthFirstStrategy implements Strategy {
61 } 74 }
62 } 75 }
63 76
64 Fitness fitness = dseAdapter.calculateFitness(); 77 Fitness fitness = dseAdapter.getFitness();
65 if (fitness.isSatisfiesHardObjectives()) { 78 if (fitness.isSatisfiesHardObjectives()) {
66 dseAdapter.newSolution(); 79 dseAdapter.newSolution();
80 var solutions = dseAdapter.getSolutions().size();
81 if (solutions >= maxSolutions) {
82 return;
83 }
67 if (backTrackIfSolution) { 84 if (backTrackIfSolution) {
68 var isSuccessfulUndo = dseAdapter.backtrack(); 85 var isSuccessfulUndo = dseAdapter.backtrack();
69 if (!isSuccessfulUndo) { 86 if (!isSuccessfulUndo) {
@@ -76,7 +93,6 @@ public class DepthFirstStrategy implements Strategy {
76 } 93 }
77 } 94 }
78 95
79 var depth = dseAdapter.getDepth();
80 if (dseAdapter.getDepth() >= maxDepth) { 96 if (dseAdapter.getDepth() >= maxDepth) {
81 var isSuccessfulUndo = dseAdapter.backtrack(); 97 var isSuccessfulUndo = dseAdapter.backtrack();
82 if (!isSuccessfulUndo) { 98 if (!isSuccessfulUndo) {