use of edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode in project AMASE by loonwerks.
the class IvcToFTGenerator method extractPropertyResult.
private void extractPropertyResult(String compName, AgreeRenaming renaming, PropertyResult propertyResult) {
// get original property name
String origPropertyName = propertyResult.getName();
String lustreName = renaming.getLustreNameFromAgreeVar(origPropertyName);
String propertyName = MHSUtils.updateElemName(compName + "_" + 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)) {
// TODO: get user specified property name if exists
String propertyDescription = propertyResult.getName();
ValidProperty property = (ValidProperty) propertyResult.getProperty();
// check if there is timeout in MIVC analysis
if (property.getMivcTimedOut()) {
new SafetyException("MIVC ANALYSIS TIMEOUT FOR " + lustreName + ": " + origPropertyName);
}
// Create mapPropToMCS for hierarchical ft printout
String propName = propertyName + ": " + propertyDescription;
Set<List<String>> mcsList = new HashSet<List<String>>();
// turn MIVC sets to MCS sets
// no limit on mhs set size
Set<List<String>> mcsSets = MHSUtils.computeMHS(property.getIvcSets(), 0, false);
// Create list for prop->MCS mapping
mcsList = createMCSList(mcsSets, renaming);
mapPropertyToMCSs.put(componentName + "__" + lustreName, mcsList);
// create node when mcsSets is not empty
if (!mcsSets.isEmpty()) {
FTNonLeafNode propertyNode;
boolean isNewNode = true;
boolean createOrNode = (mcsSets.size() > 1);
if (!faultTree.intermediateNodes.containsKey(propertyName)) {
if (createOrNode) {
propertyNode = new FTOrNode(propertyName, propertyDescription);
} else {
propertyNode = new FTAndNode(propertyName, propertyDescription);
}
} else {
propertyNode = faultTree.intermediateNodes.get(propertyName);
// if the no child node has been populated for this node yet
if (!(propertyNode instanceof FTOrNode) && !(propertyNode instanceof FTAndNode)) {
if (createOrNode) {
propertyNode = new FTOrNode(propertyName, propertyNode.propertyDescription);
} else {
propertyNode = new FTAndNode(propertyName, propertyNode.propertyDescription);
}
} else {
isNewNode = false;
}
}
if (isNewNode) {
int index = 0;
for (List<String> mcsSet : mcsSets) {
String mcsSetNodeName = propertyName + "_" + Integer.toString(index);
FTAndNode mcsSetNode = new FTAndNode(mcsSetNodeName, propertyDescription);
extractMCSSets(compName, renaming, mcsSetNode, mcsSet);
propertyNode.addChildNode(mcsSetNodeName, mcsSetNode);
// mcsSetNode.addParentNode(propertyNode);
faultTree.addIntermediateNode(mcsSetNodeName, mcsSetNode);
// update intermediate node
faultTree.addIntermediateNode(propertyNode.nodeName, propertyNode);
index++;
}
}
if (!isLowerLevel) {
faultTree.addRootNode(propertyName, propertyNode);
propertyNode.setRoot();
}
faultTree.addIntermediateNode(propertyName, propertyNode);
} else {
FTNonLeafNode propertyNode = new FTNonLeafNode(propertyName, propertyDescription);
if (faultTree.intermediateNodes.containsKey(propertyName)) {
propertyNode = faultTree.intermediateNodes.get(propertyName);
}
propertyNode.resolved = true;
propertyNode.nodeValue = false;
if (!isLowerLevel) {
faultTree.addRootNode(propertyName, propertyNode);
propertyNode.setRoot();
}
faultTree.addIntermediateNode(propertyName, propertyNode);
}
} 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.");
} else if (propertyResult.getStatus().equals(jkind.api.results.Status.UNKNOWN)) {
throw new SafetyException("One of the properties is unknown. All properties must be known and valid to generate minimal cut sets" + " Tip: Set solver to Z3 and set analysis properties PDR = 4.");
}
}
}
use of edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode 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.faultTree.FTOrNode 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;
}
}
Aggregations