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";
37 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Expected a string, number, or bool, got '" << structure.dump() <<
"' " << errorInfo);
47 for (
auto const& pathJson : modelPaths) {
48 STORM_LOG_THROW(pathJson.count(
"path") == 1, storm::exceptions::WrongFormatException,
"QVBS file " << rootIndexFile <<
" has unexpected format.");
49 std::string path =
getString(pathJson[
"path"],
"Path entry in QVBS file " + rootIndexFile);
50 std::string currModelName = path.substr(path.find(
"/") + 1);
51 if (currModelName == modelName) {
54 similarNames.
add(currModelName);
62 std::string actualModelName = modelName;
63 std::transform(actualModelName.begin(), actualModelName.end(), actualModelName.begin(), ::tolower);
65 std::string indexPath = modelPath +
"/index.json";
68 STORM_LOG_THROW(modelData.count(
"files") == 1, storm::exceptions::WrongFormatException,
"No files in " + indexPath +
".");
69 for (
auto const& fileJson : modelData[
"files"]) {
70 std::string janiFileName =
getString(fileJson[
"file"],
"file of " + indexPath +
".");
71 if (fileJson.count(
"open-parameter-values") == 1 && fileJson[
"open-parameter-values"].size() > 0) {
72 for (
auto const& openParJson : fileJson[
"open-parameter-values"]) {
73 std::string constantDefString =
"";
74 if (openParJson.count(
"values") == 1) {
75 for (
auto const& valueJson : openParJson[
"values"]) {
76 if (constantDefString !=
"") {
77 constantDefString +=
",";
79 constantDefString +=
getString(valueJson[
"name"],
"open-parameter-values in files in " + indexPath +
".") +
"=";
80 constantDefString +=
getString(valueJson[
"value"],
"open-parameter-values in files in " + indexPath +
".");
83 constantDefinitions.push_back(constantDefString);
84 janiFiles.push_back(modelPath +
"/" + janiFileName);
85 instanceInfos.push_back(janiFileName +
" \t" + constantDefString);
86 if (openParJson.count(
"states") == 1 && openParJson[
"states"].size() > 0) {
88 for (
auto const& statesJson : openParJson[
"states"]) {
89 auto note =
getString(statesJson[
"note"]);
90 if (note.find(
"Storm") != std::string::npos) {
91 states = statesJson[
"number"].get<uint64_t>();
95 instanceInfos.back() +=
" \t(" + std::to_string(states) +
" states)";
100 constantDefinitions.push_back(
"");
101 janiFiles.push_back(modelPath +
"/" + janiFileName);
102 instanceInfos.push_back(janiFileName);
108 STORM_LOG_THROW(instanceIndex < janiFiles.size(), storm::exceptions::InvalidArgumentException,
"Instance index " << instanceIndex <<
" is too high.");
109 return janiFiles[instanceIndex];
113 STORM_LOG_THROW(instanceIndex < constantDefinitions.size(), storm::exceptions::InvalidArgumentException,
114 "Instance index " << instanceIndex <<
" is too high.");
115 return constantDefinitions[instanceIndex];
118std::string
QvbsBenchmark::getInfo(uint64_t instanceIndex, boost::optional<std::vector<std::string>> propertyFilter)
const {
120 s <<
"--------------------------------------------------------------\n";
121 s <<
"QVBS " <<
getString(modelData[
"type"]) <<
"-Benchmark: " <<
getString(modelData[
"name"]) <<
" (" <<
getString(modelData[
"short"]) <<
") v"
122 <<
getString(modelData[
"version"]) <<
'\n';
123 if (instanceInfos.size() == 1) {
124 s <<
"1 instance:\n";
125 }
else if (instanceInfos.size() > 1) {
126 s << instanceInfos.size() <<
" instances:\n";
128 for (uint64_t
i = 0;
i < instanceInfos.size(); ++
i) {
129 s <<
"\t" << (
i == instanceIndex ?
"*" :
" ") <<
i <<
"\t" << instanceInfos[
i] <<
'\n';
131 if (modelData.count(
"properties") == 1) {
132 if (modelData[
"properties"].size() == 1) {
133 s <<
"1 property:\n";
134 }
else if (modelData[
"properties"].size() > 1) {
135 s << modelData[
"properties"].size() <<
" properties:\n";
137 for (
auto const& property : modelData[
"properties"]) {
138 std::string propertyName =
getString(property[
"name"]);
140 if (!propertyFilter.is_initialized() || std::find(propertyFilter->begin(), propertyFilter->end(), propertyName) != propertyFilter->end()) {
145 s << propertyName <<
" \t(" <<
getString(property[
"type"]) <<
")\n";
148 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