Search in sources :

Example 1 with ResultsInstance

use of com.ge.verdict.vdm.synthesis.ResultsInstance in project VERDICT by ge-high-assurance.

the class VerdictSynthesisTest method multipleRequirementsTest.

@Test
public void multipleRequirementsTest() {
    DLeaf.Factory factory = new DLeaf.Factory();
    Fraction[] costs = Util.fractionCosts(new double[] { 2, 5, 9, 15, 16, 18, 20, 25, 30, 37 });
    DLeaf leaf1 = new DLeaf("S1", "D1", "A2", 0, 3, costs, factory);
    DLeaf leaf2 = new DLeaf("S1", "D1", "A2", 0, 4, costs, factory);
    DTree dtree = new DAnd(leaf1, leaf2);
    CostModel costModel = new CostModel(new Triple<>("S1", "D1", costs));
    Optional<ResultsInstance> result = VerdictSynthesis.performSynthesisMultiple(dtree, factory, costModel, false, false, false, false);
    Assertions.assertThat(result.isPresent());
    Assertions.assertThat(result.get().items).hasSize(1);
    Assertions.assertThat(result.get().items).contains(new ResultsInstance.Item("S1", "D1", 0, 4, new Fraction(2), new Fraction(16)));
    Assertions.assertThat(result.get().outputCost).isEqualTo(new Fraction(16));
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) Fraction(org.apache.commons.math3.fraction.Fraction) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DAnd(com.ge.verdict.synthesis.dtree.DAnd) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Test(org.junit.Test)

Example 2 with ResultsInstance

use of com.ge.verdict.vdm.synthesis.ResultsInstance in project VERDICT by ge-high-assurance.

the class VerdictSynthesisTest method meritAssignmentTest.

@Test
public void meritAssignmentTest() {
    DLeaf.Factory factory = new DLeaf.Factory();
    Fraction[] costs1 = Util.fractionCosts(new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
    Fraction[] costs2 = Util.fractionCosts(new double[] { 1, 2, 3, 5, 6, 7, 8, 9, 10, 11 });
    DLeaf leaf1 = new DLeaf("S1", "D1", "A1", 3, 3, costs1, factory);
    DLeaf leaf2 = new DLeaf("S1", "D2", "A2", 3, 3, costs2, factory);
    DTree dtree = new DOr(leaf1, leaf2);
    CostModel costModel = new CostModel(new Triple<>("S1", "D1", costs1), new Triple<>("S1", "D2", costs2));
    Optional<ResultsInstance> result = VerdictSynthesis.performSynthesisMultiple(dtree, factory, costModel, true, true, true, false);
    Assertions.assertThat(result.isPresent());
    Assertions.assertThat(result.get().items).hasSize(2);
    Assertions.assertThat(result.get().items).contains(new ResultsInstance.Item("S1", "D1", 3, 3, new Fraction(3), new Fraction(3)));
    Assertions.assertThat(result.get().items).contains(new ResultsInstance.Item("S1", "D2", 3, 0, new Fraction(5), new Fraction(1)));
    Assertions.assertThat(result.get().outputCost).isEqualTo(new Fraction(4));
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) ADOr(com.ge.verdict.attackdefensecollector.adtree.ADOr) DOr(com.ge.verdict.synthesis.dtree.DOr) Fraction(org.apache.commons.math3.fraction.Fraction) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Test(org.junit.Test)

Example 3 with ResultsInstance

use of com.ge.verdict.vdm.synthesis.ResultsInstance in project VERDICT by ge-high-assurance.

the class VerdictSynthesisTest method resultsXmlTest.

@Test
public void resultsXmlTest() {
    DLeaf.Factory factory = new DLeaf.Factory();
    Fraction[] costs = Util.fractionCosts(new double[] { 2, 5, 9, 15, 16, 18, 20, 25, 30, 37 });
    DTree dtree = new DLeaf("S1", "D1", "A2", 0, 3, costs, factory);
    CostModel costModel = new CostModel(new Triple<>("S1", "D1", costs));
    Optional<ResultsInstance> result = VerdictSynthesis.performSynthesisMultiple(dtree, factory, costModel, false, false, false, false);
    Assertions.assertThat(result.isPresent());
    try {
        File file = File.createTempFile("testOutput", ".xml");
        result.get().toFileXml(file);
        Assertions.assertThat(result.get()).isEqualTo(ResultsInstance.fromFile(file));
    } catch (SAXException | IOException | ParserConfigurationException e) {
        e.printStackTrace();
        Assertions.fail(e.toString());
    }
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) DTree(com.ge.verdict.synthesis.dtree.DTree) ADTree(com.ge.verdict.attackdefensecollector.adtree.ADTree) Fraction(org.apache.commons.math3.fraction.Fraction) IOException(java.io.IOException) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) Test(org.junit.Test)

Example 4 with ResultsInstance

use of com.ge.verdict.vdm.synthesis.ResultsInstance in project VERDICT by ge-high-assurance.

the class SynthesisAadlWriter method perform.

