Browse Source

check validity, set standard composition

Former-commit-id: 526d484fd5 [formerly 3fac58583a]
Former-commit-id: fbb770a840
main
sjunges 9 years ago
parent
commit
b3204a178a
  1. 5
      src/parser/JaniParser.cpp
  2. 11
      src/storage/jani/JSONExporter.cpp
  3. 4
      src/storage/jani/JSONExporter.h
  4. 26
      src/storage/jani/Model.cpp
  5. 7
      src/storage/jani/Model.h
  6. 4
      src/utility/storm.cpp

5
src/parser/JaniParser.cpp

@ -129,6 +129,7 @@ namespace storm {
comment = getString(propertyStructure.at("comment"), "comment for property named '" + name + "'."); comment = getString(propertyStructure.at("comment"), "comment for property named '" + name + "'.");
} }
} }
std::shared_ptr<storm::jani::Constant> JaniParser::parseConstant(json const& constantStructure, std::string const& scopeDescription) { std::shared_ptr<storm::jani::Constant> JaniParser::parseConstant(json const& constantStructure, std::string const& scopeDescription) {
@ -336,7 +337,7 @@ namespace storm {
storm::jani::Variable const& getLValue(std::string const& ident, storm::jani::VariableSet const& globalVars, storm::jani::VariableSet const& localVars, std::string const& scopeDescription) { storm::jani::Variable const& getLValue(std::string const& ident, storm::jani::VariableSet const& globalVars, storm::jani::VariableSet const& localVars, std::string const& scopeDescription) {
if(localVars.hasVariable(ident)) { if(localVars.hasVariable(ident)) {
return globalVars.getVariable(ident);
return localVars.getVariable(ident);
} else if(globalVars.hasVariable(ident)) { } else if(globalVars.hasVariable(ident)) {
return globalVars.getVariable(ident); return globalVars.getVariable(ident);
} else { } else {
@ -675,7 +676,7 @@ namespace storm {
storm::jani::Variable const& lhs = getLValue(refstring, parentModel.getGlobalVariables(), automaton.getVariables(), "Assignment variable in edge from '" + sourceLoc + "' to '" + targetLoc + "' in automaton '" + name + "'"); storm::jani::Variable const& lhs = getLValue(refstring, parentModel.getGlobalVariables(), automaton.getVariables(), "Assignment variable in edge from '" + sourceLoc + "' to '" + targetLoc + "' in automaton '" + name + "'");
// value // value
STORM_LOG_THROW(assignmentEntry.count("value") == 1, storm::exceptions::InvalidJaniException, "Assignment in edge from '" << sourceLoc << "' to '" << targetLoc << "' in automaton '" << name << "' must have one value field"); STORM_LOG_THROW(assignmentEntry.count("value") == 1, storm::exceptions::InvalidJaniException, "Assignment in edge from '" << sourceLoc << "' to '" << targetLoc << "' in automaton '" << name << "' must have one value field");
storm::expressions::Expression assignmentExpr = parseExpression(assignmentEntry.at("value"), "assignment in edge from '" + sourceLoc + "' to '" + targetLoc + "' in automaton '" + name + "'");
storm::expressions::Expression assignmentExpr = parseExpression(assignmentEntry.at("value"), "assignment in edge from '" + sourceLoc + "' to '" + targetLoc + "' in automaton '" + name + "'", localVars);
// TODO check types // TODO check types
assignments.emplace_back(lhs, assignmentExpr); assignments.emplace_back(lhs, assignmentExpr);
} }

11
src/storage/jani/JSONExporter.cpp

@ -142,17 +142,20 @@ namespace storm {
void JsonExporter::toFile(storm::jani::Model const& janiModel, std::string const& filepath) {
void JsonExporter::toFile(storm::jani::Model const& janiModel, std::string const& filepath, bool checkValid) {
std::ofstream ofs; std::ofstream ofs;
ofs.open (filepath, std::ofstream::out ); ofs.open (filepath, std::ofstream::out );
if(ofs.is_open()) { if(ofs.is_open()) {
toStream(janiModel, ofs);
toStream(janiModel, ofs, checkValid);
} else { } else {
STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Cannot open " << filepath); STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Cannot open " << filepath);
} }
} }
void JsonExporter::toStream(storm::jani::Model const& janiModel, std::ostream& os) {
void JsonExporter::toStream(storm::jani::Model const& janiModel, std::ostream& os, bool checkValid) {
if(checkValid) {
janiModel.checkValid();
}
JsonExporter exporter; JsonExporter exporter;
exporter.convertModel(janiModel); exporter.convertModel(janiModel);
os << exporter.finalize().dump(4) << std::endl; os << exporter.finalize().dump(4) << std::endl;
@ -308,7 +311,9 @@ namespace storm {
modernjson::json autoEntry; modernjson::json autoEntry;
autoEntry["name"] = automaton.getName(); autoEntry["name"] = automaton.getName();
autoEntry["variables"] = buildVariablesArray(automaton.getVariables()); autoEntry["variables"] = buildVariablesArray(automaton.getVariables());
if(automaton.hasRestrictedInitialStates()) {
autoEntry["restrict-initial"]["exp"] = buildExpression(automaton.getInitialStatesRestriction()); autoEntry["restrict-initial"]["exp"] = buildExpression(automaton.getInitialStatesRestriction());
}
autoEntry["locations"] = buildLocationsArray(automaton.getLocations()); autoEntry["locations"] = buildLocationsArray(automaton.getLocations());
autoEntry["initial-locations"] = buildInitialLocations(automaton); autoEntry["initial-locations"] = buildInitialLocations(automaton);
autoEntry["edges"] = buildEdges(automaton.getEdges(), actionNames, automaton.buildIdToLocationNameMap()); autoEntry["edges"] = buildEdges(automaton.getEdges(), actionNames, automaton.buildIdToLocationNameMap());

4
src/storage/jani/JSONExporter.h

@ -32,8 +32,8 @@ namespace storm {
JsonExporter() = default; JsonExporter() = default;
public: public:
static void toFile(storm::jani::Model const& janiModel, std::string const& filepath);
static void toStream(storm::jani::Model const& janiModel, std::ostream& ostream);
static void toFile(storm::jani::Model const& janiModel, std::string const& filepath, bool checkValid = true);
static void toStream(storm::jani::Model const& janiModel, std::ostream& ostream, bool checkValid = false);
private: private:
void convertModel(storm::jani::Model const& model); void convertModel(storm::jani::Model const& model);

26
src/storage/jani/Model.cpp

@ -252,6 +252,10 @@ namespace storm {
this->composition = composition; this->composition = composition;
} }
void Model::setStandardSystemComposition() {
setSystemComposition(getStandardSystemComposition());
}
std::set<std::string> Model::getActionNames(bool includeSilent) const { std::set<std::string> Model::getActionNames(bool includeSilent) const {
std::set<std::string> result; std::set<std::string> result;
for (auto const& entry : actionToIndex) { for (auto const& entry : actionToIndex) {
@ -435,25 +439,11 @@ namespace storm {
} }
} }
bool Model::checkValidity(bool logdbg) const {
void Model::checkValid() const {
// TODO switch to exception based return value. // TODO switch to exception based return value.
if (version == 0) {
if(logdbg) STORM_LOG_DEBUG("Jani version is unspecified");
return false;
}
if(modelType == ModelType::UNDEFINED) {
if(logdbg) STORM_LOG_DEBUG("Model type is unspecified");
return false;
}
if(automata.empty()) {
if(logdbg) STORM_LOG_DEBUG("No automata specified");
return false;
}
// All checks passed.
return true;
STORM_LOG_ASSERT(getModelType() != storm::jani::ModelType::UNDEFINED, "Model type not set");
STORM_LOG_ASSERT(!automata.empty(), "No automata set");
STORM_LOG_ASSERT(composition != nullptr, "Composition is not set");
} }

7
src/storage/jani/Model.h

@ -221,6 +221,11 @@ namespace storm {
*/ */
void setSystemComposition(std::shared_ptr<Composition> const& composition); void setSystemComposition(std::shared_ptr<Composition> const& composition);
/*!
* Sets the system composition to be the fully-synchronizing parallel composition of all automat
* @see getStandardSystemComposition
*/
void setStandardSystemComposition();
/*! /*!
* Gets the system composition as the standard, fully-synchronizing parallel composition. * Gets the system composition as the standard, fully-synchronizing parallel composition.
*/ */
@ -328,7 +333,7 @@ namespace storm {
/*! /*!
* Checks if the model is valid JANI, which should be verified before any further operations are applied to a model. * Checks if the model is valid JANI, which should be verified before any further operations are applied to a model.
*/ */
bool checkValidity(bool logdbg = true) const;
void checkValid() const;
private: private:
/// The model name. /// The model name.

4
src/utility/storm.cpp

@ -17,9 +17,7 @@ namespace storm {
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parseJaniModel(std::string const& path) { std::pair<storm::jani::Model, std::vector<storm::jani::Property>> parseJaniModel(std::string const& path) {
std::pair<storm::jani::Model, std::vector<storm::jani::Property>> modelAndFormulae = storm::parser::JaniParser::parse(path); std::pair<storm::jani::Model, std::vector<storm::jani::Property>> modelAndFormulae = storm::parser::JaniParser::parse(path);
if(!modelAndFormulae.first.checkValidity(true)) {
STORM_LOG_THROW(false, storm::exceptions::FileIoException, "Jani file parsing yields invalid model.");
}
modelAndFormulae.first.checkValid();
return modelAndFormulae; return modelAndFormulae;
} }

Loading…
Cancel
Save