-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Greetings, FeatureIDE team. I am currently developing a Spring Boot API that can validate a given set of features according to a feature model that is specified in XML format. Following the examples in the repository, below is the flow of the program to get whether based on a feature model and a set of selected features, a solution can be found:
IFormula formula = Common.loadFormula("feature-model/model.xml");
BooleanAssignmentList clauseList = Computations.of(formula)
.map(ComputeNNFFormula::new)
.map(ComputeCNFFormula::new)
.map(ComputeBooleanClauseList::new)
.compute();
VariableMap variableMap = clauseList.getVariableMap();
SAT4JSolutionSolver solver = new SAT4JSolutionSolver(clauseList);
Set<String> featureNames = new HashSet<>(variableMap.getVariableNames());
List<Integer> indices = new ArrayList<>();
variableMap.stream().forEach(pair -> {
if (selectedFeatures.contains(pair.getValue())) {
indices.add(pair.getKey());
} else {
indices.add(-pair.getKey());
}
});
BooleanAssignment booleanAssignment = new BooleanAssignment(indices);
solver.getAssignment().addAll(booleanAssignment);
Result<Boolean> solution = solver.hasSolution();When testing outside of the Spring Boot API environment, the feature model file (model.xml) can be loaded successfully. However, when running the code in Spring Boot API, the feature model file cannot be loaded.
I tried to fix this issue by changing src/main/java/de/featjar/base/extension/ExtensionManager.java and src/testFixtures/java/de/featjar/Common.java to use a different approach to get the classloader:
// ExtensionManager.java
// Instead of using
final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
// I used
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();// Common.java
// Instead of using
URL systemResource = ClassLoader.getSystemResource(modelPath);
// I used
URL systemResource = Thread.currentThread().getContextClassLoader().getResource(modelPath);After implementing these changes, the feature model file can be loaded and the feature selection validation can be done. I also tested these changes by running the program outside of the Spring Boot API environment, and the feature model can be loaded successfully. However, is this the best approach to solving the issue?
Thank you for your time, FeatureIDE team.