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;
}
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.");
}
}
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;
}
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);
}
}
}
Aggregations