Browse Source

recursive parallel composition support in im and export

Former-commit-id: 890653ddba [formerly be393c7189]
Former-commit-id: 2311af7739
main
sjunges 9 years ago
parent
commit
1db826c0e2
  1. 22
      src/parser/JaniParser.cpp
  2. 1
      src/parser/JaniParser.h
  3. 31
      src/storage/jani/JSONExporter.cpp

22
src/parser/JaniParser.cpp

@ -715,13 +715,31 @@ namespace storm {
std::vector<std::shared_ptr<storm::jani::Composition>> compositions;
for (auto const& elemDecl : compositionStructure.at("elements")) {
STORM_LOG_THROW(elemDecl.count("automaton") == 1, storm::exceptions::InvalidJaniException, "Automaton must be given in the element");
if(!allowRecursion) {
STORM_LOG_THROW(elemDecl.count("automaton") == 1, storm::exceptions::InvalidJaniException, "Automaton must be given in the element");
}
compositions.push_back(parseComposition(elemDecl));
}
STORM_LOG_THROW(compositionStructure.count("syncs") < 2, storm::exceptions::InvalidJaniException, "Sync vectors can be given at most once");
// TODO parse syncs.
std::vector<storm::jani::SynchronizationVector> syncVectors;
if (compositionStructure.count("syncs") > 0) {
// TODO add error checks
for (auto const& syncEntry : compositionStructure.at("syncs")) {
std::vector<std::string> inputs;
for (auto const& syncInput : syncEntry.at("synchronise")) {
if(syncInput.is_null()) {
// TODO handle null;
} else {
inputs.push_back(syncInput);
}
}
std::string syncResult = syncEntry.at("result");
syncVectors.emplace_back(inputs, syncResult);
}
}
return std::shared_ptr<storm::jani::Composition>(new storm::jani::ParallelComposition(compositions, syncVectors));
}
}

1
src/parser/JaniParser.h

@ -67,6 +67,7 @@ namespace storm {
*/
std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
bool allowRecursion = true;
//////////
// Default values -- assumptions from JANI.

31
src/storage/jani/JSONExporter.cpp

@ -31,8 +31,12 @@ namespace storm {
class CompositionJsonExporter : public CompositionVisitor {
public:
static modernjson::json translate(storm::jani::Composition const& comp) {
CompositionJsonExporter visitor;
CompositionJsonExporter(bool allowRecursion) : allowRecursion(allowRecursion){
}
static modernjson::json translate(storm::jani::Composition const& comp, bool allowRecursion = true) {
CompositionJsonExporter visitor(allowRecursion);
return boost::any_cast<modernjson::json>(comp.accept(visitor, boost::none));
}
@ -55,18 +59,35 @@ namespace storm {
std::vector<modernjson::json> elems;
for (auto const& subcomp : composition.getSubcompositions()) {
modernjson::json elemDecl;
STORM_LOG_THROW(subcomp->isAutomaton(), storm::exceptions::InvalidJaniException, "Nesting composition " << *subcomp << " is not supported by JANI.");
elemDecl["automaton"] = std::static_pointer_cast<AutomatonComposition>(subcomp)->getAutomatonName();
if (subcomp->isAutomaton()) {
modernjson::json autDecl;
autDecl["automaton"] = std::static_pointer_cast<AutomatonComposition>(subcomp)->getAutomatonName();
std::vector<modernjson::json> elements;
elements.push_back(autDecl);
elemDecl["elements"] = elements;
} else {
STORM_LOG_THROW(allowRecursion, storm::exceptions::InvalidJaniException, "Nesting composition " << *subcomp << " is not supported by JANI.");
elemDecl = boost::any_cast<modernjson::json>(subcomp->accept(*this, boost::none));
}
elems.push_back(elemDecl);
}
compDecl["elements"] = elems;
std::vector<modernjson::json> synElems;
for (auto const& syncs : composition.getSynchronizationVectors()) {
modernjson::json syncDecl;
syncDecl["input"] = syncs.getInput();
syncDecl["synchronise"] = syncs.getInput();
syncDecl["result"] = syncs.getOutput();
synElems.push_back(syncDecl);
}
if (!synElems.empty()) {
compDecl["syncs"] = synElems;
}
return compDecl;
}
private:
bool allowRecursion;
};

Loading…
Cancel
Save