Search in sources :

Example 1 with FTAndNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode 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.");
        }
    }
}
Also used : FTAndNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode) ValidProperty(jkind.results.ValidProperty) ArrayList(java.util.ArrayList) List(java.util.List) FTOrNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) FTNonLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode) HashSet(java.util.HashSet)

Example 2 with FTAndNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode 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;
}
Also used : FTAndNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode) FTOrNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Example 3 with FTAndNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode 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;
    }
}
Also used : FTAndNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode) HashMap(java.util.HashMap) FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode) ArrayList(java.util.ArrayList) FTOrNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) FTLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTLeafNode) ArrayList(java.util.ArrayList) List(java.util.List) FTNonLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode) HashSet(java.util.HashSet)

Aggregations

SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)3 FTAndNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode)3 FTOrNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode)3 FTNonLeafNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 FTLeafNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTLeafNode)1 FTNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTNode)1 HashMap (java.util.HashMap)1 ValidProperty (jkind.results.ValidProperty)1