From 018e7ce056ff6e1acee775aad7920d7ad1fa152a Mon Sep 17 00:00:00 2001 From: gereon Date: Tue, 12 Mar 2013 09:43:58 +0100 Subject: [PATCH] some minor fixes. Adapter now produces same result as prism for examples/dtmc/sync/sync.pm except order of nodes. --- src/adapters/ExplicitModelAdapter.h | 40 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/adapters/ExplicitModelAdapter.h b/src/adapters/ExplicitModelAdapter.h index 1cb8151ff..23b4e0a5f 100644 --- a/src/adapters/ExplicitModelAdapter.h +++ b/src/adapters/ExplicitModelAdapter.h @@ -64,9 +64,9 @@ public: std::shared_ptr> toSparseMatrix() { LOG4CPLUS_INFO(logger, "Creating sparse matrix for probabilistic program."); - this->buildMatrix2(); - this->computeReachableStateSpace(); - std::shared_ptr> resultMatrix = this->buildMatrix(); + //this->buildMatrix2(); + //this->computeReachableStateSpace(); + std::shared_ptr> resultMatrix = this->buildMatrix2(); LOG4CPLUS_INFO(logger, "Created sparse matrix with " << resultMatrix->getRowCount() << " reachable states and " << resultMatrix->getNonZeroEntryCount() << " transitions."); @@ -236,6 +236,7 @@ private: auto stateIt = states->find(newStateId); if (stateIt == states->end()) { (*states)[newStateId] = update.getLikelihoodExpression()->getValueAsDouble(state); + this->numberOfTransitions++; } else { (*states)[newStateId] += update.getLikelihoodExpression()->getValueAsDouble(state); } @@ -288,15 +289,17 @@ private: } - res.emplace_back(); - std::map* states = &res.back(); + if (resultStates.size() > 0) { + res.emplace_back(); + std::map* states = &res.back(); - // Now add our final result states to our global result. - for (auto it : resultStates) { - uint_fast64_t newStateID = this->getOrAddStateId(it.first); - (*states)[newStateID] = it.second; + // Now add our final result states to our global result. + for (auto it : resultStates) { + uint_fast64_t newStateID = this->getOrAddStateId(it.first); + (*states)[newStateID] = it.second; + } + this->numberOfTransitions += states->size(); } - this->numberOfTransitions += states->size(); } } @@ -315,6 +318,7 @@ private: */ template std::shared_ptr> buildDTMCMatrix(std::map>> intermediate) { + std::cout << "Building DTMC matrix" << std::endl; std::shared_ptr> result(new storm::storage::SparseMatrix(allStates.size())); uint_fast64_t numberOfTransitions = 0; for (uint_fast64_t state = 0; state < this->allStates.size(); state++) { @@ -326,19 +330,21 @@ private: } numberOfTransitions += set.size(); } + std::cout << "number of Transitions: " << numberOfTransitions << std::endl; result->initialize(numberOfTransitions); for (uint_fast64_t state = 0; state < this->allStates.size(); state++) { - //if (intermediate[state].size() > 1) WARNING; - double factor = 1.0 / intermediate[state].size(); + if (intermediate[state].size() > 1) { + std::cout << "Warning: state " << state << " has " << intermediate[state].size() << " overlapping guards in dtmc" << std::endl; + } std::map map; for (auto choice : intermediate[state]) { for (auto elem : choice) { - map[elem.first] += elem.second * factor; + map[elem.first] += elem.second; } } - std::cout << "adding " << map.size() << " elements" << std::endl; + double factor = 1.0 / intermediate[state].size(); for (auto it : map) { - result->addNextValue(state, it.first, it.second); + result->addNextValue(state, it.first, it.second * factor); } } @@ -354,8 +360,9 @@ private: */ template std::shared_ptr> buildMDPMatrix(std::map>> intermediate, uint_fast64_t choices) { + std::cout << "Building MDP matrix" << std::endl; std::shared_ptr> result(new storm::storage::SparseMatrix(allStates.size(), choices)); - result->initialize(numberOfTransitions); + result->initialize(this->numberOfTransitions); uint_fast64_t nextRow = 0; for (uint_fast64_t state = 0; state < this->allStates.size(); state++) { for (auto choice : intermediate[state]) { @@ -374,6 +381,7 @@ private: this->prepareAuxiliaryDatastructures(); this->allStates.clear(); this->stateToIndexMap.clear(); + this->numberOfTransitions = 0; uint_fast64_t choices; std::map>> intermediate;