From 9a7c24372e74023c0dae236bd2cf679b5a524b62 Mon Sep 17 00:00:00 2001 From: dehnert Date: Wed, 4 Jun 2014 17:25:42 +0200 Subject: [PATCH] Added crude version of 'dump to explicit format' for Dtmcs. Former-commit-id: bbe6195046b9a90ae6c244a1648af92f1f7e784f --- src/models/AtomicPropositionsLabeling.h | 15 +++++++++++++ src/models/Dtmc.h | 30 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/models/AtomicPropositionsLabeling.h b/src/models/AtomicPropositionsLabeling.h index b5ebfba8b..1969a525a 100644 --- a/src/models/AtomicPropositionsLabeling.h +++ b/src/models/AtomicPropositionsLabeling.h @@ -142,6 +142,21 @@ public: return addAtomicProposition(ap, storage::BitVector(stateCount)); } + /*! + * Retrieves the set of atomic propositions contained in this labeling. + * + * @return The set of known atomic propositions. + */ + std::set getAtomicPropositions() const { + std::set result; + + for (auto const& apIndexPair : this->nameToLabelingMap) { + result.insert(apIndexPair.first); + } + + return result; + } + /** * Creates a new atomic proposition and attaches the given states with the label. * @param ap diff --git a/src/models/Dtmc.h b/src/models/Dtmc.h index 4dfefdcc9..43e30a647 100644 --- a/src/models/Dtmc.h +++ b/src/models/Dtmc.h @@ -290,6 +290,36 @@ public: storm::storage::SparseMatrix newTransitionMatrix = storm::utility::matrix::applyScheduler(this->getTransitionMatrix(), scheduler); return std::shared_ptr>(new Dtmc(newTransitionMatrix, this->getStateLabeling(), this->hasStateRewards() ? this->getStateRewardVector() : boost::optional>(), this->hasTransitionRewards() ? this->getTransitionRewardMatrix() : boost::optional>(), this->hasChoiceLabeling() ? this->getChoiceLabeling() : boost::optional>>())); } + + void dumpToExplicitFormat(std::string const& traFilename, std::string const& labFilename) const { + std::ofstream transStream(traFilename); + transStream << "dtmc" << std::endl; + for (uint_fast64_t stateIndex = 0; stateIndex < this->getNumberOfStates(); ++stateIndex) { + for (auto const& element : this->getTransitionMatrix().getRow(stateIndex)) { + transStream << stateIndex << " " << element.first << " " << element.second << std::endl; + } + } + transStream.close(); + + std::ofstream labStream(labFilename); + labStream << "#DECLARATION" << std::endl; + for (auto const& label : this->getStateLabeling().getAtomicPropositions()) { + labStream << label << " "; + } + labStream << std::endl; + labStream << "#END" << std::endl; + for (uint_fast64_t stateIndex = 0; stateIndex < this->getNumberOfStates(); ++stateIndex) { + std::set labels = this->getLabelsForState(stateIndex); + if (!labels.empty()) { + labStream << stateIndex << " "; + for (auto const& label : labels) { + labStream << label << " "; + } + labStream << std::endl; + } + } + labStream.close(); + } private: /*!