From 01fd3c18e38ab178c57622fd121e8b9420e2bb60 Mon Sep 17 00:00:00 2001 From: PBerger Date: Sun, 16 Jun 2013 20:34:28 +0200 Subject: [PATCH] Added move constructors, added move-calls where fitting. Former-commit-id: e73336c81665b6caf53291527aace1381231cd31 --- src/adapters/ExplicitModelAdapter.h | 3 + src/adapters/GmmxxAdapter.h | 57 +++++++++++++++++++ src/models/AbstractDeterministicModel.h | 11 +++- src/models/AbstractModel.h | 22 +++---- src/models/AbstractNondeterministicModel.h | 8 ++- src/models/Ctmc.h | 7 ++- src/models/Ctmdp.h | 5 +- src/models/Dtmc.h | 5 +- src/models/Mdp.h | 5 +- src/parser/AutoParser.h | 8 +-- src/parser/DeterministicModelParser.cpp | 21 +++---- src/parser/DeterministicModelParser.h | 6 ++ src/parser/NondeterministicModelParser.cpp | 15 ++--- src/parser/NondeterministicModelParser.h | 8 ++- ...NondeterministicSparseTransitionParser.cpp | 2 +- test/performance/graph/GraphTest.cpp | 26 +++++---- 16 files changed, 150 insertions(+), 59 deletions(-) diff --git a/src/adapters/ExplicitModelAdapter.h b/src/adapters/ExplicitModelAdapter.h index c1f083968..87af1048a 100644 --- a/src/adapters/ExplicitModelAdapter.h +++ b/src/adapters/ExplicitModelAdapter.h @@ -69,6 +69,9 @@ public: std::shared_ptr> getModel(std::string const & rewardModelName = ""); private: + // Copying/Moving is disabled for this class + ExplicitModelAdapter(ExplicitModelAdapter const& other) {} + ExplicitModelAdapter(ExplicitModelAdapter && other) {} double precision; diff --git a/src/adapters/GmmxxAdapter.h b/src/adapters/GmmxxAdapter.h index 74f0e6254..25ecda4bf 100644 --- a/src/adapters/GmmxxAdapter.h +++ b/src/adapters/GmmxxAdapter.h @@ -47,6 +47,30 @@ public: return result; } + /*! + * Converts a sparse matrix into a sparse matrix in the gmm++ format. + * @return A pointer to a row-major sparse matrix in gmm++ format. + */ + template + static gmm::csr_matrix* toGmmxxSparseMatrix(storm::storage::SparseMatrix && matrix) { + uint_fast64_t realNonZeros = matrix.getNonZeroEntryCount(); + LOG4CPLUS_DEBUG(logger, "Converting matrix with " << realNonZeros << " non-zeros to gmm++ format."); + + // Prepare the resulting matrix. + gmm::csr_matrix* result = new gmm::csr_matrix(matrix.rowCount, matrix.colCount); + + // Move Row Indications + result->jc(std::move(matrix.rowIndications)); + // Move Columns Indications + result->ir(std::move(matrix.columnIndications)); + // And do the same thing with the actual values. + result->pr(std::move(matrix.valueStorage)); + + LOG4CPLUS_DEBUG(logger, "Done converting matrix to gmm++ format."); + + return result; + } + /*! * Converts a sparse matrix in the gmm++ format to Storm Sparse Matrix format. * @return A pointer to a row-major sparse matrix in our format. @@ -86,6 +110,39 @@ public: return result; } + + /*! + * Converts a sparse matrix in the gmm++ format to Storm Sparse Matrix format. + * @return A pointer to a row-major sparse matrix in our format. + */ + template + static storm::storage::SparseMatrix* fromGmmxxSparseMatrix(gmm::csr_matrix && matrix) { + uint_fast64_t realNonZeros = gmm::nnz(matrix); + LOG4CPLUS_DEBUG(logger, "Converting matrix with " << realNonZeros << " non-zeros from gmm++ format into Storm."); + + // Prepare the resulting matrix. + storm::storage::SparseMatrix* result = new storm::storage::SparseMatrix(matrix.nrows(), matrix.ncols()); + + // Set internal NonZero Counter + result->nonZeroEntryCount = realNonZeros; + result->setState(result->Initialized); + + // Move Row Indications + result->rowIndications(std::move(matrix.jc)); + // Move Columns Indications + result->columnIndications(std::move(matrix.ir)); + // And do the same thing with the actual values. + result->valueStorage(std::move(matrix.pr)); + + result->currentSize = realNonZeros; + result->lastRow = matrix.nrows() - 1; + + result->finalize(); + + LOG4CPLUS_DEBUG(logger, "Done converting matrix to storm format."); + + return result; + } }; } //namespace adapters diff --git a/src/models/AbstractDeterministicModel.h b/src/models/AbstractDeterministicModel.h index 73f1bc2ad..277366bd5 100644 --- a/src/models/AbstractDeterministicModel.h +++ b/src/models/AbstractDeterministicModel.h @@ -42,7 +42,9 @@ class AbstractDeterministicModel: public AbstractModel { */ AbstractDeterministicModel(storm::storage::SparseMatrix&& transitionMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling, boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) - : AbstractModel(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { + // The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class + : AbstractModel(std::move(transitionMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) { + // Intentionally left empty. } /*! @@ -58,6 +60,13 @@ class AbstractDeterministicModel: public AbstractModel { AbstractDeterministicModel(AbstractDeterministicModel const& other) : AbstractModel(other) { // Intentionally left empty. } + + /*! + * Move Constructor. + */ + AbstractDeterministicModel(AbstractDeterministicModel && other) : AbstractModel(std::move(other)) { + // Intentionally left empty. + } /*! * Returns an iterator to the successors of the given state. diff --git a/src/models/AbstractModel.h b/src/models/AbstractModel.h index dcb292121..9aff2fa10 100644 --- a/src/models/AbstractModel.h +++ b/src/models/AbstractModel.h @@ -52,12 +52,12 @@ class AbstractModel: public std::enable_shared_from_this> { * the given labeling of the states. Creates copies of all given references. * @param other The Source Abstract Model */ - AbstractModel(AbstractModel&& other) { - this->transitionMatrix = std::move(other.transitionMatrix); - this->stateLabeling = std::move(other.stateLabeling); - - this->stateRewardVector = std::move(other.stateRewardVector); - this->transitionRewardMatrix = std::move(other.transitionRewardMatrix); + AbstractModel(AbstractModel&& other) + : transitionMatrix(std::move(other.transitionMatrix)), + stateLabeling(std::move(other.stateLabeling)), + stateRewardVector(std::move(other.stateRewardVector)), + transitionRewardMatrix(std::move(other.transitionRewardMatrix)) { + // Intentionally left empty. } /*! Constructs an abstract model from the given transition matrix and @@ -89,13 +89,9 @@ class AbstractModel: public std::enable_shared_from_this> { * @param transitionRewardMatrix The reward values associated with the transitions of the model. */ AbstractModel(storm::storage::SparseMatrix&& transitionMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling, - boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) { - this->transitionMatrix = std::move(transitionMatrix); - this->stateLabeling = std::move(stateLabeling); - - this->stateRewardVector = std::move(optionalStateRewardVector); - this->transitionRewardMatrix = std::move(optionalTransitionRewardMatrix); - } + boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) : + transitionMatrix(std::move(transitionMatrix)), stateLabeling(std::move(stateLabeling)), + stateRewardVector(std::move(optionalStateRewardVector)), transitionRewardMatrix(std::move(optionalTransitionRewardMatrix)) { } /*! * Destructor. diff --git a/src/models/AbstractNondeterministicModel.h b/src/models/AbstractNondeterministicModel.h index 1374c775e..4515a7a2c 100644 --- a/src/models/AbstractNondeterministicModel.h +++ b/src/models/AbstractNondeterministicModel.h @@ -52,8 +52,10 @@ class AbstractNondeterministicModel: public AbstractModel { std::vector&& nondeterministicChoiceIndices, boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) - : AbstractModel(transitionMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { - this->nondeterministicChoiceIndices = std::move(nondeterministicChoiceIndices); + // The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class + : AbstractModel(std::move(transitionMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)), + nondeterministicChoiceIndices(std::move(nondeterministicChoiceIndices)) { + // Intentionally left empty. } /*! @@ -74,7 +76,7 @@ class AbstractNondeterministicModel: public AbstractModel { /*! * Move Constructor. */ - AbstractNondeterministicModel(AbstractNondeterministicModel&& other) : AbstractModel(other), + AbstractNondeterministicModel(AbstractNondeterministicModel&& other) : AbstractModel(std::move(other)), nondeterministicChoiceIndices(std::move(other.nondeterministicChoiceIndices)) { // Intentionally left empty. } diff --git a/src/models/Ctmc.h b/src/models/Ctmc.h index 77e4317ec..faf16c0ec 100644 --- a/src/models/Ctmc.h +++ b/src/models/Ctmc.h @@ -38,6 +38,7 @@ public: Ctmc(storm::storage::SparseMatrix const& rateMatrix, storm::models::AtomicPropositionsLabeling const& stateLabeling, boost::optional> const& optionalStateRewardVector, boost::optional> const& optionalTransitionRewardMatrix) : AbstractDeterministicModel(rateMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { + // Intentionally left empty. } /*! @@ -50,7 +51,9 @@ public: */ Ctmc(storm::storage::SparseMatrix&& rateMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling, boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) - : AbstractDeterministicModel(rateMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { + // The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class + : AbstractDeterministicModel(std::move(rateMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) { + // Intentionally left empty. } /*! @@ -65,7 +68,7 @@ public: * Move Constructor. Performs a move on the given CTMC. * @param ctmc A reference to the CTMC that is to be moved from. */ - Ctmc(Ctmc&& ctmc) : AbstractDeterministicModel(ctmc) { + Ctmc(Ctmc&& ctmc) : AbstractDeterministicModel(std::move(ctmc)) { // Intentionally left empty. } diff --git a/src/models/Ctmdp.h b/src/models/Ctmdp.h index c314c46df..48655e302 100644 --- a/src/models/Ctmdp.h +++ b/src/models/Ctmdp.h @@ -63,7 +63,8 @@ public: std::vector&& nondeterministicChoiceIndices, boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) - : AbstractNondeterministicModel(probabilityMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) { + // The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class + : AbstractNondeterministicModel(std::move(probabilityMatrix), std::move(stateLabeling), std::move(nondeterministicChoiceIndices), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) { if (!this->checkValidityOfProbabilityMatrix()) { LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; @@ -85,7 +86,7 @@ public: * Move Constructor. Performs a move on the given CTMDP. * @param ctmdp A reference to the CTMDP that is to be moved. */ - Ctmdp(Ctmdp&& ctmdp) : AbstractNondeterministicModel(ctmdp) { + Ctmdp(Ctmdp&& ctmdp) : AbstractNondeterministicModel(std::move(ctmdp)) { if (!this->checkValidityOfProbabilityMatrix()) { LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; diff --git a/src/models/Dtmc.h b/src/models/Dtmc.h index c97c6c513..1813ef0ce 100644 --- a/src/models/Dtmc.h +++ b/src/models/Dtmc.h @@ -68,7 +68,8 @@ public: */ Dtmc(storm::storage::SparseMatrix&& probabilityMatrix, storm::models::AtomicPropositionsLabeling&& stateLabeling, boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) - : AbstractDeterministicModel(probabilityMatrix, stateLabeling, optionalStateRewardVector, optionalTransitionRewardMatrix) { + // The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class + : AbstractDeterministicModel(std::move(probabilityMatrix), std::move(stateLabeling), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) { if (!this->checkValidityOfProbabilityMatrix()) { LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; @@ -93,7 +94,7 @@ public: * Move Constructor. Performs a move on the given DTMC. * @param dtmc A reference to the DTMC that is to be moved. */ - Dtmc(Dtmc&& dtmc) : AbstractDeterministicModel(dtmc) { + Dtmc(Dtmc&& dtmc) : AbstractDeterministicModel(std::move(dtmc)) { // Intentionally left empty. } diff --git a/src/models/Mdp.h b/src/models/Mdp.h index 17dd907c2..9a1fcb610 100644 --- a/src/models/Mdp.h +++ b/src/models/Mdp.h @@ -65,7 +65,8 @@ public: std::vector&& nondeterministicChoiceIndices, boost::optional>&& optionalStateRewardVector, boost::optional>&& optionalTransitionRewardMatrix) - : AbstractNondeterministicModel(transitionMatrix, stateLabeling, nondeterministicChoiceIndices, optionalStateRewardVector, optionalTransitionRewardMatrix) { + // The std::move call must be repeated here because otherwise this calls the copy constructor of the Base Class + : AbstractNondeterministicModel(std::move(transitionMatrix), std::move(stateLabeling), std::move(nondeterministicChoiceIndices), std::move(optionalStateRewardVector), std::move(optionalTransitionRewardMatrix)) { if (!this->checkValidityOfProbabilityMatrix()) { LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; @@ -87,7 +88,7 @@ public: * Move Constructor. Performs a move on the given MDP. * @param mdp A reference to the MDP that is to be moved. */ - Mdp(Mdp&& mdp) : AbstractNondeterministicModel(mdp) { + Mdp(Mdp&& mdp) : AbstractNondeterministicModel(std::move(mdp)) { if (!this->checkValidityOfProbabilityMatrix()) { LOG4CPLUS_ERROR(logger, "Probability matrix is invalid."); throw storm::exceptions::InvalidArgumentException() << "Probability matrix is invalid."; diff --git a/src/parser/AutoParser.h b/src/parser/AutoParser.h index 304720f12..3a9d3f63c 100644 --- a/src/parser/AutoParser.h +++ b/src/parser/AutoParser.h @@ -47,19 +47,19 @@ class AutoParser { // Do actual parsing switch (type) { case storm::models::DTMC: { - this->model.reset(new storm::models::Dtmc(DeterministicModelParserAsDtmc(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile))); + this->model.reset(new storm::models::Dtmc(std::move(DeterministicModelParserAsDtmc(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile)))); break; } case storm::models::CTMC: { - this->model.reset(new storm::models::Ctmc(DeterministicModelParserAsCtmc(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile))); + this->model.reset(new storm::models::Ctmc(std::move(DeterministicModelParserAsCtmc(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile)))); break; } case storm::models::MDP: { - this->model.reset(new storm::models::Mdp(NondeterministicModelParserAsMdp(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile))); + this->model.reset(new storm::models::Mdp(std::move(NondeterministicModelParserAsMdp(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile)))); break; } case storm::models::CTMDP: { - this->model.reset(new storm::models::Ctmdp(NondeterministicModelParserAsCtmdp(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile))); + this->model.reset(new storm::models::Ctmdp(std::move(NondeterministicModelParserAsCtmdp(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile)))); break; } default: ; // Unknown diff --git a/src/parser/DeterministicModelParser.cpp b/src/parser/DeterministicModelParser.cpp index e1a7864a2..af38c1a7f 100644 --- a/src/parser/DeterministicModelParser.cpp +++ b/src/parser/DeterministicModelParser.cpp @@ -29,20 +29,21 @@ namespace parser { DeterministicModelParserResultContainer parseDeterministicModel(std::string const & transitionSystemFile, std::string const & labelingFile, std::string const & stateRewardFile, std::string const & transitionRewardFile) { - storm::storage::SparseMatrix resultTransitionSystem = storm::parser::DeterministicSparseTransitionParser(transitionSystemFile); + storm::storage::SparseMatrix resultTransitionSystem(std::move(storm::parser::DeterministicSparseTransitionParser(transitionSystemFile))); - uint_fast64_t stateCount = resultTransitionSystem.getRowCount(); + uint_fast64_t stateCount = resultTransitionSystem.getColumnCount(); + uint_fast64_t rowCount = resultTransitionSystem.getRowCount(); - storm::models::AtomicPropositionsLabeling resultLabeling = storm::parser::AtomicPropositionLabelingParser(stateCount, labelingFile); + storm::models::AtomicPropositionsLabeling resultLabeling(std::move(storm::parser::AtomicPropositionLabelingParser(stateCount, labelingFile))); - DeterministicModelParserResultContainer result(resultTransitionSystem, resultLabeling); + DeterministicModelParserResultContainer result(std::move(resultTransitionSystem), std::move(resultLabeling)); if (stateRewardFile != "") { result.stateRewards.reset(storm::parser::SparseStateRewardParser(stateCount, stateRewardFile)); } if (transitionRewardFile != "") { - RewardMatrixInformationStruct* rewardMatrixInfo = new RewardMatrixInformationStruct(stateCount, stateCount, nullptr); - result.transitionRewards.reset(storm::parser::DeterministicSparseTransitionParser(transitionRewardFile, false, rewardMatrixInfo)); + RewardMatrixInformationStruct* rewardMatrixInfo = new RewardMatrixInformationStruct(rowCount, stateCount, nullptr); + result.transitionRewards.reset(std::move(storm::parser::DeterministicSparseTransitionParser(transitionRewardFile, false, rewardMatrixInfo))); delete rewardMatrixInfo; } @@ -56,8 +57,8 @@ DeterministicModelParserResultContainer parseDeterministicModel(std::str */ storm::models::Dtmc DeterministicModelParserAsDtmc(std::string const & transitionSystemFile, std::string const & labelingFile, std::string const & stateRewardFile, std::string const & transitionRewardFile) { - DeterministicModelParserResultContainer parserResult = parseDeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile); - return storm::models::Dtmc(parserResult.transitionSystem, parserResult.labeling, parserResult.stateRewards, parserResult.transitionRewards); + DeterministicModelParserResultContainer parserResult(std::move(parseDeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile))); + return storm::models::Dtmc(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards)); } /*! @@ -67,8 +68,8 @@ storm::models::Dtmc DeterministicModelParserAsDtmc(std::string const & t */ storm::models::Ctmc DeterministicModelParserAsCtmc(std::string const & transitionSystemFile, std::string const & labelingFile, std::string const & stateRewardFile, std::string const & transitionRewardFile) { - DeterministicModelParserResultContainer parserResult = parseDeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile); - return storm::models::Ctmc(parserResult.transitionSystem, parserResult.labeling, parserResult.stateRewards, parserResult.transitionRewards); + DeterministicModelParserResultContainer parserResult(std::move(parseDeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile))); + return storm::models::Ctmc(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards)); } } /* namespace parser */ diff --git a/src/parser/DeterministicModelParser.h b/src/parser/DeterministicModelParser.h index 26bcde2bb..273c64c49 100644 --- a/src/parser/DeterministicModelParser.h +++ b/src/parser/DeterministicModelParser.h @@ -42,6 +42,12 @@ public: boost::optional> stateRewards; boost::optional> transitionRewards; DeterministicModelParserResultContainer(storm::storage::SparseMatrix& transitionSystem, storm::models::AtomicPropositionsLabeling& labeling) : transitionSystem(transitionSystem), labeling(labeling) { } + DeterministicModelParserResultContainer(storm::storage::SparseMatrix&& transitionSystem, storm::models::AtomicPropositionsLabeling&& labeling) : transitionSystem(std::move(transitionSystem)), labeling(std::move(labeling)) { } + + DeterministicModelParserResultContainer(const DeterministicModelParserResultContainer & other) : transitionSystem(other.transitionSystem), + labeling(other.labeling), stateRewards(other.stateRewards), transitionRewards(other.transitionRewards) {} + DeterministicModelParserResultContainer(DeterministicModelParserResultContainer && other) : transitionSystem(std::move(other.transitionSystem)), + labeling(std::move(other.labeling)), stateRewards(std::move(other.stateRewards)), transitionRewards(std::move(other.transitionRewards)) {} private: DeterministicModelParserResultContainer() {} }; diff --git a/src/parser/NondeterministicModelParser.cpp b/src/parser/NondeterministicModelParser.cpp index 228e45b57..f59e17862 100644 --- a/src/parser/NondeterministicModelParser.cpp +++ b/src/parser/NondeterministicModelParser.cpp @@ -29,20 +29,21 @@ namespace parser { NondeterministicModelParserResultContainer parseNondeterministicModel(std::string const & transitionSystemFile, std::string const & labelingFile, std::string const & stateRewardFile, std::string const & transitionRewardFile) { - NondeterministicSparseTransitionParserResult_t nondeterministicSparseTransitionParserResult = storm::parser::NondeterministicSparseTransitionParser(transitionSystemFile); - storm::storage::SparseMatrix resultTransitionSystem = nondeterministicSparseTransitionParserResult.first; + NondeterministicSparseTransitionParserResult_t nondeterministicSparseTransitionParserResult(std::move(storm::parser::NondeterministicSparseTransitionParser(transitionSystemFile))); + storm::storage::SparseMatrix resultTransitionSystem(std::move(nondeterministicSparseTransitionParserResult.first)); uint_fast64_t stateCount = resultTransitionSystem.getColumnCount(); + uint_fast64_t rowCount = resultTransitionSystem.getRowCount(); - storm::models::AtomicPropositionsLabeling resultLabeling = storm::parser::AtomicPropositionLabelingParser(stateCount, labelingFile); + storm::models::AtomicPropositionsLabeling resultLabeling(std::move(storm::parser::AtomicPropositionLabelingParser(stateCount, labelingFile))); - NondeterministicModelParserResultContainer result(resultTransitionSystem, nondeterministicSparseTransitionParserResult.second, resultLabeling); + NondeterministicModelParserResultContainer result(std::move(resultTransitionSystem), std::move(nondeterministicSparseTransitionParserResult.second), std::move(resultLabeling)); if (stateRewardFile != "") { result.stateRewards.reset(storm::parser::SparseStateRewardParser(stateCount, stateRewardFile)); } if (transitionRewardFile != "") { - RewardMatrixInformationStruct* rewardMatrixInfo = new RewardMatrixInformationStruct(nondeterministicSparseTransitionParserResult.first.getRowCount(), nondeterministicSparseTransitionParserResult.first.getColumnCount(), &nondeterministicSparseTransitionParserResult.second); + RewardMatrixInformationStruct* rewardMatrixInfo = new RewardMatrixInformationStruct(rowCount, stateCount, &result.rowMapping); result.transitionRewards.reset(storm::parser::NondeterministicSparseTransitionParser(transitionRewardFile, rewardMatrixInfo).first); delete rewardMatrixInfo; } @@ -57,7 +58,7 @@ NondeterministicModelParserResultContainer parseNondeterministicModel(st storm::models::Mdp NondeterministicModelParserAsMdp(std::string const & transitionSystemFile, std::string const & labelingFile, std::string const & stateRewardFile, std::string const & transitionRewardFile) { NondeterministicModelParserResultContainer parserResult = parseNondeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile); - return storm::models::Mdp(parserResult.transitionSystem, parserResult.labeling, parserResult.rowMapping, parserResult.stateRewards, parserResult.transitionRewards); + return storm::models::Mdp(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.rowMapping), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards)); } /*! @@ -68,7 +69,7 @@ storm::models::Mdp NondeterministicModelParserAsMdp(std::string const & storm::models::Ctmdp NondeterministicModelParserAsCtmdp(std::string const & transitionSystemFile, std::string const & labelingFile, std::string const & stateRewardFile, std::string const & transitionRewardFile) { NondeterministicModelParserResultContainer parserResult = parseNondeterministicModel(transitionSystemFile, labelingFile, stateRewardFile, transitionRewardFile); - return storm::models::Ctmdp(parserResult.transitionSystem, parserResult.labeling, parserResult.rowMapping, parserResult.stateRewards, parserResult.transitionRewards); + return storm::models::Ctmdp(std::move(parserResult.transitionSystem), std::move(parserResult.labeling), std::move(parserResult.rowMapping), std::move(parserResult.stateRewards), std::move(parserResult.transitionRewards)); } } /* namespace parser */ diff --git a/src/parser/NondeterministicModelParser.h b/src/parser/NondeterministicModelParser.h index 0f47cd084..449a9b162 100644 --- a/src/parser/NondeterministicModelParser.h +++ b/src/parser/NondeterministicModelParser.h @@ -42,7 +42,13 @@ public: std::vector rowMapping; boost::optional> stateRewards; boost::optional> transitionRewards; - NondeterministicModelParserResultContainer(storm::storage::SparseMatrix transitionSystem, std::vector rowMapping, storm::models::AtomicPropositionsLabeling labeling) : transitionSystem(transitionSystem), labeling(labeling), rowMapping(rowMapping) { } + NondeterministicModelParserResultContainer(storm::storage::SparseMatrix& transitionSystem, std::vector& rowMapping, storm::models::AtomicPropositionsLabeling& labeling) : transitionSystem(transitionSystem), labeling(labeling), rowMapping(rowMapping) { } + NondeterministicModelParserResultContainer(storm::storage::SparseMatrix&& transitionSystem, std::vector&& rowMapping, storm::models::AtomicPropositionsLabeling&& labeling) : transitionSystem(std::move(transitionSystem)), labeling(std::move(labeling)), rowMapping(std::move(rowMapping)) { } + + NondeterministicModelParserResultContainer(const NondeterministicModelParserResultContainer & other) : transitionSystem(other.transitionSystem), + labeling(other.labeling), rowMapping(other.rowMapping), stateRewards(other.stateRewards), transitionRewards(other.transitionRewards) {} + NondeterministicModelParserResultContainer(NondeterministicModelParserResultContainer && other) : transitionSystem(std::move(other.transitionSystem)), + labeling(std::move(other.labeling)), rowMapping(std::move(other.rowMapping)), stateRewards(std::move(other.stateRewards)), transitionRewards(std::move(other.transitionRewards)) {} private: NondeterministicModelParserResultContainer() {} }; diff --git a/src/parser/NondeterministicSparseTransitionParser.cpp b/src/parser/NondeterministicSparseTransitionParser.cpp index fdedd3766..b94e40868 100644 --- a/src/parser/NondeterministicSparseTransitionParser.cpp +++ b/src/parser/NondeterministicSparseTransitionParser.cpp @@ -390,7 +390,7 @@ NondeterministicSparseTransitionParserResult_t NondeterministicSparseTransitionP */ matrix.finalize(); - return std::make_pair(matrix, rowMapping); + return std::make_pair(std::move(matrix), std::move(rowMapping)); } } // namespace parser diff --git a/test/performance/graph/GraphTest.cpp b/test/performance/graph/GraphTest.cpp index 6d634de28..9ce96d1bc 100644 --- a/test/performance/graph/GraphTest.cpp +++ b/test/performance/graph/GraphTest.cpp @@ -8,19 +8,20 @@ TEST(GraphTest, PerformProb01) { storm::parser::AutoParser parser(STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds20_5.tra", STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds20_5.lab", "", ""); std::shared_ptr> dtmc = parser.getModel>(); + storm::storage::BitVector trueStates(dtmc->getNumberOfStates(), true); LOG4CPLUS_WARN(logger, "Computing prob01 (3 times) for crowds/crowds20_5..."); - std::pair prob01 = storm::utility::graph::performProb01(*dtmc, storm::storage::BitVector(dtmc->getNumberOfStates(), true), storm::storage::BitVector(dtmc->getLabeledStates("observe0Greater1"))); + std::pair prob01(storm::utility::graph::performProb01(*dtmc, trueStates, storm::storage::BitVector(dtmc->getLabeledStates("observe0Greater1")))); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 1724414u); ASSERT_EQ(prob01.second.getNumberOfSetBits(), 46046u); - prob01 = storm::utility::graph::performProb01(*dtmc, storm::storage::BitVector(dtmc->getNumberOfStates(), true), storm::storage::BitVector(dtmc->getLabeledStates("observeIGreater1"))); + prob01 = storm::utility::graph::performProb01(*dtmc, trueStates, storm::storage::BitVector(dtmc->getLabeledStates("observeIGreater1"))); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 574016u); ASSERT_EQ(prob01.second.getNumberOfSetBits(), 825797u); - prob01 = storm::utility::graph::performProb01(*dtmc, storm::storage::BitVector(dtmc->getNumberOfStates(), true), storm::storage::BitVector(dtmc->getLabeledStates("observeOnlyTrueSender"))); + prob01 = storm::utility::graph::performProb01(*dtmc, trueStates, storm::storage::BitVector(dtmc->getLabeledStates("observeOnlyTrueSender"))); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 1785309u); ASSERT_EQ(prob01.second.getNumberOfSetBits(), 40992u); @@ -31,9 +32,10 @@ TEST(GraphTest, PerformProb01) { storm::parser::AutoParser parser2(STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader6_8.tra", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader6_8.lab", "", ""); std::shared_ptr> dtmc2 = parser2.getModel>(); - + trueStates = storm::storage::BitVector(dtmc2->getNumberOfStates(), true); + LOG4CPLUS_WARN(logger, "Computing prob01 for synchronous_leader/leader6_8..."); - prob01 = storm::utility::graph::performProb01(*dtmc2, storm::storage::BitVector(dtmc2->getNumberOfStates(), true), storm::storage::BitVector(dtmc2->getLabeledStates("elected"))); + prob01 = storm::utility::graph::performProb01(*dtmc2, trueStates, storm::storage::BitVector(dtmc2->getLabeledStates("elected"))); LOG4CPLUS_WARN(logger, "Done."); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0u); @@ -45,16 +47,17 @@ TEST(GraphTest, PerformProb01) { TEST(GraphTest, PerformProb01MinMax) { storm::parser::AutoParser parser(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.lab", "", ""); std::shared_ptr> mdp = parser.getModel>(); + storm::storage::BitVector trueStates(mdp->getNumberOfStates(), true); LOG4CPLUS_WARN(logger, "Computing prob01min for asynchronous_leader/leader7..."); - std::pair prob01 = storm::utility::graph::performProb01Min(*mdp, storm::storage::BitVector(mdp->getNumberOfStates(), true), mdp->getLabeledStates("elected")); + std::pair prob01(storm::utility::graph::performProb01Min(*mdp, trueStates, mdp->getLabeledStates("elected"))); LOG4CPLUS_WARN(logger, "Done."); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0u); ASSERT_EQ(prob01.second.getNumberOfSetBits(), 2095783u); LOG4CPLUS_WARN(logger, "Computing prob01max for asynchronous_leader/leader7..."); - prob01 = storm::utility::graph::performProb01Max(*mdp, storm::storage::BitVector(mdp->getNumberOfStates(), true), mdp->getLabeledStates("elected")); + prob01 = storm::utility::graph::performProb01Max(*mdp, trueStates, mdp->getLabeledStates("elected")); LOG4CPLUS_WARN(logger, "Done."); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0u); @@ -64,16 +67,17 @@ TEST(GraphTest, PerformProb01MinMax) { storm::parser::AutoParser parser2(STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.tra", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.lab", "", ""); std::shared_ptr> mdp2 = parser2.getModel>(); + trueStates = storm::storage::BitVector(mdp2->getNumberOfStates(), true); LOG4CPLUS_WARN(logger, "Computing prob01min for consensus/coin4_6..."); - prob01 = storm::utility::graph::performProb01Min(*mdp2, storm::storage::BitVector(mdp2->getNumberOfStates(), true), mdp2->getLabeledStates("finished")); + prob01 = storm::utility::graph::performProb01Min(*mdp2, trueStates, mdp2->getLabeledStates("finished")); LOG4CPLUS_WARN(logger, "Done."); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0u); ASSERT_EQ(prob01.second.getNumberOfSetBits(), 63616u); LOG4CPLUS_WARN(logger, "Computing prob01max for consensus/coin4_6..."); - prob01 = storm::utility::graph::performProb01Max(*mdp2, storm::storage::BitVector(mdp2->getNumberOfStates(), true), mdp2->getLabeledStates("finished")); + prob01 = storm::utility::graph::performProb01Max(*mdp2, trueStates, mdp2->getLabeledStates("finished")); LOG4CPLUS_WARN(logger, "Done."); ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0u); @@ -87,13 +91,13 @@ TEST(GraphTest, PerformSCCDecompositionAndGetDependencyGraph) { std::shared_ptr> dtmc = parser.getModel>(); LOG4CPLUS_WARN(logger, "Computing SCC decomposition of crowds/crowds20_5..."); - std::vector> sccDecomposition = storm::utility::graph::performSccDecomposition(*dtmc); + std::vector> sccDecomposition(std::move(storm::utility::graph::performSccDecomposition(*dtmc))); LOG4CPLUS_WARN(logger, "Done."); ASSERT_EQ(sccDecomposition.size(), 1290297u); LOG4CPLUS_WARN(logger, "Extracting SCC dependency graph of crowds/crowds20_5..."); - storm::storage::SparseMatrix sccDependencyGraph = dtmc->extractPartitionDependencyGraph(sccDecomposition); + storm::storage::SparseMatrix sccDependencyGraph(std::move(dtmc->extractPartitionDependencyGraph(sccDecomposition))); LOG4CPLUS_WARN(logger, "Done."); ASSERT_EQ(sccDependencyGraph.getNonZeroEntryCount(), 1371253u);