28 if (structure.is_number_integer()) {
29 return std::to_string(structure.get<int64_t>());
30 }
else if (structure.is_number_float()) {
32 }
else if (structure.is_string()) {
33 return structure.get<std::string>();
34 }
else if (structure.is_boolean()) {
35 return structure.get<
bool>() ?
"true" :
"false";
38 "Expected a string, number, or bool, got '" << structure.dump() <<
"' " << errorInfo <<
".");
48 for (
auto const& pathJson : modelPaths) {
49 STORM_LOG_THROW(pathJson.count(
"path") == 1, storm::exceptions::WrongFormatException,
"QVBS file " << rootIndexFile <<
" has unexpected format.");
50 std::string path =
getString(pathJson[
"path"],
"Path entry in QVBS file " + rootIndexFile);
51 std::string currModelName = path.substr(path.find(
"/") + 1);
52 if (currModelName == modelName) {
55 similarNames.
add(currModelName);
63 std::string actualModelName = modelName;
64 std::transform(actualModelName.begin(), actualModelName.end(), actualModelName.begin(), ::tolower);
66 std::string indexPath = modelPath +
"/index.json";
69 STORM_LOG_THROW(modelData.count(
"files") == 1, storm::exceptions::WrongFormatException,
"No files in " + indexPath +
".");
70 for (
auto const& fileJson : modelData[
"files"]) {
71 std::string janiFileName =
getString(fileJson[
"file"],
"file of " + indexPath +
".");
72 if (fileJson.count(
"open-parameter-values") == 1 && fileJson[
"open-parameter-values"].size() > 0) {
73 for (
auto const& openParJson : fileJson[
"open-parameter-values"]) {
74 std::string constantDefString =
"";
75 if (openParJson.count(
"values") == 1) {
76 for (
auto const& valueJson : openParJson[
"values"]) {
77 if (constantDefString !=
"") {
78 constantDefString +=
",";
80 constantDefString +=
getString(valueJson[
"name"],
"open-parameter-values in files in " + indexPath +
".") +
"=";
81 constantDefString +=
getString(valueJson[
"value"],
"open-parameter-values in files in " + indexPath +
".");
84 constantDefinitions.push_back(constantDefString);
85 janiFiles.push_back(modelPath +
"/" + janiFileName);
86 instanceInfos.push_back(janiFileName +
" \t" + constantDefString);
87 if (openParJson.count(
"states") == 1 && openParJson[
"states"].size() > 0) {
89 for (
auto const& statesJson : openParJson[
"states"]) {
90 auto note =
getString(statesJson[
"note"]);
91 if (note.find(
"Storm") != std::string::npos) {
92 states = statesJson[
"number"].get<uint64_t>();
96 instanceInfos.back() +=
" \t(" + std::to_string(states) +
" states)";
101 constantDefinitions.push_back(
"");
102 janiFiles.push_back(modelPath +
"/" + janiFileName);
103 instanceInfos.push_back(janiFileName);
109 STORM_LOG_THROW(instanceIndex < janiFiles.size(), storm::exceptions::InvalidArgumentException,
"Instance index " << instanceIndex <<
" is too high.");
110 return janiFiles[instanceIndex];
114 STORM_LOG_THROW(instanceIndex < constantDefinitions.size(), storm::exceptions::InvalidArgumentException,
115 "Instance index " << instanceIndex <<
" is too high.");
116 return constantDefinitions[instanceIndex];
119std::string
QvbsBenchmark::getInfo(uint64_t instanceIndex, boost::optional<std::vector<std::string>> propertyFilter)
const {
121 s <<
"--------------------------------------------------------------\n";
122 s <<
"QVBS " <<
getString(modelData[
"type"]) <<
"-Benchmark: " <<
getString(modelData[
"name"]) <<
" (" <<
getString(modelData[
"short"]) <<
") v"
123 <<
getString(modelData[
"version"]) <<
'\n';
124 if (instanceInfos.size() == 1) {
125 s <<
"1 instance:\n";
126 }
else if (instanceInfos.size() > 1) {
127 s << instanceInfos.size() <<
" instances:\n";
129 for (uint64_t
i = 0;
i < instanceInfos.size(); ++
i) {
130 s <<
"\t" << (
i == instanceIndex ?
"*" :
" ") <<
i <<
"\t" << instanceInfos[
i] <<
'\n';
132 if (modelData.count(
"properties") == 1) {
133 if (modelData[
"properties"].size() == 1) {
134 s <<
"1 property:\n";
135 }
else if (modelData[
"properties"].size() > 1) {
136 s << modelData[
"properties"].size() <<
" properties:\n";
138 for (
auto const& property : modelData[
"properties"]) {
139 std::string propertyName =
getString(property[
"name"]);
141 if (!propertyFilter.is_initialized() || std::find(propertyFilter->begin(), propertyFilter->end(), propertyName) != propertyFilter->end()) {
146 s << propertyName <<
" \t(" <<
getString(property[
"type"]) <<
")\n";
149 s <<
"--------------------------------------------------------------\n";
QvbsBenchmark(std::string const &modelName)
std::string const & getJaniFile(uint64_t instanceIndex=0) const
std::string getInfo(uint64_t instanceIndex=0, boost::optional< std::vector< std::string > > propertyFilter=boost::none) const
std::string const & getConstantDefinition(uint64_t instanceIndex=0) const
bool add(std::string const &string)
Adds the given string to the set of similar strings (if it is similar).
std::string toDidYouMeanString() const
Returns a "Did you mean abc?" string.
#define STORM_LOG_THROW(cond, exception, message)
void closeFile(std::ofstream &stream)
Close the given file after writing.
bool fileExistsAndIsReadable(std::string const &filename)
Tests whether the given file exists and is readable.
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
SettingsType const & getModule()
Get module.
std::string findModelPath(std::string const &modelName)
std::string getString(storm::json< storm::RationalNumber > const &structure, std::string const &errorInfo="")
storm::json< storm::RationalNumber > readQvbsJsonFile(std::string const &filePath)
std::string to_string(ValueType const &value)
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json