use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class FTPrettyPrintVisitor method visit.
@Override
public Void visit(FTNonLeafNode nonLeaf) {
if (nonLeaf instanceof FTOrNode) {
FTOrNode orNode = (FTOrNode) nonLeaf;
orNode.accept(this);
} else if (nonLeaf instanceof FTAndNode) {
FTAndNode andNode = (FTAndNode) nonLeaf;
andNode.accept(this);
} else {
throw new SafetyException("Not instanstiated non leaf node " + nonLeaf.nodeName);
}
return null;
}
use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class FTResolveVisitor method transformNode.
private FTNonLeafNode transformNode(FTNonLeafNode node) {
HashMap<String, FTNode> nodesMap = new HashMap<>();
Set<List<String>> sourceSets = new HashSet<List<String>>();
FTNonLeafNode returnNode = null;
boolean originalAndNode = false;
int oppositeChildNum = 0;
int siblingLeafNum = 0;
if (node instanceof FTAndNode) {
originalAndNode = true;
} else {
originalAndNode = false;
}
// 2) one set for each member of the sibling leaf node of the parent node
for (FTNode child : node.childNodes.values()) {
if (child instanceof FTLeafNode) {
siblingLeafNum++;
List<String> curList = new ArrayList<>();
nodesMap.put(child.nodeName, child);
curList.add(child.nodeName);
sourceSets.add(curList);
} else if (!child.getClass().equals(node.getClass())) {
oppositeChildNum++;
List<String> curList = new ArrayList<>();
for (FTNode curNode : child.childNodes.values()) {
nodesMap.put(curNode.nodeName, curNode);
curList.add(curNode.nodeName);
}
sourceSets.add(curList);
} else {
throw new SafetyException("Child node " + child.nodeName + " should be promoted");
}
}
if (oppositeChildNum == 0) {
return returnNode;
} else {
if ((oppositeChildNum == 1) && (siblingLeafNum == 0)) {
// MHSUtils.createUniqueElemName(node.nodeName);
String newNodeName = node.nodeName;
if (originalAndNode) {
returnNode = new FTOrNode(newNodeName, node.propertyDescription);
} else {
returnNode = new FTAndNode(newNodeName, node.propertyDescription);
}
for (FTNode child : nodesMap.values()) {
// add the child node to returnNode
returnNode.addChildNode(child.nodeName, child);
}
return returnNode;
}
// make each minimal hitting set an node whose AND/OR that matches parent node, and whose child nodes are the elements of that mhs set
// connect all mhs sets via a node whose AND/OR is the opposite of the original parent node, and replace the original parent node with this new node
// TODO: set mhs set size according to fault hypothesis
Set<List<String>> destSets = new HashSet<List<String>>();
if (originalAndNode) {
if (AddFaultsToNodeVisitor.maxFaultCount != 0) {
destSets = MHSUtils.computeMHS(sourceSets, AddFaultsToNodeVisitor.maxFaultCount, false);
} else if (!AddFaultsToNodeVisitor.faultCombinationsAboveThreshold.isEmpty()) {
destSets = MHSUtils.computeMHS(sourceSets, 0, true);
}
} else // else no pruning
{
destSets = MHSUtils.computeMHS(sourceSets, 0, false);
}
if (destSets.size() == 0) {
// Different from previous null returnNode scenario
// in this case the nodeValue of the original node will be set to false
// as there is no min cut set for this node
node.nodeValue = false;
return returnNode;
} else {
// MHSUtils.createUniqueElemName(node.nodeName);
String newNodeName = node.nodeName;
if (originalAndNode) {
returnNode = new FTOrNode(newNodeName, node.propertyDescription);
} else {
returnNode = new FTAndNode(newNodeName, node.propertyDescription);
}
if (destSets.size() > 1) {
for (List<String> curSet : destSets) {
FTNonLeafNode curNode;
String curNodeName = MHSUtils.createUniqueElemName(node.nodeName);
if (originalAndNode) {
curNode = new FTAndNode(curNodeName, "");
} else {
curNode = new FTOrNode(curNodeName, "");
}
for (String curChildName : curSet) {
// get original FT node corresponding to the string
FTNode childNode = nodesMap.get(curChildName);
// add the child node to curNode
curNode.addChildNode(curChildName, childNode);
}
// set curNode as resolved as its child nodes are either leaf nodes
// or resolve node
curNode.resolved = true;
returnNode.addChildNode(curNodeName, curNode);
}
} else {
for (List<String> curSet : destSets) {
for (String curChildName : curSet) {
// get original FT node corresponding to the string
FTNode childNode = nodesMap.get(curChildName);
// add the child node to returnNode
returnNode.addChildNode(curChildName, childNode);
}
}
}
}
return returnNode;
}
}
use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class FTResolveVisitor method isSubset.
private boolean isSubset(FTNonLeafNode node, ArrayList<FaultSetProbability> faultCombinationsAboveThreshold) {
boolean isSubset = false;
HashSet<String> childNodeSet = new HashSet<String>();
for (FTNode childNode : node.childNodes.values()) {
if (!(childNode instanceof FTLeafNode)) {
throw new SafetyException("Trying to prune node " + node.nodeName + " with non leaf child " + childNode.nodeName);
} else {
childNodeSet.add(((FTLeafNode) childNode).lustreFaultName);
}
}
for (FaultSetProbability faultCombination : AddFaultsToNodeVisitor.faultCombinationsAboveThreshold) {
HashSet<String> faultCombinationSet = faultCombination.toStringSet();
if (faultCombinationSet.containsAll(childNodeSet)) {
isSubset = true;
return isSubset;
}
}
return isSubset;
}
use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class IvcToSoteriaGenerator method extractPropertyResult.
private void extractPropertyResult(SoteriaComp comp, AgreeRenaming renaming, PropertyResult propertyResult) {
// get original property name
String origPropertyName = propertyResult.getName();
String lustreName = renaming.getLustreNameFromAgreeVar(origPropertyName);
String propertyName = updateElemName(comp.componentName + "_" + lustreName);
// if it is a guarantee
if (lustreName.startsWith("__GUARANTEE")) {
// if it's a valid guarantee
if (propertyResult.getStatus().equals(jkind.api.results.Status.VALID)) {
// add property as an output to the soteria map
comp.addOutput(propertyName);
// add property violation as a top level fault to the model
if (!isLowerLevel) {
CompContractViolation contractViolation = new CompContractViolation(comp.componentName, propertyName);
model.addTopLevelFault(contractViolation);
}
ValidProperty property = (ValidProperty) propertyResult.getProperty();
SoteriaFormula formula = new SoteriaFormula(propertyName);
// handle multiple ivc sets
for (List<String> ivcSet : property.getIvcSets()) {
SoteriaFormulaSubgroup formulaSubgroup = new SoteriaFormulaSubgroup(propertyName);
extractIvcSets(comp, renaming, formulaSubgroup, ivcSet);
if (!formulaSubgroup.elmeList.isEmpty()) {
formula.addFormulaSubgroup(formulaSubgroup);
}
}
if (!formula.formulaBody.isEmpty()) {
comp.addFormula(propertyName, formula);
}
} else if (propertyResult.getStatus().equals(jkind.api.results.Status.CANCELED)) {
throw new SafetyException("One of the properties was canceled in the process of model checking." + " Rerun this analysis to proceed.");
} else if (propertyResult.getStatus().equals(jkind.api.results.Status.INVALID)) {
throw new SafetyException("One of the properties is invalid. The model must be valid using AGREE Verify All Layers.");
}
}
}
Aggregations