Search in sources :

Example 1 with AnalysisBehavior

use of edu.umn.cs.crisys.safety.safety.AnalysisBehavior in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method gatherTopLevelFaultAnalysis.

/**
 * Method gets the analysis statement located in the top node system
 * implementation. Determines if max no. faults or prob.
 *
 * @param node Top agree node.
 * @return Analysis behavior stated in the annex.
 */
public AnalysisBehavior gatherTopLevelFaultAnalysis(AgreeNode node) {
    AnalysisBehavior ab = null;
    boolean found = false;
    List<SpecStatement> specs = SafetyUtil.collapseAnnexes(SafetyUtil.getSafetyAnnexes(node, true));
    for (SpecStatement s : specs) {
        if (s instanceof AnalysisStatement) {
            AnalysisStatement as = (AnalysisStatement) s;
            ab = as.getBehavior();
            if (ab instanceof FaultCountBehavior) {
                int maxFaults = Integer.valueOf(((FaultCountBehavior) ab).getMaxFaults());
                if (maxFaults < 0) {
                    throw new SafetyException("Maximum number of faults must be non-negative.");
                }
            } else if (ab instanceof ProbabilityBehavior) {
                double minProbability = Double.valueOf(((ProbabilityBehavior) ab).getProbabilty());
                if (minProbability > 1 || minProbability < 0) {
                    throw new SafetyException("Probability out of range [0, 1]");
                }
            }
            if (found) {
                throw new SafetyException("Multiple analysis specification statements found.  Only one can be processed");
            }
            found = true;
        }
    }
    if (!found && upperMostLevel) {
        throw new SafetyException("No analysis statement; unable to run safety analysis");
    }
    return ab;
}
Also used : AnalysisStatement(edu.umn.cs.crisys.safety.safety.AnalysisStatement) FaultCountBehavior(edu.umn.cs.crisys.safety.safety.FaultCountBehavior) AnalysisBehavior(edu.umn.cs.crisys.safety.safety.AnalysisBehavior) ProbabilityBehavior(edu.umn.cs.crisys.safety.safety.ProbabilityBehavior) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) TransientConstraint(edu.umn.cs.crisys.safety.safety.TransientConstraint) PermanentConstraint(edu.umn.cs.crisys.safety.safety.PermanentConstraint) TemporalConstraint(edu.umn.cs.crisys.safety.safety.TemporalConstraint)

Example 2 with AnalysisBehavior

use of edu.umn.cs.crisys.safety.safety.AnalysisBehavior in project AMASE by loonwerks.

the class SafetyValidator method checkAnalysisStatement.

/**
 * Check for multiple analysis statements in SafetyContractImpl.
 * Check behavior of analysis statements and values for n and
 * probability.
 * @param analysisStmt
 */
@Check(CheckType.FAST)
public void checkAnalysisStatement(AnalysisStatement analysisStmt) {
    AnalysisBehavior behavior = analysisStmt.getBehavior();
    SafetyContractImpl contract = (SafetyContractImpl) analysisStmt.eContainer();
    boolean fcount = false;
    boolean probspec = false;
    for (SpecStatement spec : contract.getSpecs()) {
        if (spec instanceof AnalysisStatement) {
            if (((AnalysisStatement) spec).getBehavior() instanceof FaultCountBehavior) {
                fcount = true;
            } else if (((AnalysisStatement) spec).getBehavior() instanceof ProbabilityBehavior) {
                probspec = true;
            }
        }
    }
    if (fcount && probspec) {
        error(analysisStmt, "Only one analysis statement can be defined in the annex.");
    }
    if (behavior instanceof FaultCountBehavior) {
        FaultCountBehavior fc = (FaultCountBehavior) behavior;
        if (!testIntegerString(fc.getMaxFaults())) {
            error(analysisStmt, "Max N value must be a valid string representing a positive integer.");
        }
    } else if (behavior instanceof ProbabilityBehavior) {
        ProbabilityBehavior prob = (ProbabilityBehavior) behavior;
        if (!testProbabilityString(prob.getProbabilty())) {
            error(analysisStmt, "Probability must be a valid string between 0 and 1 inclusive.");
        }
    } else {
        error(analysisStmt, "Analysis behavior must be either 'analyze: max n fault' or 'analyze: probability r' for integer n and real number r.");
    }
}
Also used : AnalysisStatement(edu.umn.cs.crisys.safety.safety.AnalysisStatement) SafetyContractImpl(edu.umn.cs.crisys.safety.safety.impl.SafetyContractImpl) FaultCountBehavior(edu.umn.cs.crisys.safety.safety.FaultCountBehavior) AnalysisBehavior(edu.umn.cs.crisys.safety.safety.AnalysisBehavior) ProbabilityBehavior(edu.umn.cs.crisys.safety.safety.ProbabilityBehavior) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) Check(org.eclipse.xtext.validation.Check)

