Browse Source

Transient probability export to file for time range adds time to filenames.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@4693 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 14 years ago
parent
commit
8cdac825ce
  1. 36
      prism/src/prism/Prism.java
  2. 12
      prism/src/prism/PrismUtils.java

36
prism/src/prism/Prism.java

@ -2614,7 +2614,7 @@ public class Prism implements PrismSettingsListener
* The exportType should be EXPORT_PLAIN or EXPORT_MATLAB. * The exportType should be EXPORT_PLAIN or EXPORT_MATLAB.
* Optionally (if non-null), read in the initial probability distribution from a file. * Optionally (if non-null), read in the initial probability distribution from a file.
*/ */
public void doTransient(double time, int exportType, File file, File fileIn) throws PrismException
public void doTransient(double time, int exportType, File fileOut, File fileIn) throws PrismException
{ {
long l = 0; // timer long l = 0; // timer
ModelChecker mc = null; ModelChecker mc = null;
@ -2628,7 +2628,7 @@ public class Prism implements PrismSettingsListener
if (time < 0) if (time < 0)
throw new PrismException("Cannot compute transient probabilities for negative time value"); throw new PrismException("Cannot compute transient probabilities for negative time value");
if (file != null && getEngine() == MTBDD)
if (fileOut != null && getEngine() == MTBDD)
throw new PrismException("Transient probability export only supported for sparse/hybrid engines"); throw new PrismException("Transient probability export only supported for sparse/hybrid engines");
mainLog.printSeparator(); mainLog.printSeparator();
@ -2676,16 +2676,16 @@ public class Prism implements PrismSettingsListener
// print message // print message
mainLog.print("\nPrinting transient probabilities "); mainLog.print("\nPrinting transient probabilities ");
mainLog.print(getStringForExportType(exportType) + " "); mainLog.print(getStringForExportType(exportType) + " ");
mainLog.println(getDestinationStringForFile(file));
mainLog.println(getDestinationStringForFile(fileOut));
// create new file log or use main log // create new file log or use main log
tmpLog = getPrismLogForFile(file);
tmpLog = getPrismLogForFile(fileOut);
// print out or export probabilities // print out or export probabilities
if (!getExplicit()) if (!getExplicit())
probs.print(tmpLog, file == null, exportType == EXPORT_MATLAB, file == null);
probs.print(tmpLog, fileOut == null, exportType == EXPORT_MATLAB, fileOut == null);
else else
probsExpl.print(tmpLog, file == null, exportType == EXPORT_MATLAB, file == null, true);
probsExpl.print(tmpLog, fileOut == null, exportType == EXPORT_MATLAB, fileOut == null, true);
// print out computation time // print out computation time
mainLog.println("\nTime for transient probability computation: " + l / 1000.0 + " seconds."); mainLog.println("\nTime for transient probability computation: " + l / 1000.0 + " seconds.");
@ -2695,7 +2695,7 @@ public class Prism implements PrismSettingsListener
probs.clear(); probs.clear();
else else
probsExpl.clear(); probsExpl.clear();
if (file != null)
if (fileOut != null)
tmpLog.close(); tmpLog.close();
} }
@ -2708,7 +2708,7 @@ public class Prism implements PrismSettingsListener
* The exportType should be EXPORT_PLAIN or EXPORT_MATLAB. * The exportType should be EXPORT_PLAIN or EXPORT_MATLAB.
* Optionally (if non-null), read in the initial probability distribution from a file. * Optionally (if non-null), read in the initial probability distribution from a file.
*/ */
public void doTransient(UndefinedConstants times, int exportType, File file, File fileIn) throws PrismException
public void doTransient(UndefinedConstants times, int exportType, File fileOut, File fileIn) throws PrismException
{ {
int i, timeInt = 0, initTimeInt = 0; int i, timeInt = 0, initTimeInt = 0;
double timeDouble = 0, initTimeDouble = 0; double timeDouble = 0, initTimeDouble = 0;
@ -2717,11 +2717,12 @@ public class Prism implements PrismSettingsListener
StateValues probs = null, initDist = null; StateValues probs = null, initDist = null;
explicit.StateValues probsExpl = null, initDistExpl = null; explicit.StateValues probsExpl = null, initDistExpl = null;
PrismLog tmpLog = null; PrismLog tmpLog = null;
File fileOutActual = null;
if (!(currentModelType == ModelType.CTMC || currentModelType == ModelType.DTMC)) if (!(currentModelType == ModelType.CTMC || currentModelType == ModelType.DTMC))
throw new PrismException("Steady-state probabilities only computed for DTMCs/CTMCs"); throw new PrismException("Steady-state probabilities only computed for DTMCs/CTMCs");
if (file != null && getEngine() == MTBDD)
if (fileOut != null && getEngine() == MTBDD)
throw new PrismException("Transient probability export only supported for sparse/hybrid engines"); throw new PrismException("Transient probability export only supported for sparse/hybrid engines");
// no specific states format for MRMC // no specific states format for MRMC
@ -2784,19 +2785,26 @@ public class Prism implements PrismSettingsListener
l = System.currentTimeMillis() - l; l = System.currentTimeMillis() - l;
// If output is to a file and there are multiple points, change filename
if (fileOut != null && times.getNumPropertyIterations() > 1) {
fileOutActual = new File(PrismUtils.addSuffixToFilename(fileOut.getPath(), time.toString()));
} else {
fileOutActual = fileOut;
}
// print message // print message
mainLog.print("\nPrinting transient probabilities "); mainLog.print("\nPrinting transient probabilities ");
mainLog.print(getStringForExportType(exportType) + " "); mainLog.print(getStringForExportType(exportType) + " ");
mainLog.println(getDestinationStringForFile(file));
mainLog.println(getDestinationStringForFile(fileOutActual));
// create new file log or use main log // create new file log or use main log
tmpLog = getPrismLogForFile(file);
tmpLog = getPrismLogForFile(fileOutActual);
// print out or export probabilities // print out or export probabilities
if (!getExplicit()) if (!getExplicit())
probs.print(tmpLog, file == null, exportType == EXPORT_MATLAB, file == null);
probs.print(tmpLog, fileOut == null, exportType == EXPORT_MATLAB, fileOut == null);
else else
probsExpl.print(tmpLog, file == null, exportType == EXPORT_MATLAB, file == null, true);
probsExpl.print(tmpLog, fileOut == null, exportType == EXPORT_MATLAB, fileOut == null, true);
// print out computation time // print out computation time
mainLog.println("\nTime for transient probability computation: " + l / 1000.0 + " seconds."); mainLog.println("\nTime for transient probability computation: " + l / 1000.0 + " seconds.");
@ -2814,7 +2822,7 @@ public class Prism implements PrismSettingsListener
probs.clear(); probs.clear();
else else
probsExpl.clear(); probsExpl.clear();
if (file != null)
if (fileOut != null)
tmpLog.close(); tmpLog.close();
} }

12
prism/src/prism/PrismUtils.java

@ -151,12 +151,20 @@ public class PrismUtils
* Modify a filename f, appending a counter i just before the filetype extension. * Modify a filename f, appending a counter i just before the filetype extension.
*/ */
public static String addCounterSuffixToFilename(String f, int i) public static String addCounterSuffixToFilename(String f, int i)
{
return addSuffixToFilename(f, "" + i);
}
/**
* Modify a filename f, appending a string s just before the filetype extension.
*/
public static String addSuffixToFilename(String f, String s)
{ {
int j = f.lastIndexOf("."); int j = f.lastIndexOf(".");
if (j != -1) { if (j != -1) {
return f.substring(0, j) + i + f.substring(j);
return f.substring(0, j) + s + f.substring(j);
} else { } else {
return f + i;
return f + s;
} }
} }

Loading…
Cancel
Save