use of org.abs_models.frontend.ast.AttrAssignment in project abstools by abstools.
the class ProductLineAnalysisHelper method buildAndPrintAllConfigurations.
/*
* Build all SPL configurations (valid feature selections, ignoring attributes), one by one
* The purpose is to measure how long this takes, so we can compare it with the performance of type checking the SPL.
*
*/
public static void buildAndPrintAllConfigurations(Model m) {
long timeSum = 0;
for (Product product : m.getProductList()) {
long time0 = System.currentTimeMillis();
System.out.println("\u23F1 Flattening product: " + product.getFeatureSetAsString());
// Find a solution to the feature model that satisfies the product feature selection
ChocoSolver s = m.instantiateCSModel();
HashSet<Constraint> newcs = new HashSet<>();
product.getProdConstraints(s.vars, newcs);
for (Constraint c : newcs) s.addConstraint(c);
Map<String, Integer> solution = s.getSolution();
System.out.println("\u23F1 Full product configuration: " + solution);
long time1 = System.currentTimeMillis();
// i.e. add attribute assignments to features
for (String fname : solution.keySet()) {
if (// ignore internal ChocoSolver variable
fname.startsWith("$"))
continue;
if (fname.contains(".")) {
String[] parts = fname.split("\\.");
String fid = parts[0];
String aid = parts[1];
Integer val = solution.get(fname);
for (Feature feature : product.getFeatures()) {
if (feature.getName().equals(fid)) {
feature.addAttrAssignment(new AttrAssignment(aid, new IntVal(val)));
break;
}
}
}
}
long time2 = System.currentTimeMillis();
Model thisModel = m.treeCopyNoTransform();
long time3 = System.currentTimeMillis();
thisModel.flattenForProduct(product);
long time4 = System.currentTimeMillis();
timeSum += (time4 - time3);
System.out.println("\u23F1 Time: " + (time1 - time0) + " | " + (time2 - time1) + " | " + (time3 - time2) + " | " + (time4 - time3) + " | " + "Total(s): " + ((time4 - time0) / 1000.0));
}
System.out.println("\u23F1 Flattening total time (s): " + timeSum / 1000.0);
}
Aggregations