Browse Source

substitute formulas in properties after parsing

tempestpy_adaptions
TimQu 6 years ago
parent
commit
4d74ec501a
  1. 2
      src/storm-parsers/api/properties.cpp
  2. 9
      src/storm-parsers/parser/FormulaParser.cpp
  3. 8
      src/storm/storage/prism/Program.cpp
  4. 7
      src/storm/storage/prism/Program.h

2
src/storm-parsers/api/properties.cpp

@ -58,7 +58,7 @@ namespace storm {
std::vector <storm::jani::Property> parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional <std::set<std::string>> const &propertyFilter) {
storm::parser::FormulaParser formulaParser(program);
auto formulas = parseProperties(formulaParser, inputString, propertyFilter);
return substituteConstantsInProperties(formulas, program.getConstantsSubstitution());
return substituteConstantsInProperties(formulas, program.getConstantsFormulasSubstitution());
}
std::vector <storm::jani::Property> parsePropertiesForSymbolicModelDescription(std::string const &inputString, storm::storage::SymbolicModelDescription const &modelDescription, boost::optional <std::set<std::string>> const &propertyFilter) {

9
src/storm-parsers/parser/FormulaParser.cpp

@ -32,20 +32,11 @@ namespace storm {
}
FormulaParser::FormulaParser(storm::prism::Program const& program) : manager(program.getManager().getSharedPointer()), grammar(new FormulaParserGrammar(program.getManager().getSharedPointer())) {
this->addFormulasAsIdentifiers(program);
}
FormulaParser::FormulaParser(storm::prism::Program& program) : manager(program.getManager().getSharedPointer()), grammar(new FormulaParserGrammar(program.getManager().getSharedPointer())) {
this->addFormulasAsIdentifiers(program);
}
void FormulaParser::addFormulasAsIdentifiers(storm::prism::Program const& program) {
// Make the formulas of the program available to the parser.
for (auto const& formula : program.getFormulas()) {
this->addIdentifierExpression(formula.getName(), formula.getExpression());
}
}
FormulaParser::FormulaParser(FormulaParser const& other) : FormulaParser(other.manager) {
other.identifiers_.for_each([=] (std::string const& name, storm::expressions::Expression const& expression) { this->addIdentifierExpression(name, expression); });
}

8
src/storm/storage/prism/Program.cpp

@ -333,6 +333,14 @@ namespace storm {
return constantsSubstitution;
}
std::map<storm::expressions::Variable, storm::expressions::Expression> Program::getConstantsFormulasSubstitution() const {
auto result = getConstantsSubstitution();
for (auto const& formula : this->getFormulas()) {
result.emplace(formula.getExpressionVariable(), formula.getExpression());
}
return result;
}
std::size_t Program::getNumberOfConstants() const {
return this->getConstants().size();
}

7
src/storm/storage/prism/Program.h

@ -138,6 +138,13 @@ namespace storm {
*/
std::map<storm::expressions::Variable, storm::expressions::Expression> getConstantsSubstitution() const;
/*!
* Retrieves a mapping of all defined constants and formula variables to their defining expressions
*
* @return A mapping from constants and formulas to their expressions.
*/
std::map<storm::expressions::Variable, storm::expressions::Expression> getConstantsFormulasSubstitution() const;
/*!
* Retrieves all constants defined in the program.
*

Loading…
Cancel
Save