Search in sources :

Example 31 with SafetyException

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;
}
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 32 with SafetyException

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

Example 33 with SafetyException

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;
}
Also used : FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) FTLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTLeafNode) FaultSetProbability(edu.umn.cs.crisys.safety.analysis.ast.visitors.AddFaultsToNodeVisitor.FaultSetProbability) HashSet(java.util.HashSet)

Example 34 with SafetyException

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.");
        }
    }
}
Also used : CompContractViolation(edu.umn.cs.crisys.safety.analysis.soteria.CompContractViolation) ValidProperty(jkind.results.ValidProperty) SoteriaFormulaSubgroup(edu.umn.cs.crisys.safety.analysis.soteria.SoteriaFormulaSubgroup) SoteriaFormula(edu.umn.cs.crisys.safety.analysis.soteria.SoteriaFormula) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Aggregations

SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)34 ArrayList (java.util.ArrayList)14 IdExpr (jkind.lustre.IdExpr)12 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)9 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 Expr (jkind.lustre.Expr)9 NodeCallExpr (jkind.lustre.NodeCallExpr)9 RecordAccessExpr (jkind.lustre.RecordAccessExpr)9 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)7 IfThenElseExpr (jkind.lustre.IfThenElseExpr)7 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)6 IntExpr (jkind.lustre.IntExpr)6 UnaryExpr (jkind.lustre.UnaryExpr)6 BaseFault (edu.umn.cs.crisys.safety.analysis.transform.BaseFault)5 PermanentConstraint (edu.umn.cs.crisys.safety.safety.PermanentConstraint)5 TemporalConstraint (edu.umn.cs.crisys.safety.safety.TemporalConstraint)5 TransientConstraint (edu.umn.cs.crisys.safety.safety.TransientConstraint)5 FTAndNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode)3 FTNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTNode)3