Browse Source

Model type auto-detection for partially observable models.

MDPs/PTAs are considered to be POMDPs/POPTAs if they have observables.
accumulation-v4.7
Dave Parker 5 years ago
parent
commit
c7cf09659c
  1. 31
      prism/src/parser/PrismParser.java
  2. 2
      prism/src/parser/PrismParser.jj
  3. 29
      prism/src/parser/ast/ModulesFile.java

31
prism/src/parser/PrismParser.java

@ -1389,6 +1389,7 @@ Expression Init() throws ParseException {Expression expr = null;
static final public
void Observables(ModulesFile mf) throws ParseException {String name = null;
jj_consume_token(OBSERVABLES);
mf.setHasObservables(true);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case REG_IDENT:{
name = Identifier();
@ -3765,12 +3766,6 @@ fl.setLHS(s);
finally { jj_save(17, xla); }
}
static private boolean jj_3R_33()
{
if (jj_3R_30()) return true;
return false;
}
static private boolean jj_3R_164()
{
if (jj_scan_token(MAX)) return true;
@ -4247,15 +4242,6 @@ fl.setLHS(s);
return false;
}
static private boolean jj_3_2()
{
if (jj_scan_token(DQUOTE)) return true;
if (jj_3R_30()) return true;
if (jj_scan_token(DQUOTE)) return true;
if (jj_scan_token(COLON)) return true;
return false;
}
static private boolean jj_3R_141()
{
if (jj_3R_153()) return true;
@ -4268,6 +4254,15 @@ fl.setLHS(s);
return false;
}
static private boolean jj_3_2()
{
if (jj_scan_token(DQUOTE)) return true;
if (jj_3R_30()) return true;
if (jj_scan_token(DQUOTE)) return true;
if (jj_scan_token(COLON)) return true;
return false;
}
static private boolean jj_3R_140()
{
if (jj_3R_152()) return true;
@ -5598,6 +5593,12 @@ fl.setLHS(s);
return false;
}
static private boolean jj_3R_33()
{
if (jj_3R_30()) return true;
return false;
}
static private boolean jj_initialized_once = false;
/** Generated Token Manager. */
static public PrismParserTokenManager token_source;

2
prism/src/parser/PrismParser.jj

@ -953,7 +953,7 @@ void Observables(ModulesFile mf) :
String name = null;
}
{
(<OBSERVABLES>
(<OBSERVABLES> { mf.setHasObservables(true); }
( name = Identifier() { mf.addObservableVar(name); }
( <COMMA> name = Identifier() { mf.addObservableVar(name); } )* )?
<ENDOBSERVABLES>)

29
prism/src/parser/ast/ModulesFile.java

@ -68,7 +68,8 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
private ArrayList<RewardStruct> rewardStructs; // Rewards structures
private List<String> rewardStructNames; // Names of reward structures
private Expression initStates; // Initial states specification
private List<String> obsVars; // Observable variables
private boolean hasObservables; // Observables info
private List<String> obsVars;
// Lists of all identifiers used and where
private HashMap<String, ASTElement> identUsage;
@ -102,6 +103,7 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
rewardStructs = new ArrayList<RewardStruct>();
rewardStructNames = new ArrayList<String>();
initStates = null;
hasObservables = false;
obsVars = new ArrayList<String>();
identUsage = new HashMap<>();
varDecls = new Vector<Declaration>();
@ -258,6 +260,11 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
initStates = e;
}
public void setHasObservables(boolean hasObservables)
{
this.hasObservables = hasObservables;
}
public void addObservableVar(String n)
{
obsVars.add(n);
@ -543,6 +550,15 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
return initStates;
}
/**
* Does this model have an observables...endobservables block?
* (i.e., is it a partially observable model?)
*/
public boolean hasObservables()
{
return hasObservables;
}
@Override
public List<String> getObservableVars()
{
@ -1335,11 +1351,19 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
// Then, even if already specified, update the model type
// based on the existence of certain features
boolean isRealTime = containsClockVariables();
boolean isPartObs = hasObservables();
if (isRealTime) {
if (modelType == ModelType.MDP || modelType == ModelType.LTS) {
modelType = ModelType.PTA;
}
}
if (isPartObs) {
if (modelType == ModelType.MDP || modelType == ModelType.LTS) {
modelType = ModelType.POMDP;
} else if (modelType == ModelType.PTA) {
modelType = ModelType.POPTA;
}
}
}
/**
@ -1407,7 +1431,7 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
tmp += "\n";
s += tmp;
if (!obsVars.isEmpty()) {
if (hasObservables()) {
s += "observables " + String.join(",", obsVars) + " endobservables\n\n";
}
@ -1479,6 +1503,7 @@ public class ModulesFile extends ASTElement implements ModelInfo, RewardGenerato
}
if (initStates != null)
ret.setInitialStates(initStates.deepCopy());
ret.hasObservables = hasObservables;
for (String ov : obsVars)
ret.addObservableVar(ov);
// Copy other (generated) info

Loading…
Cancel
Save