Browse Source

addded post scheduler json export

removed workaround in pre scheduler json
tempestpy_adaptions
Thomas Knoll 2 years ago
parent
commit
de2243b095
  1. 124
      src/storm/storage/PostScheduler.cpp
  2. 78
      src/storm/storage/PreScheduler.cpp

124
src/storm/storage/PostScheduler.cpp

@ -130,74 +130,62 @@ namespace storm {
template <typename ValueType> template <typename ValueType>
void PostScheduler<ValueType>::printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model, bool skipUniqueChoices) const { void PostScheduler<ValueType>::printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model, bool skipUniqueChoices) const {
// STORM_LOG_THROW(model == nullptr || model->getNumberOfStates() == schedulerChoices.front().size(), storm::exceptions::InvalidOperationException, "The given model is not compatible with this scheduler."); STORM_LOG_THROW(model == nullptr || model->getNumberOfStates() == schedulerChoiceMapping.front().size(), storm::exceptions::InvalidOperationException, "The given model is not compatible with this scheduler.");
// STORM_LOG_WARN_COND(!(skipUniqueChoices && model == nullptr), "Can not skip unique choices if the model is not given."); STORM_LOG_WARN_COND(!(skipUniqueChoices && model == nullptr), "Can not skip unique choices if the model is not given.");
// storm::json<storm::RationalNumber> output; storm::json<storm::RationalNumber> output;
// for (uint64_t state = 0; state < schedulerChoices.front().size(); ++state) { for (uint64_t state = 0; state < schedulerChoiceMapping.front().size(); ++state) {
// // Check whether the state is skipped // Check whether the state is skipped
// if (skipUniqueChoices && model != nullptr && model->getTransitionMatrix().getRowGroupSize(state) == 1) { if (skipUniqueChoices && model != nullptr && model->getTransitionMatrix().getRowGroupSize(state) == 1) {
// continue; continue;
// } }
storm::json<storm::RationalNumber> stateChoicesJson;
// for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) { if (model && model->hasStateValuations()) {
// storm::json<storm::RationalNumber> stateChoicesJson; stateChoicesJson["s"] = model->getStateValuations().template toJson<storm::RationalNumber>(state);
// if (model && model->hasStateValuations()) { } else {
// stateChoicesJson["s"] = model->getStateValuations().template toJson<storm::RationalNumber>(state); stateChoicesJson["s"] = state;
// } else { }
// stateChoicesJson["s"] = state; auto const &choice = schedulerChoiceMapping[0][state];
// } storm::json<storm::RationalNumber> choicesJson;
if (!choice.getChoiceMap().empty()) {
// if (!isMemorylessScheduler()) { for (auto const &choiceProbPair : choice.getChoiceMap()) {
// stateChoicesJson["m"] = memoryState; uint64_t globalChoiceIndex = model->getTransitionMatrix().getRowGroupIndices()[state] + std::get<0>(choiceProbPair);
// } uint64_t globalChoiceCorrectionIndex = model->getTransitionMatrix().getRowGroupIndices()[state] + std::get<1>(choiceProbPair);
storm::json<storm::RationalNumber> choiceJson;
// auto const &choice = schedulerChoices[memoryState][state]; if (model && model->hasChoiceOrigins() &&
// storm::json<storm::RationalNumber> choicesJson; model->getChoiceOrigins()->getIdentifier(globalChoiceIndex) !=
model->getChoiceOrigins()->getIdentifierForChoicesWithNoOrigin()) {
// for (auto const &choiceProbPair : choice.getChoiceMap()) { auto choiceOriginJson = model->getChoiceOrigins()->getChoiceAsJson(globalChoiceIndex);
// uint64_t globalChoiceIndex = model->getTransitionMatrix().getRowGroupIndices()[state] ;//+ choiceProbPair.first; auto choiceOriginCorrectionJson = model->getChoiceOrigins()->getChoiceAsJson(globalChoiceCorrectionIndex);
// storm::json<storm::RationalNumber> choiceJson; std::string choiceActionLabel = choiceOriginJson["action-label"];
// if (model && model->hasChoiceOrigins() && std::string choiceCorrectionActionLabel = choiceOriginCorrectionJson["action-label"];
// model->getChoiceOrigins()->getIdentifier(globalChoiceIndex) != choiceOriginJson["action-label"] = choiceActionLabel.append(": ").append(choiceCorrectionActionLabel);
// model->getChoiceOrigins()->getIdentifierForChoicesWithNoOrigin()) { choiceJson["origin"] = choiceOriginJson;
// choiceJson["origin"] = model->getChoiceOrigins()->getChoiceAsJson(globalChoiceIndex); }
// } if (model && model->hasChoiceLabeling()) {
// if (model && model->hasChoiceLabeling()) { auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(globalChoiceIndex);
// auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(globalChoiceIndex); choiceJson["labels"] = std::vector<std::string>(choiceLabels.begin(),
// choiceJson["labels"] = std::vector<std::string>(choiceLabels.begin(), choiceLabels.end());
// choiceLabels.end()); }
// } choiceJson["index"] = globalChoiceIndex;
// choiceJson["index"] = globalChoiceIndex; choiceJson["prob"] = storm::utility::convertNumber<storm::RationalNumber>(
// choiceJson["prob"] = storm::utility::convertNumber<storm::RationalNumber>( std::get<1>(choiceProbPair));
// std::get<1>(choiceProbPair)); choicesJson.push_back(std::move(choiceJson));
}
// // Memory updates } else {
// if(!isMemorylessScheduler()) { choicesJson = "undefined";
// choiceJson["memory-updates"] = std::vector<storm::json<storm::RationalNumber>>(); }
// uint64_t row = model->getTransitionMatrix().getRowGroupIndices()[state]; //+ std::get<0>(choiceProbPair); stateChoicesJson["c"] = std::move(choicesJson);
// for (auto entryIt = model->getTransitionMatrix().getRow(row).begin(); entryIt < model->getTransitionMatrix().getRow(row).end(); ++entryIt) { output.push_back(std::move(stateChoicesJson));
// storm::json<storm::RationalNumber> updateJson; }
// // next model state out << output.dump(4);
// if (model && model->hasStateValuations()) {
// updateJson["s'"] = model->getStateValuations().template toJson<storm::RationalNumber>(entryIt->getColumn());
// } else {
// updateJson["s'"] = entryIt->getColumn();
// }
// // next memory state
// updateJson["m'"] = this->memoryStructure->getSuccessorMemoryState(memoryState, entryIt - model->getTransitionMatrix().begin());
// choiceJson["memory-updates"].push_back(std::move(updateJson));
// }
// }
// choicesJson.push_back(std::move(choiceJson));
// }
// if (!choicesJson.is_null()) {
// stateChoicesJson["c"] = std::move(choicesJson);
// output.push_back(std::move(stateChoicesJson));
// }
// }
// }
// out << output.dump(4);
} }

