Browse Source

possibly skip undefined choices in schedulers

main
Stefan Pranger 4 years ago
parent
commit
dc430a3213
  1. 38
      src/storm/storage/PostScheduler.cpp
  2. 40
      src/storm/storage/Scheduler.cpp
  3. 6
      src/storm/storage/Scheduler.h

38
src/storm/storage/PostScheduler.cpp

@ -100,33 +100,34 @@ namespace storm {
uint_fast64_t numOfSkippedStatesWithUniqueChoice = 0; uint_fast64_t numOfSkippedStatesWithUniqueChoice = 0;
out << std::setw(widthOfStates) << "model state:" << " " << (isMemorylessScheduler() ? "" : " memory: ") << "choice(s)" << std::endl; out << std::setw(widthOfStates) << "model state:" << " " << (isMemorylessScheduler() ? "" : " memory: ") << "choice(s)" << std::endl;
for (uint_fast64_t state = 0; state < schedulerChoiceMapping.front().size(); ++state) { for (uint_fast64_t state = 0; state < schedulerChoiceMapping.front().size(); ++state) {
std::stringstream stateString;
// Print the state info // Print the state info
if (stateValuationsGiven) { if (stateValuationsGiven) {
out << std::setw(widthOfStates) << (std::to_string(state) + ": " + model->getStateValuations().getStateInfo(state)); stateString << std::setw(widthOfStates) << (std::to_string(state) + ": " + model->getStateValuations().getStateInfo(state));
} else { } else {
out << std::setw(widthOfStates) << state; stateString << std::setw(widthOfStates) << state;
} }
out << " "; stateString << " ";
bool firstChoiceIndex = true; bool firstChoiceIndex = true;
for(uint choiceIndex = 0; choiceIndex < schedulerChoiceMapping[0][state].size(); choiceIndex++) { for(uint choiceIndex = 0; choiceIndex < schedulerChoiceMapping[0][state].size(); choiceIndex++) {
SchedulerChoice<ValueType> const& choice = schedulerChoiceMapping[0][state][choiceIndex]; SchedulerChoice<ValueType> const& choice = schedulerChoiceMapping[0][state][choiceIndex];
if(firstChoiceIndex) { if(firstChoiceIndex) {
firstChoiceIndex = false; firstChoiceIndex = false;
out << std::to_string(choiceIndex) << ": "; stateString << std::to_string(choiceIndex) << ": ";
} else { } else {
out << std::setw(widthOfStates + 5) << std::to_string(choiceIndex) << ": "; stateString << std::setw(widthOfStates + 5) << std::to_string(choiceIndex) << ": ";
} }
if (choice.isDefined()) { if (choice.isDefined()) {
if (choice.isDeterministic()) { if (choice.isDeterministic()) {
if (choiceOriginsGiven) { if (choiceOriginsGiven) {
out << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice()); stateString << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
} else { } else {
out << choice.getDeterministicChoice(); stateString << choice.getDeterministicChoice();
} }
if (choiceLabelsGiven) { if (choiceLabelsGiven) {
auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice()); auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
out << " {" << boost::join(choiceLabels, ", ") << "}"; stateString << " {" << boost::join(choiceLabels, ", ") << "}";
} }
} else { } else {
bool firstChoice = true; bool firstChoice = true;
@ -134,28 +135,31 @@ namespace storm {
if (firstChoice) { if (firstChoice) {
firstChoice = false; firstChoice = false;
} else { } else {
out << " + "; stateString << " + ";
} }
out << choiceProbPair.second << ": ("; stateString << choiceProbPair.second << ": (";
if (choiceOriginsGiven) { if (choiceOriginsGiven) {
out << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choiceProbPair.first); stateString << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choiceProbPair.first);
} else { } else {
out << choiceProbPair.first; stateString << choiceProbPair.first;
} }
if (choiceLabelsGiven) { if (choiceLabelsGiven) {
auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice()); auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
out << " {" << boost::join(choiceLabels, ", ") << "}"; stateString << " {" << boost::join(choiceLabels, ", ") << "}";
} }
out << ")"; stateString << ")";
} }
} }
} else { } else {
out << "undefined."; if(!this->printUndefinedChoices) goto skipStatesWithUndefinedChoices;
stateString << "undefined.";
} }
// Todo: print memory updates // Todo: print memory updates
out << std::endl; stateString << std::endl;
} }
out << stateString.str();
// jump to label if we find one undefined choice.
skipStatesWithUndefinedChoices:;
} }
} }

40
src/storm/storage/Scheduler.cpp

