use of jkind.api.JRealizabilityApi in project AMASE by loonwerks.
the class PreferencesUtil method getJRealizabilityApi.
public static JRealizabilityApi getJRealizabilityApi() {
IPreferenceStore prefs = getPreferenceStore();
JRealizabilityApi api = new JRealizabilityApi();
api.setJKindJar(getJKindJar());
try {
api.setEnvironment("Z3_HOME", Z3Plugin.getZ3Directory());
} catch (NoClassDefFoundError e) {
e.printStackTrace();
// Z3Plugin not present
} catch (Exception e) {
// Some unknown exception finding Z3
e.printStackTrace();
}
api.setN(prefs.getInt(PreferenceConstants.PREF_DEPTH));
api.setTimeout(prefs.getInt(PreferenceConstants.PREF_TIMEOUT));
return api;
}
use of jkind.api.JRealizabilityApi in project AMASE by loonwerks.
the class FaultsVerifyAllHandler method doAnalysis.
@Override
protected IStatus doAnalysis(final Element root, final IProgressMonitor globalMonitor) {
Thread analysisThread = new Thread() {
@Override
public void run() {
// Record the analysis start time and get model hashcode for
// saving to property analysis log, if necessary
String modelHash = "";
long startTime = 0;
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
try {
modelHash = AgreeFileUtil.getModelHashcode(root);
startTime = System.currentTimeMillis();
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}
}
activateTerminateHandlers(globalMonitor);
KindApi api = PreferencesUtil.getKindApi();
KindApi consistApi = PreferencesUtil.getConsistencyApi();
JRealizabilityApi realApi = PreferencesUtil.getJRealizabilityApi();
// Due to the way the queue is constructed in traversal,
// reversing the queue will result in subcomponent instances
// being analyzed prior to their enclosing component instance.
// Reverse the queue using a stack.
{
Stack<JKindResult> stack = new Stack<>();
while (!queue.isEmpty()) {
stack.push(queue.remove());
}
while (!stack.empty()) {
queue.add(stack.pop());
}
}
while (!queue.isEmpty() && !globalMonitor.isCanceled()) {
JKindResult result = queue.peek();
NullProgressMonitor subMonitor = new NullProgressMonitor();
monitorRef.set(subMonitor);
Program program = doFaultPropagationInjection(result, linker.getProgram(result));
linker.setProgram(result, program);
if (api instanceof JKindApi) {
String resultName = result.getName();
String adviceFileName = rerunAdviceMap.get(resultName);
if (adviceFileName == null) {
adviceFileName = "agree_advice" + adviceCount++;
rerunAdviceMap.put(resultName, adviceFileName);
} else {
((JKindApi) api).setReadAdviceFile(adviceFileName);
}
((JKindApi) api).setWriteAdviceFile(adviceFileName);
}
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) {
System.out.println("******** JKindException Text ********");
e.printStackTrace(System.out);
String errStr = e.getMessage();
int l = Math.min(errStr.length(), 300);
System.out.println(e.getMessage().substring(0, l));
break;
}
// Print to property analysis log, if necessary
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
AgreeFileUtil.printLog(result, startTime, modelHash);
}
queue.remove();
}
while (!queue.isEmpty()) {
queue.remove().cancel();
}
AddFaultsToAgree.resetStaticVars();
deactivateTerminateHandlers();
enableRerunHandler(root);
}
};
analysisThread.start();
return Status.OK_STATUS;
}
use of jkind.api.JRealizabilityApi 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 jkind.api.JRealizabilityApi in project AGREE by loonwerks.
the class VerifyHandler method doAnalysis.
protected IStatus doAnalysis(final Element root, final IProgressMonitor globalMonitor) {
Thread analysisThread = new Thread() {
@Override
public void run() {
// Record the analysis start time and get model hashcode for
// saving to property analysis log, if necessary
String modelHash = "";
long startTime = 0;
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
try {
modelHash = AgreeFileUtil.getModelHashcode(root);
startTime = System.currentTimeMillis();
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}
}
try {
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) {
String resultName = result.getName();
String adviceFileName = rerunAdviceMap.get(resultName);
if (adviceFileName == null) {
adviceFileName = "agree_advice" + adviceCount++;
rerunAdviceMap.put(resultName, adviceFileName);
} else {
((JKindApi) api).setReadAdviceFile(adviceFileName);
}
((JKindApi) api).setWriteAdviceFile(adviceFileName);
}
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) {
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);
String errStr = e.getMessage();
int l = Math.min(errStr.length(), 300);
System.out.println(e.getMessage().substring(0, l));
// >>>>>>> origin/develop
break;
}
// Print to property analysis log, if necessary
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
AgreeFileUtil.printLog(result, startTime, modelHash);
}
queue.remove();
}
while (!queue.isEmpty()) {
queue.remove().cancel();
}
} finally {
deactivateTerminateHandlers();
enableRerunHandler(root);
}
}
};
analysisThread.start();
return Status.OK_STATUS;
}
use of jkind.api.JRealizabilityApi in project AGREE by loonwerks.
the class PreferencesUtil method getJRealizabilityApi.
public static JRealizabilityApi getJRealizabilityApi() {
IPreferenceStore prefs = getPreferenceStore();
JRealizabilityApi api = new JRealizabilityApi();
api.setJKindJar(getJKindJar());
try {
api.setEnvironment("Z3_HOME", Z3Plugin.getZ3Directory());
} catch (NoClassDefFoundError e) {
e.printStackTrace();
// Z3Plugin not present
} catch (Exception e) {
// Some unknown exception finding Z3
e.printStackTrace();
}
api.setN(prefs.getInt(PreferenceConstants.PREF_DEPTH));
api.setTimeout(prefs.getInt(PreferenceConstants.PREF_TIMEOUT));
return api;
}
Aggregations