Example 3 with AnalysisBehavior

use of edu.umn.cs.crisys.safety.safety.AnalysisBehavior in project AMASE by loonwerks.

the class AnalysisStatementImpl method basicSetBehavior.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetBehavior(AnalysisBehavior newBehavior, NotificationChain msgs) {
    AnalysisBehavior oldBehavior = behavior;
    behavior = newBehavior;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SafetyPackage.ANALYSIS_STATEMENT__BEHAVIOR, oldBehavior, newBehavior);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : AnalysisBehavior(edu.umn.cs.crisys.safety.safety.AnalysisBehavior) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 4 with AnalysisBehavior

use of edu.umn.cs.crisys.safety.safety.AnalysisBehavior in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method topNodeVisit.

/**
 * Visit tasks for the top node.
 *
 * @param nb   NodeBuilder : fault info added here.
 * @param node Agree node that is the top node.
 */
private void topNodeVisit(AgreeNodeBuilder nb, AgreeNode node) {
    topNode = node;
    AnalysisBehavior maxFaults = this.gatherTopLevelFaultAnalysis(node);
    // gather path information for the faults (for creating names later)
    collectFaultPath(node, new ArrayList<>());
    this.gatherFaultPropagation(node);
    this.gatherFaultActivation(node);
    // and do not want recursive calls on this activity for subnodes.
    if (!this.mapCommNodeToInputs.isEmpty()) {
        addTopLevelAsymFaultDeclarations(nb);
    }
    // empty path to pass to top level node fault
    // node id used as the path to pass to sub level node fault
    addTopLevelFaultDeclarations(node, nb);
    // add top level fault activation assertions
    addTopLevelFaultActivationAssertions(nb);
    // max # faults).
    if (AddFaultsToAgree.getIsVerify()) {
        // clear static variables for every verification layer
        // when verifying with AGREE in the presence of faults
        init();
        addTopLevelFaultOccurrenceConstraints(maxFaults, node, nb);
    } else if (AddFaultsToAgree.getIsGenMCS()) {
        nb.setFaultTreeFlag(true);
        // in init() which is invoked when clicking the Generate Minimal Cutsets button
        if (upperMostLevel) {
            upperMostLevel = false;
            // if max fault hypothesis, collect max fault count
            if (maxFaults instanceof FaultCountBehavior) {
                maxFaultHypothesis = true;
                maxFaultCount = Integer.parseInt(((FaultCountBehavior) maxFaults).getMaxFaults());
            } else // if probabilistic fault hypothesis, collect probabilistic hypothesis
            if (maxFaults instanceof ProbabilityBehavior) {
                probabilisticHypothesis = true;
                probabilityThreshold = Double.parseDouble(((ProbabilityBehavior) maxFaults).getProbabilty());
            }
        }
        // but using the probability threshold from the upper most level
        if (probabilisticHypothesis) {
            collectTopLevelMaxFaultOccurrenceConstraint(probabilityThreshold, topNode, nb);
        }
    }
}
Also used : FaultCountBehavior(edu.umn.cs.crisys.safety.safety.FaultCountBehavior) AnalysisBehavior(edu.umn.cs.crisys.safety.safety.AnalysisBehavior) ProbabilityBehavior(edu.umn.cs.crisys.safety.safety.ProbabilityBehavior)

Aggregations

AnalysisBehavior (edu.umn.cs.crisys.safety.safety.AnalysisBehavior)4 FaultCountBehavior (edu.umn.cs.crisys.safety.safety.FaultCountBehavior)3 ProbabilityBehavior (edu.umn.cs.crisys.safety.safety.ProbabilityBehavior)3 AnalysisStatement (edu.umn.cs.crisys.safety.safety.AnalysisStatement)2 SpecStatement (edu.umn.cs.crisys.safety.safety.SpecStatement)2 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)1 PermanentConstraint (edu.umn.cs.crisys.safety.safety.PermanentConstraint)1 TemporalConstraint (edu.umn.cs.crisys.safety.safety.TemporalConstraint)1 TransientConstraint (edu.umn.cs.crisys.safety.safety.TransientConstraint)1 SafetyContractImpl (edu.umn.cs.crisys.safety.safety.impl.SafetyContractImpl)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Check (org.eclipse.xtext.validation.Check)1