Browse Source

added api call that directly applies a given jani-property filter

tempestpy_adaptions
TimQu 6 years ago
parent
commit
bf40fb54f2
  1. 27
      src/storm-cli-utilities/model-handling.h
  2. 31
      src/storm-conv-cli/storm-conv.cpp
  3. 24
      src/storm-parsers/api/model_descriptions.cpp
  4. 6
      src/storm-parsers/api/model_descriptions.h
  5. 4
      src/storm-parsers/parser/JaniParser.cpp
  6. 2
      src/storm-parsers/parser/JaniParser.h

27
src/storm-cli-utilities/model-handling.h

@ -65,27 +65,20 @@ namespace storm {
input.model = storm::api::parseProgram(ioSettings.getPrismInputFilename(), storm::settings::getModule<storm::settings::modules::BuildSettings>().isPrismCompatibilityEnabled());
} else {
storm::jani::ModelFeatures supportedFeatures = storm::api::getSupportedJaniFeatures(builderType);
auto janiInput = storm::api::parseJaniModel(ioSettings.getJaniInputFilename(), supportedFeatures);
input.model = janiInput.first;
auto const& janiPropertyInput = janiInput.second;
boost::optional<std::vector<std::string>> propertyFilter;
if (ioSettings.isJaniPropertiesSet()) {
if (ioSettings.areJaniPropertiesSelected()) {
// Make sure to preserve the provided order
for (auto const& propName : ioSettings.getSelectedJaniProperties()) {
bool found = false;
for (auto const& property : janiPropertyInput) {
if (property.getName() == propName) {
input.properties.emplace_back(property);
found = true;
break;
}
}
STORM_LOG_THROW(found, storm::exceptions::InvalidArgumentException, "No JANI property with name '" << propName << "' is known.");
}
propertyFilter = ioSettings.getSelectedJaniProperties();
} else {
input.properties = janiPropertyInput;
propertyFilter = boost::none;
}
} else {
propertyFilter = std::vector<std::string>();
}
auto janiInput = storm::api::parseJaniModel(ioSettings.getJaniInputFilename(), supportedFeatures, propertyFilter);
input.model = std::move(janiInput.first);
if (ioSettings.isJaniPropertiesSet()) {
input.properties = std::move(janiInput.second);
}
}
}

31
src/storm-conv-cli/storm-conv.cpp

