Search in sources :

Example 1 with DLeaf

use of com.ge.verdict.synthesis.dtree.DLeaf 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 DLeaf

use of com.ge.verdict.synthesis.dtree.DLeaf 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 DLeaf

use of com.ge.verdict.synthesis.dtree.DLeaf in project VERDICT by ge-high-assurance.

the class VerdictSynthesisTest method unmitigatedMixedTest.

@Test
public void unmitigatedMixedTest() {
    DLeaf.Factory factory = new DLeaf.Factory();
    SystemModel system = new SystemModel("S1");
    int targetDal = 1;
    Fraction[] costs = Util.fractionCosts(new double[] { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 });
    DLeaf dleaf = new DLeaf("S1", "D1", "A2", 0, targetDal, costs, factory);
    DTree dtree = new DOr(new ALeaf(new Attack(system.getAttackable(), "A1", "An attack", Prob.certain(), CIA.I)), dleaf);
    for (Approach approach : Approach.values()) {
        Optional<Pair<Set<ComponentDefense>, Double>> result = VerdictSynthesis.performSynthesisSingle(dtree, targetDal, factory, approach);
        Assertions.assertThat(result.isPresent());
        Assertions.assertThat(result.get().left).hasSize(1);
        Assertions.assertThat(result.get().left).contains(dleaf.componentDefense);
        Assertions.assertThat(result.get().right).isEqualTo(5);
    }
}
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) ALeaf(com.ge.verdict.synthesis.dtree.ALeaf) Fraction(org.apache.commons.math3.fraction.Fraction) Attack(com.ge.verdict.attackdefensecollector.adtree.Attack) SystemModel(com.ge.verdict.attackdefensecollector.model.SystemModel) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) Approach(com.ge.verdict.synthesis.VerdictSynthesis.Approach) Pair(com.ge.verdict.synthesis.util.Pair) Test(org.junit.Test)

Example 4 with DLeaf

use of com.ge.verdict.synthesis.dtree.DLeaf in project VERDICT by ge-high-assurance.

the class VerdictSynthesisTest method performSynthesisTestInternal.

private void performSynthesisTestInternal(int[] costs, String[] selected, Approach approach) {
    if (costs.length != 3) {
        throw new RuntimeException("hey!");
    }
    DLeaf.Factory factory = new DLeaf.Factory();
    double[] doubleCosts0 = new double[10];
    double[] doubleCosts1 = new double[10];
    double[] doubleCosts2 = new double[10];
    for (int i = 0; i < 10; i++) {
        doubleCosts0[i] = costs[0];
        doubleCosts1[i] = costs[1];
        doubleCosts2[i] = costs[2];
    }
    Fraction[] fractionCosts0 = Util.fractionCosts(doubleCosts0);
    Fraction[] fractionCosts1 = Util.fractionCosts(doubleCosts1);
    Fraction[] fractionCosts2 = Util.fractionCosts(doubleCosts2);
    int targetDal = 1;
    DLeaf cd1 = new DLeaf("C1", "D1", "A1", 0, targetDal, fractionCosts0, factory);
    DLeaf cd2 = new DLeaf("C2", "D2", "A2", 0, targetDal, fractionCosts1, factory);
    DLeaf cd3 = new DLeaf("C3", "D3", "A3", 0, targetDal, fractionCosts2, factory);
    DTree tree = new DOr(new DAnd(cd1, cd2), new DAnd(cd2, cd3), new DAnd(cd1, cd3));
    Optional<Pair<Set<ComponentDefense>, Double>> output = VerdictSynthesis.performSynthesisSingle(tree, targetDal, factory, approach);
    Assertions.assertThat(output.isPresent()).isTrue();
    Assertions.assertThat(output.get().left.size()).isEqualTo(selected.length);
    for (String comp : selected) {
        Assertions.assertThat(output.get().left.stream()).withFailMessage("Expected: " + stringOfArray(selected) + ", output: " + stringOfIterable(output.get().left) + ", does not contain component: " + comp + ", approach: " + approach.toString()).anyMatch(pair -> pair.component.equals(comp));
    }
}
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) ADAnd(com.ge.verdict.attackdefensecollector.adtree.ADAnd) DAnd(com.ge.verdict.synthesis.dtree.DAnd) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) Pair(com.ge.verdict.synthesis.util.Pair)

Example 5 with DLeaf

use of com.ge.verdict.synthesis.dtree.DLeaf in project VERDICT by ge-high-assurance.

the class VerdictSynthesisTest method totalCostTest.

@Test
public void totalCostTest() {
    Fraction[] costs = Util.fractionCosts(new double[] { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 });
    DLeaf.Factory factory = new DLeaf.Factory();
    // this one counts as 3*2
    new DLeaf("C1", "D1", "A1", 3, 7, costs, factory);
    new DLeaf("C1", "D1", "A1", 3, 5, costs, // this one is a duplicate so it doesn't count
    factory);
    // this one counts as 4*2
    new DLeaf("C1", "D2", "A2", 4, 7, costs, factory);
    Assertions.assertThat(VerdictSynthesis.totalImplCost(factory)).isEqualTo(new Fraction(14));
}
Also used : DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) Fraction(org.apache.commons.math3.fraction.Fraction) Test(org.junit.Test)

Aggregations

DLeaf (com.ge.verdict.synthesis.dtree.DLeaf)16 Fraction (org.apache.commons.math3.fraction.Fraction)14 Test (org.junit.Test)14 ADTree (com.ge.verdict.attackdefensecollector.adtree.ADTree)11 DTree (com.ge.verdict.synthesis.dtree.DTree)11 ADOr (com.ge.verdict.attackdefensecollector.adtree.ADOr)9 DOr (com.ge.verdict.synthesis.dtree.DOr)9 ADAnd (com.ge.verdict.attackdefensecollector.adtree.ADAnd)7 DAnd (com.ge.verdict.synthesis.dtree.DAnd)7 File (java.io.File)6 ADNot (com.ge.verdict.attackdefensecollector.adtree.ADNot)5 Attack (com.ge.verdict.attackdefensecollector.adtree.Attack)5 Defense (com.ge.verdict.attackdefensecollector.adtree.Defense)5 SystemModel (com.ge.verdict.attackdefensecollector.model.SystemModel)5 ALeaf (com.ge.verdict.synthesis.dtree.ALeaf)3 ComponentDefense (com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense)3 ResultsInstance (com.ge.verdict.vdm.synthesis.ResultsInstance)3 Pair (com.ge.verdict.synthesis.util.Pair)2 AttackDefenseCollector (com.ge.verdict.attackdefensecollector.AttackDefenseCollector)1 Pair (com.ge.verdict.attackdefensecollector.Pair)1