Search in sources :

Example 1 with FTNode

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

the class FTPrettyPrintVisitor method printNonLeafNode.

private void printNonLeafNode(String nodeOpStr, FTNonLeafNode nonLeaf) {
    writeln("let " + nonLeaf.propertyName + " = ");
    writeln(nodeOpStr + " [");
    boolean multipleElem = false;
    for (FTNode node : nonLeaf.childNodes.values()) {
        if (multipleElem) {
            writeln(";");
        }
        write(node.nodeName);
        multipleElem = true;
    }
    writeln("    ];;");
}
Also used : FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode)

Example 2 with FTNode

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

the class FTMinCutSetPrintVisitor method visit.

@Override
public Void visit(FaultTree ft) {
    write(ft.includeStr);
    newline();
    // walk through the tree and print from bottom to top
    for (FTNode root : ft.resolvedRootNodes) {
        String rootName = root.nodeName;
        if (root.nodeValue == true) {
            root.accept(this);
            printRootNode(rootName);
        } else {
            printNoTreeRootNode(rootName);
        }
    }
    return null;
}
Also used : FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode)

Example 3 with FTNode

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

the class FTMinCutSetTxtPrintVisitor method visit.

@Override
public Void visit(FTOrNode orNode) {
    LinkedList<FTNode> sortedChildren = new LinkedList<FTNode>(orNode.childNodes.values());
    sortedChildren.sort(Comparator.comparing(FTNode::getProbability).reversed());
    writeln("Total " + orNode.childNodes.size() + " Minimal Cut Sets found for this property");
    writeln("Probability of failure for the overall property: " + orNode.getProbability());
    writeln("");
    int minCutSetNum = 0;
    for (FTNode child : sortedChildren) {
        minCutSetNum++;
        writeln("Minimal Cut Set # " + minCutSetNum);
        if (child instanceof FTLeafNode) {
            writeln("Cardinality 1");
        }
        child.accept(this);
        newline();
    }
    return null;
}
Also used : FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode) LinkedList(java.util.LinkedList) FTLeafNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTLeafNode)

Example 4 with FTNode

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

the class FTResolveVisitor method promoteNode.

// replace a node with its child nodes in its parent node's child nodes
private void promoteNode(FTNonLeafNode node) {
    List<FTNode> childNodesToAdd = new ArrayList<FTNode>();
    List<FTNode> childNodesToRemove = new ArrayList<FTNode>();
    for (FTNode childNode : node.childNodes.values()) {
        // if child node not yet resolved, throw exception
        if (!childNode.resolved) {
            throw new SafetyException("Unresolved child node " + childNode.nodeName + " for parent node " + node.nodeName);
        } else {
            if ((childNode.childNodes.size() == 1) || childNode.getClass().equals(node.getClass())) {
                for (FTNode grandChild : childNode.childNodes.values()) {
                    childNodesToAdd.add(grandChild);
                }
                childNodesToRemove.add(childNode);
            }
        }
    }
    node.addChildNodes(childNodesToAdd);
    node.removeChildNodes(childNodesToRemove);
}
Also used : FTNode(edu.umn.cs.crisys.safety.analysis.faultTree.FTNode) ArrayList(java.util.ArrayList) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Example 5 with FTNode

use of edu.umn.cs.crisys.safety.analysis.faultTree.FTNode 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)

Aggregations

FTNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTNode)14 FTLeafNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTLeafNode)4 FTNonLeafNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode)4 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 FaultSetProbability (edu.umn.cs.crisys.safety.analysis.ast.visitors.AddFaultsToNodeVisitor.FaultSetProbability)1 FTAndNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode)1 FTOrNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1