Search in sources :

Example 1 with FTNonLeafNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode in project AMASE by loonwerks.

the class FTPrettyPrintVisitor method visit.

@Override
public Void visit(FaultTree ft) {
    write(ft.includeStr);
    newline();
    // print leaf nodes
    for (FTLeafNode leaf : ft.leafNodes.values()) {
        leaf.accept(this);
    }
    // print non leaf nodes
    for (FTNonLeafNode nonLeaf : ft.sortedIntermediateNodes) {
        nonLeaf.accept(this);
    }
    // compute cutsets and probabilities for each root node
    for (FTNonLeafNode root : ft.rootNodes.values()) {
        String rootName = root.propertyName;
        writeln("(* ----- CUTSET WITH PROBABILITIES ----- *)");
        writeln("cutsets " + rootName + ";;");
        writeln("probErrorCut " + rootName + ";;");
        writeln("probErrorCutImp " + rootName + ";;");
        writeln("(* ----- FAULT TREE VISUALIZATIONS ----- *)");
        // fault tree visualization
        write("dot_gen_show_direct_tree_file ~rend:\"pdf\" ");
        writeln("\"" + rootName + "_direct_ftree.gv\" " + rootName + " ;;");
        write("dot_gen_show_tree_file ~rend:\"pdf\" ");
        writeln("\"" + rootName + "_optimized_ftree.gv\" " + rootName + " ;;");
        newline();
    }
    return null;
}
Also used : FTNonLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode) FTLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTLeafNode)

Example 2 with FTNonLeafNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode 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 3 with FTNonLeafNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode in project AMASE by loonwerks.

the class FTResolveVisitor method visit.

@Override
public FTNonLeafNode visit(FTOrNode node) {
    FTNonLeafNode returnNode = null;
    boolean isRoot = node.isRoot;
    List<FTNode> childNodesToRemove = new ArrayList<FTNode>();
    // if no child node, return nodeValue false
    if (node.childNodes.isEmpty()) {
        node.nodeValue = false;
        return node;
    }
    // if not resolved, go visit its child nodes
    if (!isORNodeResolved(node, isRoot)) {
        for (FTNode child : node.childNodes.values()) {
            FTNode childReturn = child.accept(this);
            // remove that child node
            if (childReturn.nodeValue == false) {
                childNodesToRemove.add(child);
            } else {
                node.replaceChildNode(childReturn.nodeName, childReturn);
            }
        }
        node.removeChildNodes(childNodesToRemove);
        // set it to false so it can be handled at the upper level
        if (node.childNodes.isEmpty()) {
            node.nodeValue = false;
            return node;
        }
        // after visiting, if not resolved, go resolve it
        if (!isORNodeResolved(node, isRoot)) {
            returnNode = resolveOrNode(node, isRoot);
        }
    }
    // so it can be eliminated when returned to the upper level
    if (node.nodeValue) {
        if (returnNode != null) {
            return prune(returnNode);
        } else {
            return prune(node);
        }
    } else {
        return node;
    }
}
Also used : FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode) ArrayList(java.util.ArrayList) FTNonLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode)

Example 4 with FTNonLeafNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode in project AMASE by loonwerks.

the class FTResolveVisitor method resolveAndNode.

private FTNonLeafNode resolveAndNode(FTNonLeafNode node) {
    // go through all child nodes that are resolved AND node, and promote the grand child nodes
    promoteNode(node);
    if ((isANDNodeResolved(node))) {
        return node;
    }
    // for the rest of the child nodes that are resolved OR node, transform the parent node
    FTNonLeafNode returnNode = transformNode(node);
    // if no new node created from transformNode, return node
    if (returnNode == null) {
        // set resolved to true
        node.resolved = true;
        return node;
    } else // else return new node created from transformNode
    {
        returnNode.resolved = true;
        return returnNode;
    }
}
Also used : FTNonLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode)

Example 5 with FTNonLeafNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode in project AMASE by loonwerks.

the class FTResolveVisitor method visit.

@Override
public FTNode visit(FTAndNode node) {
    FTNonLeafNode returnNode = null;
    boolean isRoot = node.isRoot;
    // if no child node, return node value false
    if (node.childNodes.isEmpty()) {
        node.nodeValue = false;
        return node;
    }
    // if not resolved, go visit its child nodes
    if (!isANDNodeResolved(node)) {
        for (FTNode child : node.childNodes.values()) {
            FTNode childReturn = child.accept(this);
            // the parent node becomes false
            if (childReturn.nodeValue == false) {
                node.nodeValue = false;
                return node;
            } else {
                node.replaceChildNode(childReturn.nodeName, childReturn);
            }
        }
        // set it can be removed at the upper level
        if (node.childNodes.isEmpty()) {
            node.nodeValue = false;
            return node;
        }
        // after visiting, if not resolved, go resolve it
        if (!isANDNodeResolved(node)) {
            returnNode = resolveAndNode(node);
        }
    }
    // so it can be eliminated when returned to the upper level
    if (node.nodeValue) {
        if (returnNode != null) {
            return prune(returnNode);
        } else {
            return prune(node);
        }
    } else {
        return node;
    }
}
Also used : FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode) FTNonLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode)

Aggregations

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