@ -147,6 +147,7 @@ namespace storm {
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.");
out << std::setw(widthOfStates) << "model state:" << " " << (isMemorylessScheduler() ? "" : " memory: ") << "choice(s)" << std::endl; out << std::setw(widthOfStates) << "model state:" << " " << (isMemorylessScheduler() ? "" : " memory: ") << "choice(s)" << std::endl;
for (uint_fast64_t state = 0; state < schedulerChoices.front().size(); ++state) { for (uint_fast64_t state = 0; state < schedulerChoices.front().size(); ++state) {
std::stringstream stateString;
// 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) {
++numOfSkippedStatesWithUniqueChoice; ++numOfSkippedStatesWithUniqueChoice;
@ -155,11 +156,11 @@ namespace storm {
// Print the state info // Print the state info
if (stateValuationsGiven) { if (stateValuationsGiven) {
out << std::setw(widthOfStates) << (std::to_string(state) + ": " + model->getStateValuations().getStateInfo(state)); stateString << std::setw(widthOfStates) << (std::to_string(state) + ": " + model->getStateValuations().getStateInfo(state));
} else { } else {
out << std::setw(widthOfStates) << state; stateString << std::setw(widthOfStates) << state;
} }
out << " "; stateString << " ";
bool firstMemoryState = true; bool firstMemoryState = true;
for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) { for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) {
@ -167,12 +168,12 @@ namespace storm {
if (firstMemoryState) { if (firstMemoryState) {
firstMemoryState = false; firstMemoryState = false;
} else { } else {
out << std::setw(widthOfStates) << ""; stateString << std::setw(widthOfStates) << "";
out << " "; stateString << " ";
} }
// Print the memory state info // Print the memory state info
if (!isMemorylessScheduler()) { if (!isMemorylessScheduler()) {
out << "m" << std::setw(8) << memoryState; stateString << "m" << std::setw(8) << memoryState;
} }
// Print choice info // Print choice info
@ -180,13 +181,13 @@ namespace storm {
if (choice.isDefined()) { if (choice.isDefined()) {
if (choice.isDeterministic()) { if (choice.isDeterministic()) {
if (choiceOriginsGiven) { if (choiceOriginsGiven) {
out << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice()); stateString << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
} else { } else {
out << choice.getDeterministicChoice(); stateString << choice.getDeterministicChoice();
} }
if (choiceLabelsGiven) { if (choiceLabelsGiven) {
auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice()); auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
out << " {" << boost::join(choiceLabels, ", ") << "}"; stateString << " {" << boost::join(choiceLabels, ", ") << "}";
} }
} else { } else {
bool firstChoice = true; bool firstChoice = true;
@ -194,26 +195,28 @@ namespace storm {
if (firstChoice) { if (firstChoice) {
firstChoice = false; firstChoice = false;
} else { } else {
out << " + "; stateString << " + ";
} }
out << choiceProbPair.second << ": ("; stateString << choiceProbPair.second << ": (";
if (choiceOriginsGiven) { if (choiceOriginsGiven) {
out << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choiceProbPair.first); stateString << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choiceProbPair.first);
} else { } else {
out << choiceProbPair.first; stateString << choiceProbPair.first;
} }
if (choiceLabelsGiven) { if (choiceLabelsGiven) {
auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice()); auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
out << " {" << boost::join(choiceLabels, ", ") << "}"; stateString << " {" << boost::join(choiceLabels, ", ") << "}";
} }
out << ")"; stateString << ")";
} }
} }
} else { } else {
out << "undefined."; if(!printUndefinedChoices) continue;
stateString << "undefined.";
} }
// Todo: print memory updates // Todo: print memory updates
out << stateString.str();
out << std::endl; out << std::endl;
} }
} }
@ -271,6 +274,11 @@ namespace storm {
out << output.dump(4); out << output.dump(4);
} }
template <typename ValueType>
void Scheduler<ValueType>::setPrintUndefinedChoices(bool value) {
printUndefinedChoices = value;
}
template class Scheduler<double>; template class Scheduler<double>;
template class Scheduler<float>; template class Scheduler<float>;
template class Scheduler<storm::RationalNumber>; template class Scheduler<storm::RationalNumber>;

6
src/storm/storage/Scheduler.h

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <sstream>
#include "storm/storage/memorystructure/MemoryStructure.h" #include "storm/storage/memorystructure/MemoryStructure.h"
#include "storm/storage/SchedulerChoice.h" #include "storm/storage/SchedulerChoice.h"
@ -117,10 +119,14 @@ namespace storm {
*/ */
void printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model = nullptr, bool skipUniqueChoices = false) const; void printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model = nullptr, bool skipUniqueChoices = false) const;
void setPrintUndefinedChoices(bool value = true);
private: private:
boost::optional<storm::storage::MemoryStructure> memoryStructure; boost::optional<storm::storage::MemoryStructure> memoryStructure;
std::vector<std::vector<SchedulerChoice<ValueType>>> schedulerChoices; std::vector<std::vector<SchedulerChoice<ValueType>>> schedulerChoices;
bool printUndefinedChoices = false;
protected: protected:
uint_fast64_t numOfUndefinedChoices; uint_fast64_t numOfUndefinedChoices;
uint_fast64_t numOfDeterministicChoices; uint_fast64_t numOfDeterministicChoices;

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