Search in sources :

Example 1 with Product

use of org.abs_models.frontend.ast.Product in project abstools by abstools.

the class ProductDeclarationTest method productUnion.

@Test
public void productUnion() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3} || {F4};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(4, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F1", "F2", "F3", "F4"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Product

use of org.abs_models.frontend.ast.Product in project abstools by abstools.

the class ProductDeclarationTest method oldProductSyntax.

@Test
public void oldProductSyntax() throws WrongProgramArgumentException {
    Model model = assertParse("product P1(F1, F2, F3);");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(3, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F1", "F2", "F3"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Product

use of org.abs_models.frontend.ast.Product in project abstools by abstools.

the class ProductDeclarationTest method productIntersect.

@Test
public void productIntersect() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3} && {F2, F3};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(2, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F2", "F3"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Product

use of org.abs_models.frontend.ast.Product 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);
}
Also used : Constraint(choco.kernel.model.constraints.Constraint) IntVal(org.abs_models.frontend.ast.IntVal) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) Model(org.abs_models.frontend.ast.Model) AttrAssignment(org.abs_models.frontend.ast.AttrAssignment) ChocoSolver(org.abs_models.frontend.mtvl.ChocoSolver) HashSet(java.util.HashSet)

Example 5 with Product

use of org.abs_models.frontend.ast.Product in project abstools by abstools.

the class ProductLineAnalysisHelper method buildPFGT.

public static DeltaTrie buildPFGT(ProductLine pl, SemanticConditionList errors) {
    Model model = pl.getModel();
    DeltaTrie trie = new DeltaTrie(model, errors);
    for (Product product : model.getProductList()) {
        // for each product: obtain sequence of deltas & add it to the trie
        Set<String> applicableDeltas = pl.findApplicableDeltas(product);
        List<String> productGenerationString = pl.sortDeltas(applicableDeltas);
        trie.addWord(productGenerationString, product);
    }
    return trie;
}
Also used : Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product)

Aggregations

Product (org.abs_models.frontend.ast.Product)12 Model (org.abs_models.frontend.ast.Model)11 HashSet (java.util.HashSet)10 Feature (org.abs_models.frontend.ast.Feature)10 ProductDecl (org.abs_models.frontend.ast.ProductDecl)9 Test (org.junit.Test)9 Constraint (choco.kernel.model.constraints.Constraint)1 AttrAssignment (org.abs_models.frontend.ast.AttrAssignment)1 IntVal (org.abs_models.frontend.ast.IntVal)1 ChocoSolver (org.abs_models.frontend.mtvl.ChocoSolver)1