Search in sources :

Example 1 with PrintUtils

use of edu.umn.cs.crisys.safety.analysis.ast.visitors.PrintUtils 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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JRealizabilityResult(jkind.api.results.JRealizabilityResult) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) JKindException(jkind.JKindException) Set(java.util.Set) FileWriter(java.io.FileWriter) IvcToFTGenerator(edu.umn.cs.crisys.safety.analysis.generators.IvcToFTGenerator) IOException(java.io.IOException) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) FTResolveVisitor(edu.umn.cs.crisys.safety.analysis.ast.visitors.FTResolveVisitor) Date(java.util.Date) JKindResult(jkind.api.results.JKindResult) JKindApi(jkind.api.JKindApi) PrintUtils(edu.umn.cs.crisys.safety.analysis.ast.visitors.PrintUtils) BufferedWriter(java.io.BufferedWriter) JRealizabilityApi(jkind.api.JRealizabilityApi) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) FaultTree(edu.umn.cs.crisys.safety.analysis.faultTree.FaultTree) KindApi(jkind.api.KindApi) JKindApi(jkind.api.JKindApi) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Aggregations

ConsistencyResult (com.rockwellcollins.atc.agree.analysis.ConsistencyResult)1 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)1 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)1 FTResolveVisitor (edu.umn.cs.crisys.safety.analysis.ast.visitors.FTResolveVisitor)1 PrintUtils (edu.umn.cs.crisys.safety.analysis.ast.visitors.PrintUtils)1 FaultTree (edu.umn.cs.crisys.safety.analysis.faultTree.FaultTree)1 IvcToFTGenerator (edu.umn.cs.crisys.safety.analysis.generators.IvcToFTGenerator)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Set (java.util.Set)1 JKindException (jkind.JKindException)1 JKindApi (jkind.api.JKindApi)1 JRealizabilityApi (jkind.api.JRealizabilityApi)1 KindApi (jkind.api.KindApi)1 JKindResult (jkind.api.results.JKindResult)1 JRealizabilityResult (jkind.api.results.JRealizabilityResult)1