@ -209,18 +209,31 @@ namespace storm {
auto const& input = storm::settings::getModule<storm::settings::modules::ConversionInputSettings>();
// Parse the jani model
auto janiModelProperties = storm::api::parseJaniModel(input.getJaniInputFilename(), storm::jani::getAllKnownModelFeatures());
// Parse properties (if available, otherwise take the ones from the jani file)
std::vector<storm::jani::Property> properties;
if (input.isPropertyInputSet()) {
boost::optional<std::set<std::string>> propertyFilter = storm::api::parsePropertyFilter(input.getPropertyInputFilter());
properties = storm::api::parsePropertiesForSymbolicModelDescription(input.getPropertyInput(), janiModelProperties.first, propertyFilter);
// Parse the jani model and selected properties
boost::optional<std::vector<std::string>> janiPropertyFilter;
if (input.isJaniPropertiesSet()) {
if (input.areJaniPropertiesSelected()) {
janiPropertyFilter = input.getSelectedJaniProperties();
} else {
janiPropertyFilter = boost::none;
}
} else {
for (auto const& p : janiModelProperties.second) {
properties.push_back(p.second);
if (input.isPropertyInputSet()) {
janiPropertyFilter = std::vector<std::string>();
} else {
// If no properties are selected, take the ones from the jani file.
janiPropertyFilter = boost::none;
}
}
auto janiModelProperties = storm::api::parseJaniModel(input.getJaniInputFilename(), storm::jani::getAllKnownModelFeatures(), janiPropertyFilter);
// Parse additional properties given from command line
std::vector<storm::jani::Property> properties = std::move(janiModelProperties.second);
if (input.isPropertyInputSet()) {
boost::optional<std::set<std::string>> propertyFilter = storm::api::parsePropertyFilter(input.getPropertyInputFilter());
auto additionalProperties = storm::api::parsePropertiesForSymbolicModelDescription(input.getPropertyInput(), janiModelProperties.first, propertyFilter);
properties.insert(properties.end(), additionalProperties.begin(), additionalProperties.end());
}
storm::storage::SymbolicModelDescription symbDescr(janiModelProperties.first);

24
src/storm-parsers/api/model_descriptions.cpp

@ -35,8 +35,28 @@ namespace storm {
return std::make_pair(std::move(parsedResult.first), std::move(propertyMap));
}
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parseJaniModel(std::string const& filename, storm::jani::ModelFeatures const& allowedFeatures) {
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> modelAndFormulae = storm::parser::JaniParser::parse(filename);
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parseJaniModel(std::string const& filename, storm::jani::ModelFeatures const& allowedFeatures, boost::optional<std::vector<std::string>> const& propertyFilter) {
bool parseProperties = !propertyFilter.is_initialized() || !propertyFilter.get().empty();
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> modelAndFormulae = storm::parser::JaniParser::parse(filename, parseProperties);
// eliminate unselected properties.
if (propertyFilter.is_initialized()) {
std::vector<storm::jani::Property> newProperties;
// Make sure to preserve the provided order
for (auto const& propName : propertyFilter.get()) {
bool found = false;
for (auto const& property : modelAndFormulae.second) {
if (property.getName() == propName) {
newProperties.push_back(std::move(property));
found = true;
break;
}
}
STORM_LOG_ERROR_COND(found, "No JANI property with name '" << propName << "' is known.");
}
modelAndFormulae.second = std::move(newProperties);
}
modelAndFormulae.first.checkValid();
auto nonEliminatedFeatures = modelAndFormulae.first.restrictToFeatures(allowedFeatures, modelAndFormulae.second);

6
src/storm-parsers/api/model_descriptions.h

@ -2,7 +2,8 @@
#include <string>
#include <map>
#include <storm/storage/jani/ModelFeatures.h>
#include <vector>
#include <boost/optional.hpp>
namespace storm {
namespace prism {
@ -10,6 +11,7 @@ namespace storm {
}
namespace jani {
class Model;
class ModelFeatures;
class Property;
}
@ -18,6 +20,6 @@ namespace storm {
storm::prism::Program parseProgram(std::string const& filename, bool prismCompatibility = false, bool simplify = true);
std::pair<storm::jani::Model, std::map<std::string, storm::jani::Property>> parseJaniModel(std::string const& filename);
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parseJaniModel(std::string const& filename, storm::jani::ModelFeatures const& allowedFeatures);
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parseJaniModel(std::string const& filename, storm::jani::ModelFeatures const& allowedFeatures, boost::optional<std::vector<std::string>> const& propertyFilter = boost::none);
}
}

4
src/storm-parsers/parser/JaniParser.cpp

@ -68,10 +68,10 @@ namespace storm {
return static_cast<int64_t>(num);
}
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> JaniParser::parse(std::string const& path) {
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> JaniParser::parse(std::string const& path, bool parseProperties) {
JaniParser parser;
parser.readFile(path);
return parser.parseModel();
return parser.parseModel(parseProperties);
}
JaniParser::JaniParser(std::string const& jsonstring) {

2
src/storm-parsers/parser/JaniParser.h

@ -44,7 +44,7 @@ namespace storm {
JaniParser() : expressionManager(new storm::expressions::ExpressionManager()) {}
JaniParser(std::string const& jsonstring);
static std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parse(std::string const& path);
static std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parse(std::string const& path, bool parseProperties = true);
protected:
void readFile(std::string const& path);

Loading…
Cancel
Save