From 023d49fc77e483eadd987bacce2e0859aed96f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=A4rcker?= Date: Thu, 23 May 2019 09:39:44 +0200 Subject: [PATCH] Implement property switch to recognize multiple properties #107 The switch -property (or -prop) now recognizes a comma-separated list of property indices or property names (possibly mixed). --- prism/src/prism/PrismCL.java | 52 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/prism/src/prism/PrismCL.java b/prism/src/prism/PrismCL.java index 41ff6de2..d1c84bbc 100644 --- a/prism/src/prism/PrismCL.java +++ b/prism/src/prism/PrismCL.java @@ -104,7 +104,7 @@ public class PrismCL implements PrismModelListener private boolean testExitsOnFail = true; // property info - private Object propertyToCheck = null; + private List propertyIndices = null; private String propertyString = ""; // argument to -const switch @@ -677,28 +677,30 @@ public class PrismCL implements PrismModelListener numPropertiesToCheck = 0; } // unless specified, verify all properties - else if (propertyToCheck == null) { + else if (propertyIndices == null) { numPropertiesToCheck = propertiesFile.getNumProperties(); for (i = 0; i < numPropertiesToCheck; i++) { propertiesToCheck.add(propertiesFile.getPropertyObject(i)); } } - // otherwise just verify the relevant property + // otherwise just verify the specified properties else { - if (propertyToCheck instanceof Integer) { - int propIndex = (Integer) propertyToCheck; - if (propIndex <= 0 || propIndex > propertiesFile.getNumProperties()) - errorAndExit("There is not a property " + propIndex + " to verify"); - numPropertiesToCheck = 1; - propertiesToCheck.add(propertiesFile.getPropertyObject(propIndex - 1)); - } else if (propertyToCheck instanceof String) { - Property p = propertiesFile.getPropertyObjectByName((String) propertyToCheck); - if (p == null) - errorAndExit("There is not a property \"" + propertyToCheck + "\" to check"); - numPropertiesToCheck = 1; - propertiesToCheck.add(p); - } else { - errorAndExit("There is not a property " + propertyToCheck + " to check"); + for (Object o : propertyIndices) { + if (o instanceof Integer) { + int propIndex = (Integer) o; + if (propIndex <= 0 || propIndex > propertiesFile.getNumProperties()) + errorAndExit("There is not a property " + propIndex + " to verify"); + numPropertiesToCheck += 1; + propertiesToCheck.add(propertiesFile.getPropertyObject(propIndex - 1)); + } else if (o instanceof String) { + Property p = propertiesFile.getPropertyObjectByName((String) o); + if (p == null) + errorAndExit("There is not a property \"" + propertyIndices + "\" to check"); + numPropertiesToCheck += 1; + propertiesToCheck.add(p); + } else { + errorAndExit("There is not a property " + propertyIndices + " to check"); + } } } } @@ -1167,10 +1169,16 @@ public class PrismCL implements PrismModelListener // which property to check (int index or string name) else if (sw.equals("prop") || sw.equals("property")) { if (i < args.length - 1) { - try { - propertyToCheck = Integer.parseInt(args[++i]); - } catch (NumberFormatException e) { - propertyToCheck = args[i]; + String[] props = args[++i].trim().split(","); + propertyIndices = new ArrayList(); + for (String p : props) { + if (!p.isEmpty()) { + try { + propertyIndices.add(Integer.parseInt(p)); + } catch (NumberFormatException e) { + propertyIndices.add(p); + } + } } } else { errorAndExit("No value specified for -" + sw + " switch"); @@ -2395,7 +2403,7 @@ public class PrismCL implements PrismModelListener mainLog.println("-settings ................ Load settings from "); mainLog.println(); mainLog.println("-pf (or -pctl or -csl) . Model check properties "); - mainLog.println("-property (or -prop ) ... Only model check property with index/name "); + mainLog.println("-property (or -prop) .... Only model check properties included in list of indices/names"); mainLog.println("-const .................. Define constant values as (e.g. for experiments)"); mainLog.println("-steadystate (or -ss) .......... Compute steady-state probabilities (D/CTMCs only)"); mainLog.println("-transient (or -tr ) .... Compute transient probabilities for time (or time range) (D/CTMCs only)");