Skip to content

Commit

Permalink
fix: use getClass().getResource() to access examples
Browse files Browse the repository at this point in the history
  • Loading branch information
schweikart committed Sep 28, 2023
1 parent 69233c9 commit 51a89e3
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import edu.kit.provideq.toolbox.meta.ProblemSolver;
import edu.kit.provideq.toolbox.meta.ProblemType;
import edu.kit.provideq.toolbox.meta.setting.MetaSolverSetting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -40,8 +44,12 @@ public ProblemSolver<String, String> findSolver(Problem<String> problem,
@Override
public List<String> getExampleProblems() {
try {
return resourceProvider.getExampleProblems(examplesDirectoryPath);
} catch (Exception e) {
var problemStream = Objects.requireNonNull(
getClass().getResourceAsStream("sandwich.txt"),
"Sandwich example for Dead Feature is unavailable!"
);
return List.of(resourceProvider.readStream(problemStream));
} catch (IOException e) {
throw new RuntimeException("Could not load example problems", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import edu.kit.provideq.toolbox.meta.ProblemSolver;
import edu.kit.provideq.toolbox.meta.ProblemType;
import edu.kit.provideq.toolbox.meta.setting.MetaSolverSetting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -40,8 +44,12 @@ public ProblemSolver<String, String> findSolver(Problem<String> problem,
@Override
public List<String> getExampleProblems() {
try {
return resourceProvider.getExampleProblems(examplesDirectoryPath);
} catch (Exception e) {
var problemStream = Objects.requireNonNull(
getClass().getResourceAsStream("sandwich.txt"),
"Sandwich example for Void Feature Models is unavailable!"
);
return List.of(resourceProvider.readStream(problemStream));
} catch (IOException e) {
throw new RuntimeException("Could not load example problems", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import edu.kit.provideq.toolbox.meta.Problem;
import edu.kit.provideq.toolbox.meta.ProblemType;
import edu.kit.provideq.toolbox.meta.setting.MetaSolverSetting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -46,8 +50,12 @@ public MaxCutSolver findSolver(
@Override
public List<String> getExampleProblems() {
try {
return resourceProvider.getExampleProblems(examplesDirectoryPath);
} catch (Exception e) {
var problemStream = Objects.requireNonNull(
getClass().getResourceAsStream("3-nodes-3-edges.txt"),
"3-nodes-3-edges example for MaxCut is unavailable!"
);
return List.of(resourceProvider.readStream(problemStream));
} catch (IOException e) {
throw new RuntimeException("Could not load example problems", e);
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/edu/kit/provideq/toolbox/sat/MetaSolverSat.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import edu.kit.provideq.toolbox.meta.setting.MetaSolverSetting;
import edu.kit.provideq.toolbox.sat.solvers.GamsSatSolver;
import edu.kit.provideq.toolbox.sat.solvers.SatSolver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -43,8 +47,12 @@ public SatSolver findSolver(Problem<String> problem, List<MetaSolverSetting> met
@Override
public List<String> getExampleProblems() {
try {
return resourceProvider.getExampleProblems(examplesDirectoryPath);
} catch (Exception e) {
var problemStream = Objects.requireNonNull(
getClass().getResourceAsStream("simple-and.txt"),
"Simple-And example for SAT is unavailable!"
);
return List.of(resourceProvider.readStream(problemStream));
} catch (IOException e) {
throw new RuntimeException("Could not load example problems", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Sandwich

features
Sandwich {extended__}
mandatory
Bread
alternative
"Full Grain" {Calories 203, Price 1.99, Organic true}
Flatbread {Calories 90, Price 0.79, Organic true}
Toast {Calories 250, Price 0.99, Organic false}
optional
Cheese
optional
Gouda
alternative
Sprinkled {Fat {value 35, unit "g"}}
Slice {Fat {value 35, unit "g"}}
Cheddar
"Cream Cheese"
Meat
or
"Salami" {Producer "Farmer Bob"}
Ham {Producer "Farmer Sam"}
"Chicken Breast" {Producer "Farmer Sam"}
Vegetables
optional
"Cucumber"
Tomatoes
Lettuce

0 comments on commit 51a89e3

Please sign in to comment.