Browse Source

preserved order of jani-properties as given in the file

tempestpy_adaptions
TimQu 6 years ago
parent
commit
019cc8b1a0
  1. 17
      src/storm-cli-utilities/model-handling.h
  2. 14
      src/storm-parsers/api/model_descriptions.cpp
  3. 3
      src/storm-parsers/api/model_descriptions.h
  4. 8
      src/storm-parsers/parser/JaniParser.cpp
  5. 4
      src/storm-parsers/parser/JaniParser.h

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

@ -71,15 +71,20 @@ namespace storm {
if (ioSettings.isJaniPropertiesSet()) {
if (ioSettings.areJaniPropertiesSelected()) {
// Make sure to preserve the provided order
for (auto const& propName : ioSettings.getSelectedJaniProperties()) {
auto propertyIt = janiPropertyInput.find(propName);
STORM_LOG_THROW(propertyIt != janiPropertyInput.end(), storm::exceptions::InvalidArgumentException, "No JANI property with name '" << propName << "' is known.");
input.properties.emplace_back(propertyIt->second);
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.");
}
} else {
for (auto const& property : janiPropertyInput) {
input.properties.emplace_back(property.second);
}
input.properties = janiPropertyInput;
}
}
}

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

@ -27,15 +27,19 @@ namespace storm {
// Add derived-operators and state-exit-rewards as these can be handled by all model builders
features.add(storm::jani::ModelFeature::DerivedOperators);
features.add(storm::jani::ModelFeature::StateExitRewards);
return parseJaniModel(filename, features);
auto parsedResult = parseJaniModel(filename, features);
std::map<std::string, storm::jani::Property> propertyMap;
for (auto const& property : parsedResult.second) {
propertyMap.emplace(property.getName(), property);
}
return std::make_pair(std::move(parsedResult.first), std::move(propertyMap));
}
std::pair<storm::jani::Model, std::map<std::string, storm::jani::Property>> parseJaniModel(std::string const& filename, storm::jani::ModelFeatures const& allowedFeatures) {
std::pair<storm::jani::Model, std::map<std::string, 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) {
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> modelAndFormulae = storm::parser::JaniParser::parse(filename);
modelAndFormulae.first.checkValid();
// TODO: properties
auto nonEliminatedFeatures = modelAndFormulae.first.restrictToFeatures(allowedFeatures);
auto nonEliminatedFeatures = modelAndFormulae.first.restrictToFeatures(allowedFeatures, modelAndFormulae.second);
STORM_LOG_THROW(nonEliminatedFeatures.empty(), storm::exceptions::NotSupportedException, "The used model feature(s) " << nonEliminatedFeatures.toString() << " is/are not in the list of allowed features.");
return modelAndFormulae;
}

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

@ -18,7 +18,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::map<std::string, 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);
}
}

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

@ -68,7 +68,7 @@ namespace storm {
return static_cast<int64_t>(num);
}
std::pair<storm::jani::Model, std::map<std::string, 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) {
JaniParser parser;
parser.readFile(path);
return parser.parseModel();
@ -85,7 +85,7 @@ namespace storm {
storm::utility::closeFile(file);
}
std::pair<storm::jani::Model, std::map<std::string, storm::jani::Property>> JaniParser::parseModel(bool parseProperties) {
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> JaniParser::parseModel(bool parseProperties) {
//jani-version
STORM_LOG_THROW(parsedStructure.count("jani-version") == 1, storm::exceptions::InvalidJaniException, "Jani-version must be given exactly once.");
uint64_t version = getUnsignedInt(parsedStructure.at("jani-version"), "jani version");
@ -200,7 +200,7 @@ namespace storm {
// Parse properties
storm::logic::RewardAccumulationEliminationVisitor rewAccEliminator(model);
STORM_LOG_THROW(parsedStructure.count("properties") <= 1, storm::exceptions::InvalidJaniException, "At most one list of properties can be given");
std::map<std::string, storm::jani::Property> properties;
std::vector<storm::jani::Property> properties;
if (parseProperties && parsedStructure.count("properties") == 1) {
STORM_LOG_THROW(parsedStructure.at("properties").is_array(), storm::exceptions::InvalidJaniException, "Properties should be an array");
for(auto const& propertyEntry : parsedStructure.at("properties")) {
@ -208,7 +208,7 @@ namespace storm {
auto prop = this->parseProperty(propertyEntry, scope.refine("property[" + std::to_string(properties.size()) + "]"));
// Eliminate reward accumulations as much as possible
rewAccEliminator.eliminateRewardAccumulations(prop);
properties.emplace(prop.getName(), prop);
properties.push_back(prop);
} catch (storm::exceptions::NotSupportedException const& ex) {
STORM_LOG_WARN("Cannot handle property: " << ex.what());
} catch (storm::exceptions::NotImplementedException const& ex) {

4
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::map<std::string, storm::jani::Property>> parse(std::string const& path);
static std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parse(std::string const& path);
protected:
void readFile(std::string const& path);
@ -74,7 +74,7 @@ namespace storm {
}
};
std::pair<storm::jani::Model, std::map<std::string, storm::jani::Property>> parseModel(bool parseProperties = true);
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parseModel(bool parseProperties = true);
storm::jani::Property parseProperty(json const& propertyStructure, Scope const& scope);
storm::jani::Automaton parseAutomaton(json const& automatonStructure, storm::jani::Model const& parentModel, Scope const& scope);
struct ParsedType {
Loading…
Cancel
Save