Skip to content

Commit 5f3d28f

Browse files
committed
Model export gets label names from Model attachments if modeLInfo is absent.
1 parent a35e0fe commit 5f3d28f

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

prism/src/explicit/StateModelChecker.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,7 @@
8080
import parser.type.TypeDouble;
8181
import parser.visitor.ASTTraverseModify;
8282
import parser.visitor.ReplaceLabels;
83-
import prism.Accuracy;
84-
import prism.Evaluator;
85-
import prism.Filter;
86-
import prism.ModelInfo;
87-
import prism.ModelType;
88-
import prism.Pair;
89-
import prism.Prism;
90-
import prism.PrismComponent;
91-
import prism.PrismException;
92-
import prism.PrismFileLog;
93-
import prism.PrismLangException;
94-
import prism.PrismLog;
95-
import prism.PrismNotSupportedException;
96-
import prism.PrismSettings;
97-
import prism.Result;
98-
import prism.RewardGenerator;
83+
import prism.*;
9984

10085
/**
10186
* Super class for explicit-state model checkers.
@@ -1473,6 +1458,25 @@ private Object replaceWithLabel(Expression e) throws PrismLangException
14731458
}
14741459
}
14751460

1461+
/**
1462+
* Get a {@link ModelInfo} object for the provided model,
1463+
* containing info about model type, variables and labels.
1464+
* If this is already stored locally in {@link #modelInfo}, use that.
1465+
* If not construct one from data attached to the model.
1466+
*/
1467+
protected <Value> ModelInfo getModelInfo(Model<Value> model) throws PrismException
1468+
{
1469+
if (modelInfo != null) {
1470+
return modelInfo;
1471+
}
1472+
BasicModelInfo modelInfo = new BasicModelInfo(model.getModelType());
1473+
if (model.getVarList() != null) {
1474+
modelInfo.setVarList(model.getVarList());
1475+
}
1476+
model.getLabels().forEach(label -> modelInfo.getLabelNameList().add(label));
1477+
return modelInfo;
1478+
}
1479+
14761480
/**
14771481
* Construct rewards for the reward structure with index r of the reward generator and a model.
14781482
* Ensures non-negative rewards.
@@ -1594,9 +1598,9 @@ protected <Value> Pair<List<Rewards<Value>>, List<String>> getAllRewards(Model<V
15941598
* (always present) stored model info, plus any additional labels attached directly
15951599
* to the model that are not already included.
15961600
*/
1597-
protected List<String> getAllLabelNames(Model<?> model)
1601+
protected List<String> getAllLabelNames(Model<?> model) throws PrismException
15981602
{
1599-
List<String> labelNames = new ArrayList<>(modelInfo.getLabelNames());
1603+
List<String> labelNames = new ArrayList<>(getModelInfo(model).getLabelNames());
16001604
for (String name : model.getLabels()) {
16011605
if (!labelNames.contains(name)) {
16021606
labelNames.add(name);
@@ -1646,7 +1650,7 @@ public <Value> void exportModel(Model<Value> model, ModelExportTask exportTask)
16461650
default:
16471651
throw new PrismNotSupportedException("Export " + exportOptions.getFormat().description() + " not supported by explicit engine");
16481652
}
1649-
exporter.setModelInfo(modelInfo);
1653+
exporter.setModelInfo(getModelInfo(model));
16501654
File file = exportTask.getFile();
16511655
// Disallow stdout export for binary formats
16521656
if (exportOptions.getFormat().isBinary() && !exportOptions.getBinaryAsText() && file == null) {

0 commit comments

Comments
 (0)