Browse Source

skipDontCareStates-option for scheduler printing

Conflicts:
	src/storm/storage/Scheduler.cpp
	src/storm/storage/Scheduler.h
tempestpy_adaptions
hannah 3 years ago
committed by Stefan Pranger
parent
commit
0713c5dccd
  1. 4
      src/storm/api/export.h
  2. 29
      src/storm/storage/Scheduler.cpp
  3. 9
      src/storm/storage/Scheduler.h

4
src/storm/api/export.h

@ -56,9 +56,9 @@ namespace storm {
storm::utility::openFile(filename, stream); storm::utility::openFile(filename, stream);
std::string jsonFileExtension = ".json"; std::string jsonFileExtension = ".json";
if (filename.size() > 4 && std::equal(jsonFileExtension.rbegin(), jsonFileExtension.rend(), filename.rbegin())) { if (filename.size() > 4 && std::equal(jsonFileExtension.rbegin(), jsonFileExtension.rend(), filename.rbegin())) {
scheduler.printJsonToStream(stream, model);
scheduler.printJsonToStream(stream, model, false, true);
} else { } else {
scheduler.printToStream(stream, model);
scheduler.printToStream(stream, model, false, true);
} }
storm::utility::closeFile(stream); storm::utility::closeFile(stream);
} }

29
src/storm/storage/Scheduler.cpp

@ -162,7 +162,7 @@ namespace storm {
} }
template <typename ValueType> template <typename ValueType>
void Scheduler<ValueType>::printToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model, bool skipUniqueChoices) const {
void Scheduler<ValueType>::printToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model, bool skipUniqueChoices, bool skipDontCareStates) 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() == schedulerChoices.front().size(), storm::exceptions::InvalidOperationException, "The given model is not compatible with this scheduler.");
bool const stateValuationsGiven = model != nullptr && model->hasStateValuations(); bool const stateValuationsGiven = model != nullptr && model->hasStateValuations();
@ -214,6 +214,15 @@ namespace storm {
if (!isMemorylessScheduler()) { if (!isMemorylessScheduler()) {
stateString << "m" << std::setw(8) << memoryState; stateString << "m" << std::setw(8) << memoryState;
} }
stateString << " ";
bool firstMemoryState = true;
for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) {
// Ignore dontCare states
if(skipDontCareStates && isDontCare(state, memoryState)) {
continue;
}
// Print choice info // Print choice info
SchedulerChoice<ValueType> const& choice = schedulerChoices[memoryState][state]; SchedulerChoice<ValueType> const& choice = schedulerChoices[memoryState][state];
@ -256,7 +265,8 @@ namespace storm {
// Print memory updates // Print memory updates
if(!isMemorylessScheduler()) { if(!isMemorylessScheduler()) {
out << std::setw(widthOfStates) << "";
stateString << std::setw(widthOfStates) << "";
// The memory updates do not depend on the actual choice, they only depend on the current model- and memory state as well as the successor model state.
for (auto const& choiceProbPair : choice.getChoiceAsDistribution()) { for (auto const& choiceProbPair : choice.getChoiceAsDistribution()) {
uint64_t row = model->getTransitionMatrix().getRowGroupIndices()[state] + choiceProbPair.first; uint64_t row = model->getTransitionMatrix().getRowGroupIndices()[state] + choiceProbPair.first;
bool firstUpdate = true; bool firstUpdate = true;
@ -270,28 +280,29 @@ namespace storm {
// out << "model state' = " << entryIt->getColumn() << ": (transition = " << entryIt - model->getTransitionMatrix().begin() << ") -> " << "(m' = "<<this->memoryStructure->getSuccessorMemoryState(memoryState, entryIt - model->getTransitionMatrix().begin()) <<")"; // out << "model state' = " << entryIt->getColumn() << ": (transition = " << entryIt - model->getTransitionMatrix().begin() << ") -> " << "(m' = "<<this->memoryStructure->getSuccessorMemoryState(memoryState, entryIt - model->getTransitionMatrix().begin()) <<")";
} }
} }
}
stateString << std::endl; stateString << std::endl;
} }
out << stateString.str();
out << std::endl;
stateString << stateString.str();
stateString << std::endl;
} }
} }
if (numOfSkippedStatesWithUniqueChoice > 0) { if (numOfSkippedStatesWithUniqueChoice > 0) {
out << "Skipped " << numOfSkippedStatesWithUniqueChoice << " deterministic states with unique choice." << std::endl;
stateString << "Skipped " << numOfSkippedStatesWithUniqueChoice << " deterministic states with unique choice." << std::endl;
} }
out << "___________________________________________________________________" << std::endl;
stateString << "___________________________________________________________________" << std::endl;
} }
template <> template <>
void Scheduler<float>::printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<float>> model, bool skipUniqueChoices) const {
void Scheduler<float>::printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<float>> model, bool skipUniqueChoices, bool skipDontCareStates) const {
STORM_LOG_THROW(isMemorylessScheduler(), storm::exceptions::NotImplementedException, "Json export of schedulers not implemented for this value type."); STORM_LOG_THROW(isMemorylessScheduler(), storm::exceptions::NotImplementedException, "Json export of schedulers not implemented for this value type.");
} }
template <typename ValueType> template <typename ValueType>
void Scheduler<ValueType>::printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model, bool skipUniqueChoices) const {
void Scheduler<ValueType>::printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model, bool skipUniqueChoices, bool skipDontCareStates) 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() == schedulerChoices.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;
@ -303,7 +314,7 @@ namespace storm {
for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) { for (uint_fast64_t memoryState = 0; memoryState < getNumberOfMemoryStates(); ++memoryState) {
// Ignore dontCare states // Ignore dontCare states
if ((!isMemorylessScheduler()) && isDontCare(state, memoryState)) {
if (skipDontCareStates && isDontCare(state, memoryState)) {
continue; continue;
} }

9
src/storm/storage/Scheduler.h

@ -135,18 +135,15 @@ namespace storm {
* @param skipUniqueChoices If true, the (unique) choice for deterministic states (i.e., states with only one enabled choice) is not printed explicitly. * @param skipUniqueChoices If true, the (unique) choice for deterministic states (i.e., states with only one enabled choice) is not printed explicitly.
* Requires a model to be given. * Requires a model to be given.
*/ */
void printToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model = nullptr, bool skipUniqueChoices = false) const;
void printToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model = nullptr, bool skipUniqueChoices = false, bool skipDontCareStates = false) const;
/*! /*!
* Prints the scheduler in json format to the given output stream. * Prints the scheduler in json format to the given output stream.
*/ */
void printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model = nullptr, bool skipUniqueChoices = false) const;
void setPrintUndefinedChoices(bool value = true);
protected:
void printJsonToStream(std::ostream& out, std::shared_ptr<storm::models::sparse::Model<ValueType>> model = nullptr, bool skipUniqueChoices = false, bool skipDontCareStates = false) const;
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;

Loading…
Cancel
Save