public static void perform(IProject project, File projectDir, ResultsInstance results) {
    if (!saveEditor())
        return;
    Map<String, Property> props = new LinkedHashMap<>();
    {
        List<EObject> objs = VerdictHandlersUtils.preprocessAadlFiles(projectDir);
        for (EObject obj : objs) {
            if (obj instanceof Property) {
                Property prop = (Property) obj;
                props.put(prop.getFullName(), prop);
            }
        }
    }
    Map<String, List<ResultsInstance.Item>> elemChanges = new LinkedHashMap<>();
    for (ResultsInstance.Item item : results.items) {
        if (!elemChanges.containsKey(item.component)) {
            elemChanges.put(item.component, new ArrayList<>());
        }
        elemChanges.get(item.component).add(item);
    }
    VerdictHandlersUtils.modifyAadlDocuments(project, (file, resource) -> {
        if (resource != null) {
            resource.getAllContents().forEachRemaining(obj -> {
                if (obj instanceof Subcomponent && !(obj instanceof DataSubcomponent)) {
                    Subcomponent comp = (Subcomponent) obj;
                    applyChangesToElem(comp, props, elemChanges);
                } else if (obj instanceof Connection) {
                    Connection conn = (Connection) obj;
                    applyChangesToElem(conn, props, elemChanges);
                }
            });
        } else {
            System.err.println("Error: resource is null for file: " + file);
        }
    });
}
Also used : Connection(org.osate.aadl2.Connection) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) LinkedHashMap(java.util.LinkedHashMap) DataSubcomponent(org.osate.aadl2.DataSubcomponent) EObject(org.eclipse.emf.ecore.EObject) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.osate.aadl2.Property)

Example 5 with ResultsInstance

use of com.ge.verdict.vdm.synthesis.ResultsInstance in project VERDICT by ge-high-assurance.

the class VerdictSynthesis method addExtraImplDefenses.

/**
 * Returns a new results instance with any extraneous defenses from the provided list added to
 * the results items liset as removals.
 *
 * @param results the input results to use as a baseline
 * @param implCompDefPairs the set of all implemented component-defense pairs
 * @param costModel the cost model
 * @return a new results instance with the extraneous defenses included
 */
public static ResultsInstance addExtraImplDefenses(ResultsInstance results, Map<com.ge.verdict.attackdefensecollector.Pair<String, String>, Integer> implCompDefPairs, CostModel costModel) {
    List<ResultsInstance.Item> items = new ArrayList<>(results.items);
    Fraction inputCost = results.inputCost;
    Fraction outputCost = results.outputCost;
    // find all of the pairs already in the defense tree
    Set<com.ge.verdict.attackdefensecollector.Pair<String, String>> accountedCompDefPairs = results.items.stream().map(item -> new com.ge.verdict.attackdefensecollector.Pair<>(item.component, item.defenseProperty)).collect(Collectors.toSet());
    for (Map.Entry<com.ge.verdict.attackdefensecollector.Pair<String, String>, Integer> entry : implCompDefPairs.entrySet()) {
        // only add if not already accounted for
        if (!accountedCompDefPairs.contains(entry.getKey())) {
            String comp = entry.getKey().left;
            String defProp = entry.getKey().right;
            int implDal = entry.getValue();
            // compute cost of the implemented pair
            Fraction pairInputCost = costModel.cost(defProp, comp, implDal);
            Fraction pairOutputCost = costModel.cost(defProp, comp, 0);
            // the item will be a removal, so from implDal -> 0 DAL
            items.add(new ResultsInstance.Item(comp, defProp, implDal, 0, pairInputCost, pairOutputCost));
            inputCost = inputCost.add(pairInputCost);
            // this may seem silly, but in theory we can have a non-zero cost for DAL 0
            outputCost = outputCost.add(pairOutputCost);
        }
    }
    return new ResultsInstance(results.partialSolution, results.meritAssignment, results.inputSat, inputCost, outputCost, items);
}
Also used : IntStream(java.util.stream.IntStream) Optimize(com.microsoft.z3.Optimize) Context(com.microsoft.z3.Context) Formula(org.logicng.formulas.Formula) Assignment(org.logicng.datastructures.Assignment) MaxSATSolver(org.logicng.solvers.MaxSATSolver) RatNum(com.microsoft.z3.RatNum) ArrayList(java.util.ArrayList) Map(java.util.Map) FormulaFactory(org.logicng.formulas.FormulaFactory) BoolExpr(com.microsoft.z3.BoolExpr) Status(com.microsoft.z3.Status) DTree(com.ge.verdict.synthesis.dtree.DTree) ArithExpr(com.microsoft.z3.ArithExpr) LinkedHashSet(java.util.LinkedHashSet) DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) PrintWriter(java.io.PrintWriter) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) Model(com.microsoft.z3.Model) List(java.util.List) Fraction(org.apache.commons.math3.fraction.Fraction) ArithmeticUtils(org.apache.commons.math3.util.ArithmeticUtils) Pair(com.ge.verdict.synthesis.util.Pair) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Expr(com.microsoft.z3.Expr) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArrayList(java.util.ArrayList) Fraction(org.apache.commons.math3.fraction.Fraction) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Map(java.util.Map) Pair(com.ge.verdict.synthesis.util.Pair)

Aggregations

ResultsInstance (com.ge.verdict.vdm.synthesis.ResultsInstance)9 DLeaf (com.ge.verdict.synthesis.dtree.DLeaf)6 Fraction (org.apache.commons.math3.fraction.Fraction)6 DTree (com.ge.verdict.synthesis.dtree.DTree)5 ADTree (com.ge.verdict.attackdefensecollector.adtree.ADTree)4 Test (org.junit.Test)4 ComponentDefense (com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 AttackDefenseCollector (com.ge.verdict.attackdefensecollector.AttackDefenseCollector)2 ADAnd (com.ge.verdict.attackdefensecollector.adtree.ADAnd)2 ADOr (com.ge.verdict.attackdefensecollector.adtree.ADOr)2 Pair (com.ge.verdict.synthesis.util.Pair)2 Context (com.microsoft.z3.Context)2 Model (com.microsoft.z3.Model)2 Optimize (com.microsoft.z3.Optimize)2 RatNum (com.microsoft.z3.RatNum)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2