Browse Source
added conversion from PRISM to JANI. Added simplistic tests for that.
added conversion from PRISM to JANI. Added simplistic tests for that.
Former-commit-id: 5b31fa589c
main
24 changed files with 1080 additions and 130 deletions
-
2src/parser/JaniParser.cpp
-
2src/storage/jani/Action.h
-
16src/storage/jani/Automaton.cpp
-
17src/storage/jani/Automaton.h
-
2src/storage/jani/BooleanVariable.h
-
2src/storage/jani/BoundedIntegerVariable.h
-
6src/storage/jani/Constant.cpp
-
7src/storage/jani/Constant.h
-
4src/storage/jani/EdgeSet.cpp
-
7src/storage/jani/EdgeSet.h
-
412src/storage/jani/Exporter.cpp
-
48src/storage/jani/Exporter.h
-
144src/storage/jani/Model.cpp
-
169src/storage/jani/Model.h
-
18src/storage/jani/ModelType.cpp
-
2src/storage/jani/ModelType.h
-
2src/storage/jani/UnboundedIntegerVariable.h
-
10src/storage/jani/Variable.cpp
-
5src/storage/jani/Variable.h
-
33src/storage/jani/VariableSet.cpp
-
25src/storage/jani/VariableSet.h
-
243src/storage/prism/Program.cpp
-
9src/storage/prism/Program.h
-
25test/functional/storage/PrismProgramTest.cpp
@ -0,0 +1,412 @@ |
|||||
|
#include "src/storage/jani/Exporter.h"
|
||||
|
|
||||
|
#include <iostream>
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace jani { |
||||
|
|
||||
|
void appendIndent(std::stringstream& out, uint64_t indent) { |
||||
|
for (uint64_t i = 0; i < indent; ++i) { |
||||
|
out << "\t"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void appendField(std::stringstream& out, std::string const& name) { |
||||
|
out << "\"" << name << "\": "; |
||||
|
} |
||||
|
|
||||
|
void appendValue(std::stringstream& out, std::string const& value) { |
||||
|
out << "\"" << value << "\""; |
||||
|
} |
||||
|
|
||||
|
void clearLine(std::stringstream& out) { |
||||
|
out << std::endl; |
||||
|
} |
||||
|
|
||||
|
std::string expressionToString(storm::expressions::Expression const& expression) { |
||||
|
std::stringstream s; |
||||
|
s << expression; |
||||
|
return s.str(); |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendVersion(std::stringstream& out, uint64_t janiVersion, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "jani-version"); |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendModelName(std::stringstream& out, std::string const& name, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "name"); |
||||
|
appendValue(out, name); |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendModelType(std::stringstream& out, storm::jani::ModelType const& modelType, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "type"); |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendAction(std::stringstream& out, storm::jani::Action const& action, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{" << std::endl; |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "name"); |
||||
|
appendValue(out, action.getName()); |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendActions(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "actions"); |
||||
|
out << " [" << std::endl; |
||||
|
|
||||
|
for (uint64_t index = 0; index < model.actions.size(); ++index) { |
||||
|
appendAction(out, model.actions[index], indent + 1); |
||||
|
if (index < model.actions.size() - 1) { |
||||
|
out << ","; |
||||
|
} |
||||
|
clearLine(out); |
||||
|
} |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "]"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendVariable(std::stringstream& out, storm::jani::BooleanVariable const& variable, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "name"); |
||||
|
appendValue(out, variable.getName()); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "type"); |
||||
|
appendValue(out, "bool"); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "initial-value"); |
||||
|
appendValue(out, expressionToString(variable.getInitialValue())); |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendBoundedIntegerVariableType(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const { |
||||
|
out << " {"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "kind"); |
||||
|
appendValue(out, "bounded"); |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "base"); |
||||
|
appendValue(out, "int"); |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "lower-bound"); |
||||
|
appendValue(out, expressionToString(variable.getLowerBound())); |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "upper-bound"); |
||||
|
appendValue(out, expressionToString(variable.getLowerBound())); |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent - 1); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendVariable(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "name"); |
||||
|
appendValue(out, variable.getName()); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "type"); |
||||
|
appendBoundedIntegerVariableType(out, variable, indent + 2); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "initial-value"); |
||||
|
appendValue(out, expressionToString(variable.getInitialValue())); |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendVariable(std::stringstream& out, storm::jani::UnboundedIntegerVariable const& variable, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "name"); |
||||
|
appendValue(out, variable.getName()); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "type"); |
||||
|
appendValue(out, "int"); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "initial-value"); |
||||
|
appendValue(out, expressionToString(variable.getInitialValue())); |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendVariables(std::stringstream& out, storm::jani::VariableSet const& variables, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "variables"); |
||||
|
out << " ["; |
||||
|
clearLine(out); |
||||
|
|
||||
|
for (auto const& variable : variables.getBooleanVariables()) { |
||||
|
appendVariable(out, variable, indent + 1); |
||||
|
clearLine(out); |
||||
|
} |
||||
|
for (auto const& variable : variables.getBoundedIntegerVariables()) { |
||||
|
appendVariable(out, variable, indent + 1); |
||||
|
clearLine(out); |
||||
|
} |
||||
|
for (auto const& variable : variables.getUnboundedIntegerVariables()) { |
||||
|
appendVariable(out, variable, indent + 1); |
||||
|
clearLine(out); |
||||
|
} |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "]"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendLocation(std::stringstream& out, storm::jani::Location const& location, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "name"); |
||||
|
appendValue(out, location.getName()); |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendLocations(std::stringstream& out, storm::jani::Automaton const& automaton, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "locations"); |
||||
|
out << " ["; |
||||
|
clearLine(out); |
||||
|
|
||||
|
for (auto const& location : automaton.getLocations()) { |
||||
|
appendLocation(out, location, indent + 1); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
} |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "]"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendAssignment(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Assignment const& assignment, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "ref"); |
||||
|
storm::jani::Variable const& variable = model.getVariables().hasVariable(assignment.getExpressionVariable()) ? model.getVariables().getVariable(assignment.getExpressionVariable()) : automaton.getVariables().getVariable(assignment.getExpressionVariable()); |
||||
|
appendValue(out, variable.getName()); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "value"); |
||||
|
appendValue(out, expressionToString(assignment.getAssignedExpression())); |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendEdgeDestination(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::EdgeDestination const& destination, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "probability"); |
||||
|
appendValue(out, expressionToString(destination.getProbability())); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "location"); |
||||
|
appendValue(out, automaton.getLocation(destination.getLocationId()).getName()); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "assignments"); |
||||
|
out << " ["; |
||||
|
clearLine(out); |
||||
|
|
||||
|
for (uint64_t index = 0; index < destination.getAssignments().size(); ++index) { |
||||
|
appendAssignment(out, model, automaton, destination.getAssignments()[index], indent + 2); |
||||
|
if (index < destination.getAssignments().size() - 1) { |
||||
|
out << ","; |
||||
|
} |
||||
|
clearLine(out); |
||||
|
} |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
out << "]"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
clearLine(out); |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendEdge(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Edge const& edge, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "location"); |
||||
|
appendValue(out, automaton.getLocation(edge.getSourceLocationId()).getName()); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "action"); |
||||
|
appendValue(out, model.getAction(edge.getActionId()).getName()); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "guard"); |
||||
|
appendValue(out, expressionToString(edge.getGuard())); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "destinations"); |
||||
|
out << " ["; |
||||
|
clearLine(out); |
||||
|
|
||||
|
for (auto const& destination : edge.getDestinations()) { |
||||
|
appendEdgeDestination(out, model, automaton, destination, indent + 2); |
||||
|
} |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
out << "]"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendEdges(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "edges"); |
||||
|
out << " ["; |
||||
|
clearLine(out); |
||||
|
|
||||
|
for (uint64_t location = 0; location < automaton.getNumberOfLocations(); ++location) { |
||||
|
for (auto const& edge : automaton.getEdgesFromLocation(location)) { |
||||
|
appendEdge(out, model, automaton, edge, indent + 1); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "]"; |
||||
|
clearLine(out); |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendAutomaton(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
out << "{"; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "name"); |
||||
|
appendValue(out, automaton.getName()); |
||||
|
clearLine(out); |
||||
|
appendVariables(out, automaton.getVariables(), indent + 1); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendLocations(out, automaton, indent + 1); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendIndent(out, indent + 1); |
||||
|
appendField(out, "initial-location"); |
||||
|
appendValue(out, std::to_string(automaton.getInitialLocationIndex())); |
||||
|
clearLine(out); |
||||
|
|
||||
|
appendEdges(out, model, automaton, indent + 1); |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "}"; |
||||
|
} |
||||
|
|
||||
|
void Exporter::appendAutomata(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const { |
||||
|
appendIndent(out, indent); |
||||
|
appendField(out, "automata"); |
||||
|
out << " ["; |
||||
|
clearLine(out); |
||||
|
|
||||
|
for (uint64_t index = 0; index < model.automata.size(); ++index) { |
||||
|
appendAutomaton(out, model, model.automata[index], indent + 1); |
||||
|
if (index < model.automata.size() - 1) { |
||||
|
out << ","; |
||||
|
} |
||||
|
clearLine(out); |
||||
|
} |
||||
|
|
||||
|
appendIndent(out, indent); |
||||
|
out << "]"; |
||||
|
} |
||||
|
|
||||
|
std::string Exporter::toJaniString(storm::jani::Model const& model) const { |
||||
|
std::stringstream out; |
||||
|
|
||||
|
out << "{" << std::endl; |
||||
|
appendVersion(out, model.getJaniVersion(), 1); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendModelName(out, model.getName(), 1); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendModelType(out, model.getModelType(), 1); |
||||
|
out << ","; |
||||
|
clearLine(out); |
||||
|
appendActions(out, model, 1); |
||||
|
clearLine(out); |
||||
|
appendVariables(out, model.getVariables(), 1); |
||||
|
clearLine(out); |
||||
|
appendAutomata(out, model, 1); |
||||
|
clearLine(out); |
||||
|
out << "}" << std::endl; |
||||
|
|
||||
|
return out.str(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <sstream> |
||||
|
#include <cstdint> |
||||
|
|
||||
|
#include "src/storage/jani/Model.h" |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace jani { |
||||
|
|
||||
|
class Exporter { |
||||
|
public: |
||||
|
Exporter() = default; |
||||
|
|
||||
|
std::string toJaniString(storm::jani::Model const& model) const; |
||||
|
|
||||
|
private: |
||||
|
void appendVersion(std::stringstream& out, uint64_t janiVersion, uint64_t indent) const; |
||||
|
|
||||
|
void appendModelName(std::stringstream& out, std::string const& name, uint64_t indent) const; |
||||
|
|
||||
|
void appendModelType(std::stringstream& out, storm::jani::ModelType const& modelType, uint64_t indent) const; |
||||
|
|
||||
|
void appendAction(std::stringstream& out, storm::jani::Action const& action, uint64_t indent) const; |
||||
|
|
||||
|
void appendActions(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const; |
||||
|
|
||||
|
void appendVariables(std::stringstream& out, storm::jani::VariableSet const& variables, uint64_t indent) const; |
||||
|
|
||||
|
void appendVariable(std::stringstream& out, storm::jani::BooleanVariable const& variable, uint64_t indent) const; |
||||
|
void appendVariable(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const; |
||||
|
void appendBoundedIntegerVariableType(std::stringstream& out, storm::jani::BoundedIntegerVariable const& variable, uint64_t indent) const; |
||||
|
void appendVariable(std::stringstream& out, storm::jani::UnboundedIntegerVariable const& variable, uint64_t indent) const; |
||||
|
|
||||
|
void appendAutomata(std::stringstream& out, storm::jani::Model const& model, uint64_t indent) const; |
||||
|
void appendAutomaton(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const; |
||||
|
|
||||
|
void appendLocation(std::stringstream& out, storm::jani::Location const& location, uint64_t indent) const; |
||||
|
void appendLocations(std::stringstream& out, storm::jani::Automaton const& automaton, uint64_t indent) const; |
||||
|
|
||||
|
void appendAssignment(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Assignment const& assignment, uint64_t indent) const; |
||||
|
void appendEdgeDestination(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::EdgeDestination const& destination, uint64_t indent) const; |
||||
|
void appendEdge(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, storm::jani::Edge const& edge, uint64_t indent) const; |
||||
|
void appendEdges(std::stringstream& out, storm::jani::Model const& model, storm::jani::Automaton const& automaton, uint64_t indent) const; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
@ -1,54 +1,154 @@ |
|||||
#include <src/exceptions/InvalidJaniException.h>
|
|
||||
#include "src/storage/jani/Model.h"
|
#include "src/storage/jani/Model.h"
|
||||
|
|
||||
|
#include "src/storage/expressions/ExpressionManager.h"
|
||||
|
|
||||
|
#include "src/storage/jani/AutomatonComposition.h"
|
||||
|
#include "src/storage/jani/ParallelComposition.h"
|
||||
|
#include "src/storage/jani/RenameComposition.h"
|
||||
|
|
||||
|
#include "src/utility/macros.h"
|
||||
|
#include "src/exceptions/WrongFormatException.h"
|
||||
|
|
||||
namespace storm { |
namespace storm { |
||||
namespace jani { |
namespace jani { |
||||
|
|
||||
Model::Model(std::string const& name, ModelType const& modelType, uint64_t version) : name(name), modelType(modelType), version(version) { |
|
||||
|
static const std::string SILENT_ACTION_NAME = ""; |
||||
|
|
||||
|
Model::Model() { |
||||
// Intentionally left empty.
|
// Intentionally left empty.
|
||||
} |
} |
||||
|
|
||||
uint64_t Model::addAction(Action const& act) { |
|
||||
STORM_LOG_THROW(actionToIndex.count(act.getName()) == 0, storm::exceptions::InvalidJaniException, "Action with name " + act.getName() + " already exists"); |
|
||||
actionToIndex.emplace(act.getName(), actions.size()); |
|
||||
actions.push_back(act); |
|
||||
|
|
||||
|
Model::Model(std::string const& name, ModelType const& modelType, uint64_t version, boost::optional<std::shared_ptr<storm::expressions::ExpressionManager>> const& expressionManager) : name(name), modelType(modelType), version(version), composition(nullptr) { |
||||
|
// Use the provided manager or create a new one.
|
||||
|
if (expressionManager) { |
||||
|
this->expressionManager = expressionManager.get(); |
||||
|
} else { |
||||
|
this->expressionManager = std::make_shared<storm::expressions::ExpressionManager>(); |
||||
|
} |
||||
|
|
||||
|
// Add a prefined action that represents the silent action.
|
||||
|
silentActionIndex = addAction(storm::jani::Action(SILENT_ACTION_NAME)); |
||||
|
} |
||||
|
|
||||
|
uint64_t Model::getJaniVersion() const { |
||||
|
return version; |
||||
|
} |
||||
|
|
||||
|
ModelType const& Model::getModelType() const { |
||||
|
return modelType; |
||||
|
} |
||||
|
|
||||
|
std::string const& Model::getName() const { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
uint64_t Model::addAction(Action const& action) { |
||||
|
auto it = actionToIndex.find(action.getName()); |
||||
|
STORM_LOG_THROW(it == actionToIndex.end(), storm::exceptions::WrongFormatException, "Action with name '" << action.getName() << "' already exists"); |
||||
|
actionToIndex.emplace(action.getName(), actions.size()); |
||||
|
actions.push_back(action); |
||||
return actions.size() - 1; |
return actions.size() - 1; |
||||
} |
} |
||||
|
|
||||
bool Model::hasAction(std::string const &name) const { |
|
||||
return actionToIndex.count(name) != 0; |
|
||||
|
|
||||
|
Action const& Model::getAction(uint64_t index) const { |
||||
|
return actions[index]; |
||||
} |
} |
||||
|
|
||||
|
|
||||
|
bool Model::hasAction(std::string const& name) const { |
||||
|
return actionToIndex.find(name) != actionToIndex.end(); |
||||
|
} |
||||
|
|
||||
uint64_t Model::getActionIndex(std::string const& name) const { |
uint64_t Model::getActionIndex(std::string const& name) const { |
||||
assert(this->hasAction(name)); |
|
||||
return actionToIndex.at(name); |
|
||||
|
auto it = actionToIndex.find(name); |
||||
|
STORM_LOG_THROW(it != actionToIndex.end(), storm::exceptions::WrongFormatException, "Unable to retrieve index of unknown action '" << name << "'."); |
||||
|
return it->second; |
||||
} |
} |
||||
|
|
||||
|
|
||||
void Model::checkSupported() const { |
|
||||
//TODO
|
|
||||
|
|
||||
|
uint64_t Model::addConstant(Constant const& constant) { |
||||
|
auto it = constantToIndex.find(constant.getName()); |
||||
|
STORM_LOG_THROW(it == constantToIndex.end(), storm::exceptions::WrongFormatException, "Cannot add constant with name '" << constant.getName() << "', because a constant with that name already exists."); |
||||
|
constantToIndex.emplace(constant.getName(), constants.size()); |
||||
|
constants.push_back(constant); |
||||
|
return constants.size() - 1; |
||||
} |
} |
||||
|
|
||||
|
|
||||
|
void Model::addBooleanVariable(BooleanVariable const& variable) { |
||||
|
globalVariables.addBooleanVariable(variable); |
||||
|
} |
||||
|
|
||||
|
void Model::addBoundedIntegerVariable(BoundedIntegerVariable const& variable) { |
||||
|
globalVariables.addBoundedIntegerVariable(variable); |
||||
|
} |
||||
|
|
||||
|
void Model::addUnboundedIntegerVariable(UnboundedIntegerVariable const& variable) { |
||||
|
globalVariables.addUnboundedIntegerVariable(variable); |
||||
|
} |
||||
|
|
||||
|
VariableSet const& Model::getVariables() const { |
||||
|
return globalVariables; |
||||
|
} |
||||
|
|
||||
|
storm::expressions::ExpressionManager& Model::getExpressionManager() { |
||||
|
return *expressionManager; |
||||
|
} |
||||
|
|
||||
|
storm::expressions::ExpressionManager const& Model::getExpressionManager() const { |
||||
|
return *expressionManager; |
||||
|
} |
||||
|
|
||||
|
uint64_t Model::addAutomaton(Automaton const& automaton) { |
||||
|
auto it = automatonToIndex.find(automaton.getName()); |
||||
|
STORM_LOG_THROW(it == automatonToIndex.end(), storm::exceptions::WrongFormatException, "Automaton with name '" << automaton.getName() << "' already exists."); |
||||
|
automatonToIndex.emplace(automaton.getName(), automata.size()); |
||||
|
automata.push_back(automaton); |
||||
|
return automata.size() - 1; |
||||
|
} |
||||
|
|
||||
|
std::shared_ptr<Composition> Model::getStandardSystemComposition() const { |
||||
|
std::set<std::string> fullSynchronizationAlphabet = getActionNames(false); |
||||
|
|
||||
|
std::shared_ptr<Composition> current; |
||||
|
current = std::make_shared<AutomatonComposition>(this->automata.front().getName()); |
||||
|
for (uint64_t index = 1; index < automata.size(); ++index) { |
||||
|
current = std::make_shared<ParallelComposition>(current, std::make_shared<AutomatonComposition>(automata[index].getName()), fullSynchronizationAlphabet); |
||||
|
} |
||||
|
return current; |
||||
|
} |
||||
|
|
||||
|
Composition const& Model::getSystemComposition() const { |
||||
|
return *composition; |
||||
|
} |
||||
|
|
||||
|
std::set<std::string> Model::getActionNames(bool includeSilent) const { |
||||
|
std::set<std::string> result; |
||||
|
for (auto const& entry : actionToIndex) { |
||||
|
if (includeSilent || entry.second != silentActionIndex) { |
||||
|
result.insert(entry.first); |
||||
|
} |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
bool Model::checkValidity(bool logdbg) const { |
bool Model::checkValidity(bool logdbg) const { |
||||
// TODO switch to exception based return value.
|
// TODO switch to exception based return value.
|
||||
|
|
||||
|
|
||||
if (version == 0) { |
if (version == 0) { |
||||
if(logdbg) STORM_LOG_DEBUG("Jani version is unspecified"); |
if(logdbg) STORM_LOG_DEBUG("Jani version is unspecified"); |
||||
return false; |
return false; |
||||
} |
} |
||||
|
|
||||
|
|
||||
if(modelType == ModelType::UNDEFINED) { |
if(modelType == ModelType::UNDEFINED) { |
||||
if(logdbg) STORM_LOG_DEBUG("Model type is unspecified"); |
if(logdbg) STORM_LOG_DEBUG("Model type is unspecified"); |
||||
return false; |
return false; |
||||
} |
} |
||||
|
|
||||
|
|
||||
if(automata.empty()) { |
if(automata.empty()) { |
||||
if(logdbg) STORM_LOG_DEBUG("No automata specified"); |
if(logdbg) STORM_LOG_DEBUG("No automata specified"); |
||||
return false; |
return false; |
||||
} |
} |
||||
// All checks passed.
|
// All checks passed.
|
||||
return true; |
return true; |
||||
|
|
||||
|
|
||||
} |
} |
||||
|
|
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue