33 changed files with 716 additions and 220 deletions
-
9CMakeLists.txt
-
0LICENSE-STORM.txt
-
57src/adapters/EigenAdapter.h
-
11src/adapters/GmmxxAdapter.h
-
6src/exceptions/BaseException.h
-
19src/exceptions/InvalidAccessException.h
-
1src/modelChecker/DtmcPrctlModelChecker.h
-
2src/modelChecker/EigenDtmcPrctlModelChecker.h
-
75src/modelChecker/GmmxxDtmcPrctlModelChecker.h
-
18src/models/AbstractModel.cpp
-
4src/models/AbstractModel.h
-
22src/models/Dtmc.h
-
20src/parser/AutoParser.cpp
-
2src/parser/AutoParser.h
-
24src/parser/DeterministicModelParser.cpp
-
62src/parser/DeterministicModelParser.h
-
185src/parser/DeterministicSparseTransitionParser.cpp
-
4src/parser/DeterministicSparseTransitionParser.h
-
40src/parser/DtmcParser.h
-
14src/parser/NonDeterministicSparseTransitionParser.cpp
-
2src/parser/NonDeterministicSparseTransitionParser.h
-
30src/storage/BitVector.h
-
6src/storage/JacobiDecomposition.h
-
80src/storage/SparseMatrix.h
-
8src/storm.cpp
-
8src/utility/Settings.cpp
-
59src/utility/Settings.h
-
96test/eigen/EigenAdapterTest.cpp
-
6test/parser/ParseDtmcTest.cpp
-
9test/storage/SparseMatrixTest.cpp
-
33test/storm-tests.cpp
@ -0,0 +1,57 @@ |
|||
/* |
|||
* EigenAdapter.h |
|||
* |
|||
* Created on: 21.01.2013 |
|||
* Author: Philipp Berger |
|||
*/ |
|||
|
|||
#ifndef STORM_ADAPTERS_EIGENADAPTER_H_ |
|||
#define STORM_ADAPTERS_EIGENADAPTER_H_ |
|||
|
|||
#include "src/storage/SparseMatrix.h" |
|||
#include "Eigen/Sparse" |
|||
|
|||
#include "log4cplus/logger.h" |
|||
#include "log4cplus/loggingmacros.h" |
|||
|
|||
extern log4cplus::Logger logger; |
|||
|
|||
namespace storm { |
|||
|
|||
namespace adapters { |
|||
|
|||
class EigenAdapter { |
|||
public: |
|||
/*! |
|||
* Converts a sparse matrix into the sparse matrix in the eigen format. |
|||
* @return A pointer to a row-major sparse matrix in eigen format. |
|||
*/ |
|||
template<class T> |
|||
static Eigen::SparseMatrix<T, Eigen::RowMajor, int_fast32_t>* toEigenSparseMatrix(storm::storage::SparseMatrix<T> const& matrix) { |
|||
uint_fast64_t realNonZeros = matrix.getNonZeroEntryCount(); |
|||
LOG4CPLUS_DEBUG(logger, "Converting matrix with " << realNonZeros << " non-zeros to Eigen format."); |
|||
|
|||
// Prepare the resulting matrix. |
|||
Eigen::SparseMatrix<T, Eigen::RowMajor, int_fast32_t>* result = new Eigen::SparseMatrix<T, Eigen::RowMajor, int_fast32_t>(matrix.rowCount, matrix.colCount); |
|||
|
|||
result->resizeNonZeros(realNonZeros); |
|||
//result->reserve(realNonZeros); |
|||
|
|||
// Copy Row Indications |
|||
std::copy(matrix.rowIndications.begin(), matrix.rowIndications.end(), (result->outerIndexPtr())); |
|||
// Copy Columns Indications |
|||
std::copy(matrix.columnIndications.begin(), matrix.columnIndications.end(), (result->innerIndexPtr())); |
|||
// And do the same thing with the actual values. |
|||
std::copy(matrix.valueStorage.begin(), matrix.valueStorage.end(), (result->valuePtr())); |
|||
|
|||
LOG4CPLUS_DEBUG(logger, "Done converting matrix to Eigen format."); |
|||
|
|||
return result; |
|||
} |
|||
}; |
|||
|
|||
} //namespace adapters |
|||
|
|||
} //namespace storm |
|||
|
|||
#endif /* STORM_ADAPTERS_GMMXXADAPTER_H_ */ |
@ -0,0 +1,19 @@ |
|||
#ifndef STORM_EXCEPTIONS_INVALIDACCESSEXCEPTION_H_ |
|||
#define STORM_EXCEPTIONS_INVALIDACCESSEXCEPTION_H_ |
|||
|
|||
#include "src/exceptions/BaseException.h" |
|||
|
|||
namespace storm { |
|||
|
|||
namespace exceptions { |
|||
|
|||
/*! |
|||
* @brief This exception is thrown when a function is used/accessed that is forbidden to use (e.g. Copy Constructors) |
|||
*/ |
|||
STORM_EXCEPTION_DEFINE_NEW(InvalidAccessException) |
|||
|
|||
} // namespace exceptions |
|||
|
|||
} // namespace storm |
|||
|
|||
#endif // STORM_EXCEPTIONS_INVALIDACCESSEXCEPTION_H_ |
@ -0,0 +1,62 @@ |
|||
/* |
|||
* DtmcParser.h |
|||
* |
|||
* Created on: 19.12.2012 |
|||
* Author: thomas |
|||
*/ |
|||
|
|||
#ifndef STORM_PARSER_DETERMINISTICMODELPARSER_H_ |
|||
#define STORM_PARSER_DETERMINISTICMODELPARSER_H_ |
|||
|
|||
#include "src/parser/Parser.h" |
|||
#include "src/models/Dtmc.h" |
|||
#include "src/models/Ctmc.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
/*! |
|||
* @brief Load label and transition file and return initialized dtmc or ctmc object. |
|||
* |
|||
* @Note This class creates a new Dtmc or Ctmc object that can |
|||
* be accessed via getDtmc() or getCtmc(). However, it will not delete this object! |
|||
* |
|||
* @Note The labeling representation in the file may use at most as much nodes as are specified in the transition system. |
|||
*/ |
|||
class DeterministicModelParser: public storm::parser::Parser { |
|||
public: |
|||
DeterministicModelParser(std::string const & transitionSystemFile, std::string const & labelingFile, |
|||
std::string const & stateRewardFile = "", std::string const & transitionRewardFile = ""); |
|||
|
|||
/*! |
|||
* @brief Get the parsed dtmc model. |
|||
*/ |
|||
std::shared_ptr<storm::models::Dtmc<double>> getDtmc() { |
|||
if (this->dtmc == nullptr) { |
|||
this->dtmc = std::shared_ptr<storm::models::Dtmc<double>>(new storm::models::Dtmc<double>(this->transitionSystem, this->labeling, this->stateRewards, this->transitionRewards)); |
|||
} |
|||
return this->dtmc; |
|||
} |
|||
/*! |
|||
* @brief Get the parsed ctmc model. |
|||
*/ |
|||
std::shared_ptr<storm::models::Ctmc<double>> getCtmc() { |
|||
if (this->ctmc == nullptr) { |
|||
this->ctmc = std::shared_ptr<storm::models::Ctmc<double>>(new storm::models::Ctmc<double>(this->transitionSystem, this->labeling, this->stateRewards, this->transitionRewards)); |
|||
} |
|||
return this->ctmc; |
|||
} |
|||
|
|||
private: |
|||
std::shared_ptr<storm::storage::SparseMatrix<double>> transitionSystem; |
|||
std::shared_ptr<storm::models::AtomicPropositionsLabeling> labeling; |
|||
std::shared_ptr<std::vector<double>> stateRewards; |
|||
std::shared_ptr<storm::storage::SparseMatrix<double>> transitionRewards; |
|||
|
|||
std::shared_ptr<storm::models::Dtmc<double>> dtmc; |
|||
std::shared_ptr<storm::models::Ctmc<double>> ctmc; |
|||
}; |
|||
|
|||
} /* namespace parser */ |
|||
} /* namespace storm */ |
|||
#endif /* STORM_PARSER_DETERMINISTICMODELPARSER_H_ */ |
@ -1,40 +0,0 @@ |
|||
/* |
|||
* DtmcParser.h |
|||
* |
|||
* Created on: 19.12.2012 |
|||
* Author: thomas |
|||
*/ |
|||
|
|||
#ifndef STORM_PARSER_DTMCPARSER_H_ |
|||
#define STORM_PARSER_DTMCPARSER_H_ |
|||
|
|||
#include "src/parser/Parser.h" |
|||
#include "src/models/Dtmc.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
/*! |
|||
* @brief Load label and transition file and return initialized dtmc object |
|||
* |
|||
* @Note This class creates a new Dtmc object that can |
|||
* be accessed via getDtmc(). However, it will not delete this object! |
|||
* |
|||
* @Note The labeling representation in the file may use at most as much nodes as are specified in the dtmc. |
|||
*/ |
|||
class DtmcParser: public storm::parser::Parser { |
|||
public: |
|||
DtmcParser(std::string const & transitionSystemFile, std::string const & labelingFile, |
|||
std::string const & stateRewardFile = "", std::string const & transitionRewardFile = ""); |
|||
|
|||
std::shared_ptr<storm::models::Dtmc<double>> getDtmc() { |
|||
return this->dtmc; |
|||
} |
|||
|
|||
private: |
|||
std::shared_ptr<storm::models::Dtmc<double>> dtmc; |
|||
}; |
|||
|
|||
} /* namespace parser */ |
|||
} /* namespace storm */ |
|||
#endif /* STORM_PARSER_DTMCPARSER_H_ */ |
@ -0,0 +1,96 @@ |
|||
#include "gtest/gtest.h"
|
|||
|
|||
#include "Eigen/Sparse"
|
|||
#include "src/adapters/EigenAdapter.h"
|
|||
#include "src/exceptions/InvalidArgumentException.h"
|
|||
#include "boost/integer/integer_mask.hpp"
|
|||
|
|||
#define STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE 5
|
|||
#define STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE 5
|
|||
|
|||
TEST(EigenAdapterTest, SimpleDenseSquareCopy) { |
|||
// 5 rows
|
|||
storm::storage::SparseMatrix<double> sm(STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|||
|
|||
double values[STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE]; |
|||
sm.initialize(STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|||
|
|||
int row = 0; |
|||
int col = 0; |
|||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|||
values[i] = static_cast<double>(i + 1); |
|||
|
|||
sm.addNextValue(row, col, values[i]); |
|||
++col; |
|||
if (col == STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|||
++row; |
|||
col = 0; |
|||
} |
|||
} |
|||
sm.finalize(); |
|||
|
|||
auto esm = storm::adapters::EigenAdapter::toEigenSparseMatrix(sm); |
|||
|
|||
ASSERT_EQ(esm->rows(), STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|||
ASSERT_EQ(esm->cols(), STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|||
ASSERT_EQ(esm->nonZeros(), STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE); |
|||
|
|||
row = 0; |
|||
col = 0; |
|||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE; ++i) { |
|||
ASSERT_EQ(values[i], esm->coeff(row, col)); |
|||
++col; |
|||
if (col == STORM_EIGENADAPTERTEST_SIMPLEDENSESQUARECOPY_SIZE) { |
|||
++row; |
|||
col = 0; |
|||
} |
|||
} |
|||
} |
|||
|
|||
TEST(EigenAdapterTest, SimpleSparseSquareCopy) { |
|||
// 5 rows
|
|||
storm::storage::SparseMatrix<double> sm(STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|||
|
|||
double values[STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE]; |
|||
sm.initialize((STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE + 1) / 2); |
|||
|
|||
int row = 0; |
|||
int col = 0; |
|||
|
|||
bool everySecondElement = true; |
|||
|
|||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|||
values[i] = static_cast<double>(i + 1); |
|||
if (everySecondElement) { |
|||
sm.addNextValue(row, col, values[i]); |
|||
} |
|||
everySecondElement = !everySecondElement; |
|||
++col; |
|||
if (col == STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|||
++row; |
|||
col = 0; |
|||
} |
|||
} |
|||
sm.finalize(); |
|||
|
|||
auto esm = storm::adapters::EigenAdapter::toEigenSparseMatrix(sm); |
|||
|
|||
ASSERT_EQ(esm->rows(), STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|||
ASSERT_EQ(esm->cols(), STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE); |
|||
ASSERT_EQ(esm->nonZeros(), (STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE + 1) / 2); |
|||
|
|||
row = 0; |
|||
col = 0; |
|||
everySecondElement = true; |
|||
for (int i = 0; i < STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE * STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE; ++i) { |
|||
if (everySecondElement) { |
|||
ASSERT_EQ(values[i], esm->coeff(row, col)); |
|||
} |
|||
everySecondElement = !everySecondElement; |
|||
++col; |
|||
if (col == STORM_EIGENADAPTERTEST_SIMPLESPARSESQUARECOPY_SIZE) { |
|||
++row; |
|||
col = 0; |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue