diff --git a/prism/src/prism/Prism.java b/prism/src/prism/Prism.java index d8c5259c..6932c0e1 100644 --- a/prism/src/prism/Prism.java +++ b/prism/src/prism/Prism.java @@ -64,6 +64,7 @@ import simulator.PrismModelExplorer; import simulator.SimulatorEngine; import simulator.method.SimulationMethod; import sparse.PrismSparse; +import strat.Strategy; import dv.DoubleVector; import explicit.CTMC; import explicit.CTMCModelChecker; @@ -2671,6 +2672,31 @@ public class Prism implements PrismSettingsListener getSimulator().modelCheckExperiment(currentModulesFile, propertiesFile, undefinedConstants, results, expr, initialState, pathLength, simMethod); } + /** + * Export a strategy (for the currently loaded model); + * @param strat The strategy + * @param file File to output the path to (stdout if null) + */ + public void exportStrategy(Strategy strat, File file) throws FileNotFoundException, PrismException + { + PrismLog tmpLog; + + // Print message + mainLog.print("\nExporting strategy "); + //mainLog.print(getStringForExportType(exportType) + " "); + mainLog.println(getDestinationStringForFile(file)); + + // Create new file log or use main log + tmpLog = getPrismLogForFile(file); + + // Export + strat.export(tmpLog); + + // Tidy up + if (file != null) + tmpLog.close(); + } + /** * Generate a random path through the model using the simulator. * @param modulesFile The model diff --git a/prism/src/prism/PrismCL.java b/prism/src/prism/PrismCL.java index ec764659..9ae68620 100644 --- a/prism/src/prism/PrismCL.java +++ b/prism/src/prism/PrismCL.java @@ -371,9 +371,16 @@ public class PrismCL implements PrismModelListener } // if a strategy was generated, and we need to export it, do so - if (res.getStrategy() != null) { - mainLog.println("\nExporting strategy..."); - res.getStrategy().export(mainLog); + if (exportstrat && res.getStrategy() != null) { + try { + prism.exportStrategy(res.getStrategy(), exportStratFilename.equals("stdout") ? null : new File(exportStratFilename)); + } + // in case of error, report it and proceed + catch (FileNotFoundException e) { + error("Couldn't open file \"" + exportStratFilename + "\" for output"); + } catch (PrismException e) { + error(e.getMessage()); + } } // if required, check result against expected value