Browse Source

possibly skip undefined choices in schedulers

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

92
src/storm/storage/PostScheduler.cpp

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

120
src/storm/storage/Scheduler.cpp

@ -146,76 +146,79 @@ namespace storm {
out << ":" << std::endl; out << ":" << std::endl;
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) {
// Check whether the state is skipped std::stringstream stateString;
if (skipUniqueChoices && model != nullptr && model->getTransitionMatrix().getRowGroupSize(state) == 1) { // Check whether the state is skipped
++numOfSkippedStatesWithUniqueChoice; if (skipUniqueChoices && model != nullptr && model->getTransitionMatrix().getRowGroupSize(state) == 1) {
continue; ++numOfSkippedStatesWithUniqueChoice;
} continue;
}
// Print the state info
if (stateValuationsGiven) {
stateString << std::setw(widthOfStates) << (std::to_string(state) + ": " + model->getStateValuations().getStateInfo(state));
} else {
stateString << std::setw(widthOfStates) << state;
}
stateString << " ";
// Print the state info bool firstMemoryState = true;
if (stateValuationsGiven) { for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) {
out << std::setw(widthOfStates) << (std::to_string(state) + ": " + model->getStateValuations().getStateInfo(state)); // Indent if this is not the first memory state
if (firstMemoryState) {
firstMemoryState = false;
} else { } else {
out << std::setw(widthOfStates) << state; stateString << std::setw(widthOfStates) << "";
stateString << " ";
}
// Print the memory state info
if (!isMemorylessScheduler()) {
stateString << "m" << std::setw(8) << memoryState;
} }
out << " ";
bool firstMemoryState = true; // Print choice info
for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) { SchedulerChoice<ValueType> const& choice = schedulerChoices[memoryState][state];
// Indent if this is not the first memory state if (choice.isDefined()) {
if (firstMemoryState) { if (choice.isDeterministic()) {
firstMemoryState = false; if (choiceOriginsGiven) {
stateString << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
} else {
stateString << choice.getDeterministicChoice();
}
if (choiceLabelsGiven) {
auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
stateString << " {" << boost::join(choiceLabels, ", ") << "}";
}
} else { } else {
out << std::setw(widthOfStates) << ""; bool firstChoice = true;
out << " "; for (auto const& choiceProbPair : choice.getChoiceAsDistribution()) {
} if (firstChoice) {
// Print the memory state info firstChoice = false;
if (!isMemorylessScheduler()) { } else {
out << "m" << std::setw(8) << memoryState; stateString << " + ";
} }
stateString << choiceProbPair.second << ": (";
// Print choice info
SchedulerChoice<ValueType> const& choice = schedulerChoices[memoryState][state];
if (choice.isDefined()) {
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] + choiceProbPair.first);
} else { } else {
out << choice.getDeterministicChoice(); 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, ", ") << "}";
}
} else {
bool firstChoice = true;
for (auto const& choiceProbPair : choice.getChoiceAsDistribution()) {
if (firstChoice) {
firstChoice = false;
} else {
out << " + ";
}
out << choiceProbPair.second << ": (";
if (choiceOriginsGiven) {
out << model->getChoiceOrigins()->getChoiceInfo(model->getTransitionMatrix().getRowGroupIndices()[state] + choiceProbPair.first);
} else {
out << choiceProbPair.first;
}
if (choiceLabelsGiven) {
auto choiceLabels = model->getChoiceLabeling().getLabelsOfChoice(model->getTransitionMatrix().getRowGroupIndices()[state] + choice.getDeterministicChoice());
out << " {" << boost::join(choiceLabels, ", ") << "}";
}
out << ")";
} }
stateString << ")";
} }
} else {
out << "undefined.";
} }
} else {
// Todo: print memory updates if(!printUndefinedChoices) continue;
out << std::endl; stateString << "undefined.";
} }
// Todo: print memory updates
out << stateString.str();
out << std::endl;
}
} }
if (numOfSkippedStatesWithUniqueChoice > 0) { if (numOfSkippedStatesWithUniqueChoice > 0) {
out << "Skipped " << numOfSkippedStatesWithUniqueChoice << " deterministic states with unique choice." << std::endl; out << "Skipped " << numOfSkippedStatesWithUniqueChoice << " deterministic states with unique choice." << 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