78
src/storm/storage/PreScheduler.cpp

@ -165,48 +165,50 @@ namespace storm {
auto const &choice = schedulerChoices[memoryState][state]; auto const &choice = schedulerChoices[memoryState][state];
storm::json<storm::RationalNumber> choicesJson; storm::json<storm::RationalNumber> choicesJson;
if (!choice.getChoiceMap().empty()) {
for (auto const &choiceProbPair : choice.getChoiceMap()) { for (auto const &choiceProbPair : choice.getChoiceMap()) {
uint64_t globalChoiceIndex = model->getTransitionMatrix().getRowGroupIndices()[state] + std::get<uint_fast64_t>(choiceProbPair); uint64_t globalChoiceIndex = model->getTransitionMatrix().getRowGroupIndices()[state] + std::get<uint_fast64_t>(choiceProbPair);
storm::json<storm::RationalNumber> choiceJson; storm::json<storm::RationalNumber> choiceJson;
if (model && model->hasChoiceOrigins() && if (model && model->hasChoiceOrigins() &&
model->getChoiceOrigins()->getIdentifier(globalChoiceIndex) != model->getChoiceOrigins()->getIdentifier(globalChoiceIndex) !=
model->getChoiceOrigins()->getIdentifierForChoicesWithNoOrigin()) { model->getChoiceOrigins()->getIdentifierForChoicesWithNoOrigin()) {
choiceJson["origin"] = model->getChoiceOrigins()->getChoiceAsJson(globalChoiceIndex); choiceJson["origin"] = model->getChoiceOrigins()->getChoiceAsJson(globalChoiceIndex);
} }
if (model && model->hasChoiceLabeling()) { if (model && model->hasChoiceLabeling()) {
auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(globalChoiceIndex); auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(globalChoiceIndex);
choiceJson["labels"] = std::vector<std::string>(choiceLabels.begin(), choiceJson["labels"] = std::vector<std::string>(choiceLabels.begin(),
choiceLabels.end()); choiceLabels.end());
} }
choiceJson["index"] = globalChoiceIndex; choiceJson["index"] = globalChoiceIndex;
choiceJson["prob"] = storm::utility::convertNumber<storm::RationalNumber>( choiceJson["prob"] = storm::utility::convertNumber<storm::RationalNumber>(
std::get<ValueType>(choiceProbPair)); std::get<ValueType>(choiceProbPair));
// Memory updates
// Memory updates if(!isMemorylessScheduler()) {
if(!isMemorylessScheduler()) { choiceJson["memory-updates"] = std::vector<storm::json<storm::RationalNumber>>();
choiceJson["memory-updates"] = std::vector<storm::json<storm::RationalNumber>>(); uint64_t row = model->getTransitionMatrix().getRowGroupIndices()[state] + std::get<uint_fast64_t>(choiceProbPair);
uint64_t row = model->getTransitionMatrix().getRowGroupIndices()[state] + std::get<uint_fast64_t>(choiceProbPair); for (auto entryIt = model->getTransitionMatrix().getRow(row).begin(); entryIt < model->getTransitionMatrix().getRow(row).end(); ++entryIt) {
for (auto entryIt = model->getTransitionMatrix().getRow(row).begin(); entryIt < model->getTransitionMatrix().getRow(row).end(); ++entryIt) { storm::json<storm::RationalNumber> updateJson;
storm::json<storm::RationalNumber> updateJson; // next model state
// next model state if (model && model->hasStateValuations()) {
if (model && model->hasStateValuations()) { updateJson["s'"] = model->getStateValuations().template toJson<storm::RationalNumber>(entryIt->getColumn());
updateJson["s'"] = model->getStateValuations().template toJson<storm::RationalNumber>(entryIt->getColumn()); } else {
} else { updateJson["s'"] = entryIt->getColumn();
updateJson["s'"] = entryIt->getColumn(); }
// next memory state
updateJson["m'"] = this->memoryStructure->getSuccessorMemoryState(memoryState, entryIt - model->getTransitionMatrix().begin());
choiceJson["memory-updates"].push_back(std::move(updateJson));
} }
// next memory state
updateJson["m'"] = this->memoryStructure->getSuccessorMemoryState(memoryState, entryIt - model->getTransitionMatrix().begin());
choiceJson["memory-updates"].push_back(std::move(updateJson));
} }
}
choicesJson.push_back(std::move(choiceJson)); choicesJson.push_back(std::move(choiceJson));
} }
if (!choicesJson.is_null()) { } else {
stateChoicesJson["c"] = std::move(choicesJson); choicesJson = "undefined";
output.push_back(std::move(stateChoicesJson));
} }
stateChoicesJson["c"] = std::move(choicesJson);
output.push_back(std::move(stateChoicesJson));
} }
} }
out << output.dump(4); out << output.dump(4);

|||||||
100:0
Loading…
Cancel
Save