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));
}
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));
}
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());
}
}
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);
}
});
}
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);
}
Aggregations