use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method buildNonFaultCombinationAssertions.
/**
* Method builds combinations of faults that cannot occur together based on
* probability values.
*
* Uses macros to shrink the size of the entire formula in case the number of
* fault combinations is too large for the Lustre parser to handle.
*
* @param topNode AgreeNode, top of program
* @param builder Node builder will have assertions
* added.
* @param elementProbabilities Prob of elements
* @param faultCombinationsAboveThreshold Which FaultSetProbabilities are above
* threshold given in top level annex.
*/
private void buildNonFaultCombinationAssertions(AgreeNode topNode, AgreeNodeBuilder builder, ArrayList<FaultProbability> elementProbabilities, ArrayList<FaultSetProbability> faultCombinationsAboveThreshold) {
// With the valid fault combinations including dependent faults, and
// noFaultExpr has the default (no-fault) case. Let's construct a proposition.
Set<FaultProbability> elementProbabilitySet = new HashSet<>(elementProbabilities);
// the default (no-fault) case
Expr faultHypothesis = getNoFaultProposition(elementProbabilitySet);
// Vars for macros
List<BinaryExpr> macroList = new ArrayList<BinaryExpr>();
List<String> macroNames = new ArrayList<String>();
int noGoodEls = 0;
int unique = 0;
for (FaultSetProbability fsp : faultCombinationsAboveThreshold) {
Set<FaultProbability> goodElements = new HashSet<>(elementProbabilities);
goodElements.removeAll(fsp.elements);
// add the assertion that the rest of the faults are not to happen
if (!goodElements.isEmpty()) {
noGoodEls = noGoodEls + goodElements.size();
Expr local = getNoFaultProposition(goodElements);
faultHypothesis = new BinaryExpr(local, BinaryOp.OR, faultHypothesis);
// Macros
if (noGoodEls > SAFE_NUM_ELEMENTS) {
IdExpr macro = new IdExpr("GOODELS_" + noGoodEls + unique);
macroNames.add("GOODELS_" + noGoodEls + unique);
noGoodEls = 0;
unique++;
BinaryExpr binMacro = new BinaryExpr(macro, BinaryOp.EQUAL, faultHypothesis);
macroList.add(binMacro);
faultHypothesis = macro;
}
} else // if there are all faults in the current combination
// add the assertion that all faults are allowed to happen
// which will be ORed with the default no fault case
{
Expr local = getAllFaultProposition(fsp.elements);
faultHypothesis = new BinaryExpr(local, BinaryOp.OR, faultHypothesis);
}
}
// Add this fault hypothesis as an assertion if not null.
if (faultHypothesis == null) {
new SafetyException("There is a problem with fault hypothesis for component: " + topNode.id + ". A possible problem is that single layer analysis" + " is being run with no faults defined in lower layer." + " Check hypothesis statements and fault defs in this analysis.");
}
for (String s : macroNames) {
builder.addLocal(new AgreeVar(s, NamedType.BOOL, topNode.reference));
}
for (BinaryExpr b : macroList) {
builder.addLocalEquation(new AgreeEquation((IdExpr) b.left, b.right, topNode.reference));
builder.addAssertion(new AgreeStatement("", b, topNode.reference));
// builder.addGuarantee(new AgreeStatement("", b, topNode.reference));
}
builder.addAssertion(new AgreeStatement("", faultHypothesis, topNode.reference));
}
use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class GenMCSHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
AddFaultsToAgree.resetStaticVars();
Event selEvent = (Event) event.getTrigger();
MenuItem item = (MenuItem) selEvent.widget;
AddFaultsToAgree.setTransformFlag(item);
// clear static variables before each run
AddFaultsToNodeVisitor.init();
if (!SafetyUtil.containsSafetyAnnex(getClassifiers())) {
new SafetyException("A safety annex in the implementation is required to run the fault analysis.");
return Status.CANCEL_STATUS;
}
// Else, return null.
if (AddFaultsToAgree.getIsGenMCS()) {
return super.execute(event);
} else {
return null;
}
}
use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class GenMCSHandler method doAnalysis.
// The following method is copied and modified from AGREE VerifyHandler
private IStatus doAnalysis(final Element root, final IProgressMonitor globalMonitor, AnalysisResult result, AgreeResultsLinker linker) {
Thread analysisThread = new Thread() {
@Override
public void run() {
activateTerminateHandlers(globalMonitor);
KindApi api = PreferencesUtil.getKindApi();
KindApi consistApi = PreferencesUtil.getConsistencyApi();
JRealizabilityApi realApi = PreferencesUtil.getJRealizabilityApi();
while (!queue.isEmpty() && !globalMonitor.isCanceled()) {
JKindResult result = queue.peek();
NullProgressMonitor subMonitor = new NullProgressMonitor();
monitorRef.set(subMonitor);
Program program = linker.getProgram(result);
if (api instanceof JKindApi) {
result.getName();
}
try {
if (result instanceof ConsistencyResult) {
consistApi.execute(program, result, subMonitor);
} else if (result instanceof JRealizabilityResult) {
realApi.execute(program, (JRealizabilityResult) result, subMonitor);
} else {
api.execute(program, result, subMonitor);
}
} catch (JKindException e) {
new SafetyException("JKind exception: " + e.getMessage());
System.out.println("******** JKindException Text ********");
e.printStackTrace(System.out);
System.out.println("******** JKind Output ********");
System.out.println(result.getText());
System.out.println("******** Agree Lustre ********");
System.out.println(program);
break;
}
queue.remove();
}
while (!queue.isEmpty()) {
queue.remove().cancel();
}
// then print empty min cut set fault tree
if ((!AddFaultsToNodeVisitor.maxFaultHypothesis && !AddFaultsToNodeVisitor.probabilisticHypothesis) || (AddFaultsToNodeVisitor.maxFaultHypothesis && (AddFaultsToNodeVisitor.maxFaultCount == 0)) || (AddFaultsToNodeVisitor.probabilisticHypothesis && AddFaultsToNodeVisitor.faultCombinationsAboveThreshold.isEmpty())) {
PrintUtils printUtils = new PrintUtils();
printUtils.printEmptyTree();
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File file = File.createTempFile("ResolvedFT_" + timeStamp + "_", ".ml");
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(printUtils.toString());
bw.close();
org.eclipse.swt.program.Program.launch(file.toString());
} catch (IOException e) {
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
} else {
// open progress bar
// shell.open();
IvcToFTGenerator ftGenerator = new IvcToFTGenerator();
FTResolveVisitor resolveVisitor = new FTResolveVisitor();
FaultTree faultTree = ftGenerator.generateFT(result, linker);
resolveVisitor.visit(faultTree);
LinkedHashMap<String, Set<List<String>>> mapForHFT = ftGenerator.getMapPropertyToMCSs();
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File hierarchyFTFile = File.createTempFile("HierarchicalCausalFactors_" + timeStamp + "_", ".txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(hierarchyFTFile));
PrintUtils printUtils = new PrintUtils();
bw.write(printUtils.printHierarchicalText(mapForHFT));
bw.close();
// display.dispose();
org.eclipse.swt.program.Program.launch(hierarchyFTFile.toString());
} catch (IOException e) {
// close progress bar
// display.dispose();
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File minCutSetFile = File.createTempFile("MinCutSet_" + timeStamp + "_", ".txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(minCutSetFile));
bw.write(faultTree.printMinCutSetTxt());
bw.close();
// display.dispose();
org.eclipse.swt.program.Program.launch(minCutSetFile.toString());
} catch (IOException e) {
// close progress bar
// display.dispose();
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File minCutSetTallyFile = File.createTempFile("MinCutSetTally_" + timeStamp + "_", ".txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(minCutSetTallyFile));
bw.write(faultTree.printMinCutSetTally());
bw.close();
// display.dispose();
org.eclipse.swt.program.Program.launch(minCutSetTallyFile.toString());
} catch (IOException e) {
// close progress bar
// display.dispose();
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
}
AddFaultsToAgree.resetStaticVars();
deactivateTerminateHandlers();
enableRerunHandler(root);
}
};
analysisThread.start();
return Status.OK_STATUS;
}
use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class FaultASTBuilder method renameEqId.
/**
* Make new fault with updated eq stmt ids
* @param f fault to update
* @param idMap map from old id to new
* @return new updated fault
*/
private Fault renameEqId(Fault f, Map<String, String> idMap) {
Fault newFault = new Fault(f);
newFault.safetyEqVars.clear();
newFault.safetyEqAsserts.clear();
newFault.faultOutputMap.clear();
newFault.faultInputMap.clear();
if (!f.triggers.isEmpty()) {
throw new SafetyException("User-defined triggers are currently unsupported.");
}
// update the variable declarations
for (AgreeVar eq : f.safetyEqVars) {
if (idMap.containsKey(eq.id)) {
eq = new AgreeVar(idMap.get(eq.id), eq.type, eq.reference);
}
newFault.safetyEqVars.add(eq);
}
ReplaceIdVisitor visitor = new ReplaceIdVisitor(idMap);
for (AgreeStatement s : f.safetyEqAsserts) {
newFault.safetyEqAsserts.add(visitor.visit(s));
}
for (Map.Entry<Expr, String> element : f.faultOutputMap.entrySet()) {
newFault.faultOutputMap.put(element.getKey().accept(visitor), element.getValue());
}
for (Map.Entry<String, Expr> element : f.faultInputMap.entrySet()) {
newFault.faultInputMap.put(element.getKey(), element.getValue().accept(visitor));
}
return newFault;
}
use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.
the class FaultASTBuilder method setOutput.
/**
* Populate the fault output map
*
* @param the fault in question
* @param the output to go into the map
*/
private void setOutput(Fault fault, OutputStatement output) {
for (int i = 0; i < output.getFault_out().size(); i++) {
String param = output.getFault_out().get(i);
NamedElement compOut = output.getNom_conn().get(i);
if (compOut == null) {
throw new SafetyException("The component " + agreeNode.id + " with fault " + fault.id + " has undefined output.");
} else {
IdExpr result = new IdExpr(compOut.getName());
fault.faultOutputMap.put(result, param);
}
}
}
Aggregations