Browse Source

Merge branch 'master' of https://sselab.de/lab9/private/git/MRMC

tempestpy_adaptions
gereon 12 years ago
parent
commit
97122e29cd
  1. 42
      CMakeLists.txt
  2. 56
      src/exceptions/NoConvergence.h
  3. 2
      src/formula/And.h
  4. 5
      src/formula/BoundedUntil.h
  5. 1
      src/formula/Formulas.h
  6. 2
      src/formula/Next.h
  7. 2
      src/formula/Not.h
  8. 2
      src/formula/Or.h
  9. 176
      src/formula/ProbabilisticIntervalOperator.h
  10. 113
      src/formula/ProbabilisticOperator.h
  11. 8
      src/modelChecker/DtmcPrctlModelChecker.cpp
  12. 27
      src/modelChecker/DtmcPrctlModelChecker.h
  13. 267
      src/modelChecker/EigenDtmcPrctlModelChecker.h
  14. 5
      src/modelChecker/GmmxxDtmcPrctlModelChecker.h
  15. 30
      src/models/AtomicPropositionsLabeling.h
  16. 2
      src/models/Dtmc.h
  17. 45
      src/mrmc.cpp
  18. 6
      src/parser/parser.cpp
  19. 5
      src/parser/parser.h
  20. 6
      src/parser/readLabFile.cpp
  21. 10
      src/parser/readTraFile.cpp
  22. 2
      src/parser/readTraFile.h
  23. 5
      src/storage/BitVector.h
  24. 4
      src/storage/SquareSparseMatrix.h
  25. 13
      src/utility/osDetection.h
  26. 9
      src/utility/vector.h

42
CMakeLists.txt

@ -9,17 +9,32 @@ set (MRMC_CPP_VERSION_MINOR 0)
# Set all GTest references to the version in the repository and show it as output
set (GTEST_INCLUDE_DIR resources/3rdparty/gtest-1.6.0/include)
set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.a)
set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.a)
if(MSVC)
set (MRMC_LIB_SUFFIX lib)
set (GTEST_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest.${MRMC_LIB_SUFFIX})
set (GTEST_MAIN_LIBRARY_DEBUG ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Debug/gtest_main.${MRMC_LIB_SUFFIX})
set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest.${MRMC_LIB_SUFFIX})
set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/build/Release/gtest_main.${MRMC_LIB_SUFFIX})
set (GTEST_LIBRARIES optimized ${GTEST_LIBRARY} debug ${GTEST_LIBRARY_DEBUG})
else()
set (MRMC_LIB_SUFFIX a)
set (GTEST_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest.${MRMC_LIB_SUFFIX})
set (GTEST_MAIN_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/gtest-1.6.0/libgtest_main.${MRMC_LIB_SUFFIX})
set (GTEST_LIBRARIES ${GTEST_LIBRARY}) # as we dont use FindGTest anymore
endif()
message(STATUS "GTEST_INCLUDE_DIR is ${GTEST_INCLUDE_DIR}")
message(STATUS "GTEST_LIBRARY is ${GTEST_LIBRARY}")
message(STATUS "GTEST_MAIN_LIBRARY is ${GTEST_MAIN_LIBRARY}")
# Set all log4cplus references the version in the repository
set (LOG4CPLUS_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/include)
set (LOG4CPLUS_LIBRARY ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/src/liblog4cplus.a)
if (MSVC)
set (LOG4CPLUS_LIBRARIES optimized ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Release/log4cplusS.${MRMC_LIB_SUFFIX} debug ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/msvc10/x64/bin.Debug/log4cplusSD.${MRMC_LIB_SUFFIX})
else()
set (LOG4CPLUS_LIBRARIES ${PROJECT_SOURCE_DIR}/resources/3rdparty/log4cplus-1.1.0/src/liblog4cplus.${MRMC_LIB_SUFFIX})
endif()
message(STATUS "LOG4CPLUS_INCLUDE_DIR is ${LOG4CPLUS_INCLUDE_DIR}")
message(STATUS "LOG4CPLUS_LIBRARY is ${LOG4CPLUS_LIBRARY}")
message(STATUS "LOG4CPLUS_LIBRARY is ${LOG4CPLUS_LIBRARIES}")
# Set all Eigen references the version in the repository
set(EIGEN3_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/resources/3rdparty/eigen)
@ -52,7 +67,8 @@ if(CMAKE_COMPILER_IS_GNUCC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")
endif(USE_POPCNT)
elseif(MSVC)
# required for GMM to compile, ugly error directive in their code
add_definitions(/D_SCL_SECURE_NO_DEPRECATE)
else(CLANG)
# Set standard flags for GCC
set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Werror -pedantic -Wno-unused-variable")
@ -88,12 +104,13 @@ source_group(Headers FILES ${MRMC_TEST_HEADERS})
source_group(Sources FILES ${MRMC_TEST_SOURCES})
# Add base folder for better inclusion paths
include_directories("${PROJECT_SOURCE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/src")
# Set required external packages
find_package(Threads REQUIRED)
find_package(Doxygen REQUIRED)
#set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS program_options)
@ -141,7 +158,7 @@ if (GTEST_INCLUDE_DIR)
enable_testing()
include_directories(${GTEST_INCLUDE_DIR})
target_link_libraries(mrmc-tests ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY})
target_link_libraries(mrmc-tests ${GTEST_LIBRARIES})
add_test(NAME mrmc-tests COMMAND mrmc-tests)
if(MSVC) # VS2012 doesn't support correctly the tuples yet
@ -151,8 +168,8 @@ endif(GTEST_INCLUDE_DIR)
if (LOG4CPLUS_INCLUDE_DIR)
include_directories(${LOG4CPLUS_INCLUDE_DIR})
target_link_libraries(mrmc ${LOG4CPLUS_LIBRARY})
target_link_libraries(mrmc-tests ${LOG4CPLUS_LIBRARY})
target_link_libraries(mrmc ${LOG4CPLUS_LIBRARIES})
target_link_libraries(mrmc-tests ${LOG4CPLUS_LIBRARIES})
# On Linux, we have to link against librt
if (UNIX AND NOT APPLE)
target_link_libraries(mrmc rt)
@ -172,5 +189,8 @@ configure_file (
"${PROJECT_BINARY_DIR}/mrmc-config.h"
)
add_custom_target(memcheck valgrind --leak-check=full --show-reachable=yes ./mrmc examples/dtmc/crowds/crowds5_5.tra examples/dtmc/crowds/crowds5_5.lab)
add_custom_target(memcheck-tests valgrind --leak-check=full --show-reachable=yes ./mrmc-tests)
add_custom_target(memcheck valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/mrmc ${PROJECT_SOURCE_DIR}/examples/dtmc/crowds/crowds5_5.tra examples/dtmc/crowds/crowds5_5.lab
DEPENDS mrmc)
add_custom_target(memcheck-tests valgrind --leak-check=full --show-reachable=yes ${PROJECT_BINARY_DIR}/mrmc-tests
DEPENDS mrmc-tests)

56
src/exceptions/NoConvergence.h

@ -0,0 +1,56 @@
#ifndef MRMC_EXCEPTIONS_NO_CONVERGENCE_H_
#define MRMC_EXCEPTIONS_NO_CONVERGENCE_H_
#include <exception>
namespace mrmc {
namespace exceptions {
//!This exception is thrown when an iterative solver failed to converge with the given maxIterations
class NoConvergence : public std::exception
{
public:
/* The Visual C++-Version of the exception class has constructors accepting
* a char*-constant; The GCC version does not have these
*
* As the "extended" constructor is used in the sparse matrix code, a dummy
* constructor is used under linux (which will ignore the parameter)
*/
#ifdef _WIN32
NoConvergence() : exception("::mrmc::NoConvergence"){
iterations = -1;
maxIterations = -1;
}
NoConvergence(const char * const s, int iterations, int maxIterations): exception(s) {
this->iterations = iterations;
this->maxIterations = maxIterations;
}
#else
NoConvergence() : exception() {
iterations = -1;
maxIterations = -1;
}
NoConvergence(const char * const s, int iterations, int maxIterations): exception() {
this->iterations = iterations;
this->maxIterations = maxIterations;
}
#endif
virtual const char* what() const throw()
{ return "mrmc::NoConvergence"; }
int getIterationCount() const {
return iterations;
}
int getMaxIterationCount() const {
return maxIterations;
}
private:
int iterations;
int maxIterations;
};
} // namespace exceptions
} // namespace mrmc
#endif // MRMC_EXCEPTIONS_NO_CONVERGENCE_H_

2
src/formula/And.h

@ -142,7 +142,7 @@ public:
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual mrmc::storage::BitVector *check(const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkAnd(this);
return modelChecker.checkAnd(*this);
}
private:

5
src/formula/BoundedUntil.h

@ -11,7 +11,6 @@
#include "PCTLPathFormula.h"
#include "PCTLStateFormula.h"
#include "boost/integer/integer_mask.hpp"
#include "boost/lexical_cast.hpp"
#include <string>
namespace mrmc {
@ -131,7 +130,7 @@ public:
std::string result = "(";
result += left->toString();
result += " U<=";
result += boost::lexical_cast<std::string>(bound);
result += std::to_string(bound);
result += " ";
result += right->toString();
result += ")";
@ -168,7 +167,7 @@ public:
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkBoundedUntil(this);
return modelChecker.checkBoundedUntil(*this);
}
private:

1
src/formula/Formulas.h

@ -18,6 +18,7 @@
#include "PCTLPathFormula.h"
#include "PCTLStateFormula.h"
#include "ProbabilisticOperator.h"
#include "ProbabilisticIntervalOperator.h"
#include "Until.h"
#endif /* FORMULAS_H_ */

2
src/formula/Next.h

@ -113,7 +113,7 @@ public:
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkNext(this);
return modelChecker.checkNext(*this);
}
private:

2
src/formula/Not.h

@ -106,7 +106,7 @@ public:
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual mrmc::storage::BitVector *check(const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkNot(this);
return modelChecker.checkNot(*this);
}
private:

2
src/formula/Or.h

@ -141,7 +141,7 @@ public:
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual mrmc::storage::BitVector *check(const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkOr(this);
return modelChecker.checkOr(*this);
}
private:

176
src/formula/ProbabilisticIntervalOperator.h

@ -0,0 +1,176 @@
/*
* ProbabilisticOperator.h
*
* Created on: 19.10.2012
* Author: Thomas Heinemann
*/
#ifndef PROBABILISTICINTERVALOPERATOR_H_
#define PROBABILISTICINTERVALOPERATOR_H_
#include "PCTLStateFormula.h"
#include "PCTLPathFormula.h"
#include "utility/const_templates.h"
namespace mrmc {
namespace formula {
/*!
* @brief
* Class for a PCTL formula tree with a P (probablistic) operator node over a probability interval
* as root.
*
* If the probability interval consist just of one single value (i.e. it is [x,x] for some
* real number x), the class ProbabilisticOperator should be used instead.
*
*
* Has one PCTL path formula as sub formula/tree.
*
* @par Semantics
* The formula holds iff the probability that the path formula holds is inside the bounds
* specified in this operator
*
* The subtree is seen as part of the object and deleted with it
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PCTLStateFormula
* @see PCTLPathFormula
* @see ProbabilisticOperator
* @see PCTLFormula
*/
template<class T>
class ProbabilisticIntervalOperator : public PCTLStateFormula<T> {
public:
/*!
* Empty constructor
*/
ProbabilisticIntervalOperator() {
upper = mrmc::utility::constGetZero(upper);
lower = mrmc::utility::constGetZero(lower);
pathFormula = NULL;
}
/*!
* Constructor
*
* @param lowerBound The lower bound for the probability
* @param upperBound The upper bound for the probability
* @param pathFormula The child node
*/
ProbabilisticIntervalOperator(T lowerBound, T upperBound, PCTLPathFormula<T>& pathFormula) {
this->lower = lowerBound;
this->upper = upperBound;
this->pathFormula = &pathFormula;
}
/*!
* Destructor
*
* The subtree is deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*/
virtual ~ProbabilisticIntervalOperator() {
if (pathFormula != NULL) {
delete pathFormula;
}
}
/*!
* @returns the child node (representation of a PCTL path formula)
*/
const PCTLPathFormula<T>& getPathFormula () const {
return *pathFormula;
}
/*!
* @returns the lower bound for the probability
*/
const T& getLowerBound() const {
return lower;
}
/*!
* @returns the upper bound for the probability
*/
const T& getUpperBound() const {
return upper;
}
/*!
* Sets the child node
*
* @param pathFormula the path formula that becomes the new child node
*/
void setPathFormula(PCTLPathFormula<T>* pathFormula) {
this->pathFormula = pathFormula;
}
/*!
* Sets the interval in which the probability that the path formula holds may lie in.
*
* @param lowerBound The lower bound for the probability
* @param upperBound The upper bound for the probability
*/
void setInterval(T lowerBound, T upperBound) {
this->lower = lowerBound;
this->upper = upperBound;
}
/*!
* @returns a string representation of the formula
*/
virtual std::string toString() const {
std::string result = "(";
result += " P[";
result += std::to_string(lower);
result += ";";
result += std::to_string(upper);
result += "] ";
result += pathFormula->toString();
result += ")";
return result;
}
/*!
* Clones the called object.
*
* Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
*
* @returns a new AND-object that is identical the called object.
*/
virtual PCTLStateFormula<T>* clone() const {
ProbabilisticIntervalOperator<T>* result = new ProbabilisticIntervalOperator<T>();
result->setInterval(lower, upper);
if (pathFormula != NULL) {
result->setPathFormula(pathFormula->clone());
}
return result;
}
/*!
* Calls the model checker to check this formula.
* Needed to infer the correct type of formula class.
*
* @note This function should only be called in a generic check function of a model checker class. For other uses,
* the methods of the model checker should be used.
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual mrmc::storage::BitVector *check(const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkProbabilisticIntervalOperator(*this);
}
private:
T lower;
T upper;
PCTLPathFormula<T>* pathFormula;
};
} //namespace formula
} //namespace mrmc
#endif /* PROBABILISTICINTERVALOPERATOR_H_ */

113
src/formula/ProbabilisticOperator.h

@ -1,7 +1,7 @@
/*
* ProbabilisticOperator.h
*
* Created on: 19.10.2012
* Created on: 07.12.2012
* Author: Thomas Heinemann
*/
@ -9,53 +9,54 @@
#define PROBABILISTICOPERATOR_H_
#include "PCTLStateFormula.h"
#include "PCTLPathFormula.h"
#include "utility/const_templates.h"
namespace mrmc {
namespace formula {
/*!
* @brief
* Class for a PCTL formula tree with a P (probablistic) operator node as root.
* Class for a PCTL formula tree with a P (probablistic) operator node over a single real valued
* probability as root.
*
* If the probability interval consist just of one single value (i.e. it is [x,x] for some
* real number x), the class ProbabilisticOperator should be used instead.
*
*
* Has one PCTL path formula as sub formula/tree.
*
* @par Semantics
* The formula holds iff the probability that the path formula holds is inside the bounds specified in this operator
* The formula holds iff the probability that the path formula holds is equal to the probablility
* specified in this operator
*
* The subtree is seen as part of the object and deleted with it
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PCTLStateFormula
* @see PCTLPathFormula
* @see ProbabilisticOperator
* @see PCTLFormula
*/
template<class T>
class ProbabilisticOperator : public PCTLStateFormula<T> {
class ProbabilisticOperator : public mrmc::formula::PCTLStateFormula<T> {
public:
/*!
* Empty constructor
*/
ProbabilisticOperator() {
upper = mrmc::utility::constGetZero(upper);
lower = mrmc::utility::constGetZero(lower);
pathFormula = NULL;
// TODO Auto-generated constructor stub
}
/*!
* Constructor
*
* @param lowerBound The lower bound for the probability
* @param upperBound The upper bound for the probability
* @param pathFormula The child node (can be omitted, is then set to NULL)
* @param bound The expected value for path formulas
* @param pathFormula The child node
*/
ProbabilisticOperator(T lowerBound, T upperBound, PCTLPathFormula<T>* pathFormula=NULL) {
this->lower = lowerBound;
this->upper = upperBound;
this->pathFormula = pathFormula;
ProbabilisticOperator(T bound, PCTLPathFormula<T>& pathFormula) {
this->bound = bound;
this->pathFormula = &pathFormula;
}
/*!
@ -65,9 +66,7 @@ public:
* (this behavior can be prevented by setting them to NULL before deletion)
*/
virtual ~ProbabilisticOperator() {
if (pathFormula != NULL) {
delete pathFormula;
}
// TODO Auto-generated destructor stub
}
/*!
@ -78,17 +77,10 @@ public:
}
/*!
* @returns the lower bound for the probability
*/
const T& getLowerBound() const {
return lower;
}
/*!
* @returns the upper bound for the probability
* @returns the bound for the probability
*/
const T& getUpperBound() const {
return upper;
const T& getBound() const {
return bound;
}
/*!
@ -101,29 +93,12 @@ public:
}
/*!
* Sets the interval in which the probability that the path formula holds may lie.
* Sets the expected probability that the path formula holds.
*
* @param lowerBound The lower bound for the probability
* @param upperBound The upper bound for the probability
* @param bound The bound for the probability
*/
void setInterval(T lowerBound, T upperBound) {
this->lower = lowerBound;
this->upper = upperBound;
}
/*!
* @returns a string representation of the formula
*/
virtual std::string toString() const {
std::string result = "(";
result += " P[";
result += lower;
result += ";";
result += upper;
result += "] ";
result += pathFormula->toString();
result += ")";
return result;
void setBound(T bound) {
this->bound = bound;
}
/*!
@ -131,11 +106,11 @@ public:
*
* Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
*
* @returns a new AND-object that is identical the called object.
* @returns a new ProbabilisticOperator-object that is identical to the called object.
*/
virtual PCTLStateFormula<T>* clone() const {
ProbabilisticOperator<T>* result = new ProbabilisticOperator<T>();
result->setInterval(lower, upper);
result->setBound(bound);
if (pathFormula != NULL) {
result->setPathFormula(pathFormula->clone());
}
@ -146,23 +121,31 @@ public:
* Calls the model checker to check this formula.
* Needed to infer the correct type of formula class.
*
* @note This function should only be called in a generic check function of a model checker class. For other uses,
* the methods of the model checker should be used.
* @note This function should only be called in a generic check function of a model checker
* class. For other uses, the methods of the model checker should be used.
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
* @returns A bit vector indicating all states that satisfy the formula represented by the
* called object.
*/
virtual mrmc::storage::BitVector *check(const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkProbabilisticOperator(this);
virtual mrmc::storage::BitVector *check(
const mrmc::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkProbabilisticOperator(*this);
}
/*!
* Returns a string representation of this PCTLStateFormula
*
* @returns a string representation of this PCTLStateFormula
*/
virtual std::string toString() const {
// TODO
return "";
}
private:
T lower;
T upper;
T bound;
PCTLPathFormula<T>* pathFormula;
};
} //namespace formula
} //namespace mrmc
} /* namespace formula */
} /* namespace mrmc */
#endif /* PROBABILISTICOPERATOR_H_ */

8
src/modelChecker/DtmcPrctlModelChecker.cpp

@ -1,8 +0,0 @@
/*
* DtmcPrctlModelChecker.cpp
*
* Created on: 22.10.2012
* Author: Thomas Heinemann
*/
#include "DtmcPrctlModelChecker.h"

27
src/modelChecker/DtmcPrctlModelChecker.h

@ -26,14 +26,7 @@ class DtmcPrctlModelChecker;
#include "src/formula/PCTLPathFormula.h"
#include "src/formula/PCTLStateFormula.h"
#include "src/formula/And.h"
#include "src/formula/AP.h"
#include "src/formula/BoundedUntil.h"
#include "src/formula/Next.h"
#include "src/formula/Not.h"
#include "src/formula/Or.h"
#include "src/formula/ProbabilisticOperator.h"
#include "src/formula/Until.h"
#include "src/formula/Formulas.h"
#include "src/models/Dtmc.h"
#include "src/storage/BitVector.h"
@ -69,7 +62,7 @@ public:
*
* @param modelChecker The model checker that is copied.
*/
explicit DtmcPrctlModelChecker(mrmc::modelChecker::DtmcPrctlModelChecker<T>* modelChecker) {
explicit DtmcPrctlModelChecker(const mrmc::modelChecker::DtmcPrctlModelChecker<T>* modelChecker) {
this->model = new mrmc::models::Dtmc<T>(modelChecker->getModel());
}
@ -163,12 +156,24 @@ public:
}
/*!
* The check method for a state formula with a probabilistic operator node as root in its formula tree
* The check method for a state formula with a probabilistic operator node as root in its
* formula tree
*
* @param formula The state formula to check
* @returns The set of states satisfying the formula, represented by a bit vector
*/
virtual mrmc::storage::BitVector* checkProbabilisticOperator(const mrmc::formula::ProbabilisticOperator<T>& formula) const = 0;
virtual mrmc::storage::BitVector* checkProbabilisticOperator(
const mrmc::formula::ProbabilisticOperator<T>& formula) const = 0;
/*!
* The check method for a state formula with a probabilistic interval operator node as root in
* its formula tree
*
* @param formula The state formula to check
* @returns The set of states satisfying the formula, represented by a bit vector
*/
virtual mrmc::storage::BitVector* checkProbabilisticIntervalOperator(
const mrmc::formula::ProbabilisticIntervalOperator<T>& formula) const = 0;
/*!
* The check method for a path formula; Will infer the actual type of formula and delegate it

267
src/modelChecker/EigenDtmcPrctlModelChecker.h

@ -0,0 +1,267 @@
/*
* EigenDtmcPrctlModelChecker.h
*
* Created on: 07.12.2012
* Author:
*/
#ifndef EIGENDTMCPRCTLMODELCHECKER_H_
#define EIGENDTMCPRCTLMODELCHECKER_H_
#include "src/utility/vector.h"
#include "src/models/Dtmc.h"
#include "src/modelChecker/DtmcPrctlModelChecker.h"
#include "src/solver/GraphAnalyzer.h"
#include "src/utility/const_templates.h"
#include "src/exceptions/NoConvergence.h"
#include "Eigen/Sparse"
#include "Eigen/src/IterativeLinearSolvers/BiCGSTAB.h"
#include "gmm/gmm_matrix.h"
#include "gmm/gmm_iter_solvers.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
extern log4cplus::Logger logger;
namespace mrmc {
namespace modelChecker {
/*
* A model checking engine that makes use of the eigen backend.
*/
template <class Type>
class EigenDtmcPrctlModelChecker : public DtmcPrctlModelChecker<Type> {
public:
explicit EigenDtmcPrctlModelChecker(mrmc::models::Dtmc<Type>& dtmc) : DtmcPrctlModelChecker<Type>(dtmc) { }
virtual ~EigenDtmcPrctlModelChecker() { }
virtual mrmc::storage::BitVector* checkProbabilisticOperator(const mrmc::formula::ProbabilisticOperator<Type>& formula) const {
std::vector<Type>* probabilisticResult = this->checkPathFormula(formula.getPathFormula());
mrmc::storage::BitVector* result = new mrmc::storage::BitVector(this->getModel().getNumberOfStates());
Type bound = formula.getBound();
for (uint_fast64_t i = 0; i < this->getModel().getNumberOfStates(); ++i) {
if ((*probabilisticResult)[i] == bound) result->set(i, true);
}
delete probabilisticResult;
return result;
}
virtual mrmc::storage::BitVector* checkProbabilisticIntervalOperator(const mrmc::formula::ProbabilisticIntervalOperator<Type>& formula) const {
std::vector<Type>* probabilisticResult = this->checkPathFormula(formula.getPathFormula());
mrmc::storage::BitVector* result = new mrmc::storage::BitVector(this->getModel().getNumberOfStates());
Type lower = formula.getLowerBound();
Type upper = formula.getUpperBound();
for (uint_fast64_t i = 0; i < this->getModel().getNumberOfStates(); ++i) {
if ((*probabilisticResult)[i] >= lower && (*probabilisticResult)[i] <= upper) result->set(i, true);
}
delete probabilisticResult;
return result;
}
virtual std::vector<Type>* checkBoundedUntil(const mrmc::formula::BoundedUntil<Type>& formula) const {
// First, we need to compute the states that satisfy the sub-formulas of the until-formula.
mrmc::storage::BitVector* leftStates = this->checkStateFormula(formula.getLeft());
mrmc::storage::BitVector* rightStates = this->checkStateFormula(formula.getRight());
// Copy the matrix before we make any changes.
mrmc::storage::SquareSparseMatrix<Type> tmpMatrix(*this->getModel().getTransitionProbabilityMatrix());
// Make all rows absorbing that violate both sub-formulas or satisfy the second sub-formula.
tmpMatrix.makeRowsAbsorbing((~*leftStates & *rightStates) | *rightStates);
// Transform the transition probability matrix to the eigen format to use its arithmetic.
Eigen::SparseMatrix<Type, 1, int_fast32_t>* eigenMatrix = tmpMatrix.toEigenSparseMatrix();
// Create the vector with which to multiply.
uint_fast64_t stateCount = this->getModel().getNumberOfStates();
typedef Eigen::Matrix<Type, -1, 1, 0, -1, 1> VectorType;
typedef Eigen::Map<VectorType> MapType;
std::vector<Type>* result = new std::vector<Type>(stateCount);
// Dummy Type variable for const templates
Type dummy;
mrmc::utility::setVectorValues(result, *rightStates, mrmc::utility::constGetOne(dummy));
Type *p = &((*result)[0]); // get the address storing the data for result
MapType vectorMap(p, result->size()); // vectorMap shares data
// Now perform matrix-vector multiplication as long as we meet the bound of the formula.
for (uint_fast64_t i = 0, bound = formula.getBound(); i < bound; ++i) {
vectorMap = (*eigenMatrix) * vectorMap;
}
// Delete intermediate results.
delete leftStates;
delete rightStates;
delete eigenMatrix;
return result;
}
virtual std::vector<Type>* checkNext(const mrmc::formula::Next<Type>& formula) const {
// First, we need to compute the states that satisfy the sub-formula of the next-formula.
mrmc::storage::BitVector* nextStates = this->checkStateFormula(formula.getChild());
// Transform the transition probability matrix to the gmm++ format to use its arithmetic.
Eigen::SparseMatrix<Type, 1, int_fast32_t>* eigenMatrix = this->getModel().getTransitionProbabilityMatrix()->toEigenSparseMatrix();
// Create the vector with which to multiply and initialize it correctly.
std::vector<Type> x(this->getModel().getNumberOfStates());
Type dummy;
mrmc::utility::setVectorValues(&x, *nextStates, mrmc::utility::constGetOne(dummy));
// Delete not needed next states bit vector.
delete nextStates;
typedef Eigen::Matrix<Type, -1, 1, 0, -1, 1> VectorType;
typedef Eigen::Map<VectorType> MapType;
Type *px = &(x[0]); // get the address storing the data for x
MapType vectorX(px, x.size()); // vectorX shares data
// Create resulting vector.
std::vector<Type>* result = new std::vector<Type>(this->getModel().getNumberOfStates());
Type *pr = &((*result)[0]); // get the address storing the data for result
MapType vectorResult(px, result->size()); // vectorResult shares data
// Perform the actual computation.
vectorResult = (*eigenMatrix) * vectorX;
// Delete temporary matrix and return result.
delete eigenMatrix;
return result;
}
virtual std::vector<Type>* checkUntil(const mrmc::formula::Until<Type>& formula) const {
// First, we need to compute the states that satisfy the sub-formulas of the until-formula.
mrmc::storage::BitVector* leftStates = this->checkStateFormula(formula.getLeft());
mrmc::storage::BitVector* rightStates = this->checkStateFormula(formula.getRight());
// Then, we need to identify the states which have to be taken out of the matrix, i.e.
// all states that have probability 0 and 1 of satisfying the until-formula.
mrmc::storage::BitVector notExistsPhiUntilPsiStates(this->getModel().getNumberOfStates());
mrmc::storage::BitVector alwaysPhiUntilPsiStates(this->getModel().getNumberOfStates());
mrmc::solver::GraphAnalyzer::getPhiUntilPsiStates<double>(this->getModel(), *leftStates, *rightStates, &notExistsPhiUntilPsiStates, &alwaysPhiUntilPsiStates);
notExistsPhiUntilPsiStates.complement();
delete leftStates;
delete rightStates;
LOG4CPLUS_INFO(logger, "Found " << notExistsPhiUntilPsiStates.getNumberOfSetBits() << " 'no' states.");
LOG4CPLUS_INFO(logger, "Found " << alwaysPhiUntilPsiStates.getNumberOfSetBits() << " 'yes' states.");
mrmc::storage::BitVector maybeStates = ~(notExistsPhiUntilPsiStates | alwaysPhiUntilPsiStates);
LOG4CPLUS_INFO(logger, "Found " << maybeStates.getNumberOfSetBits() << " 'maybe' states.");
// Create resulting vector and set values accordingly.
uint_fast64_t stateCount = this->getModel().getNumberOfStates();
std::vector<Type>* result = new std::vector<Type>(stateCount);
// Only try to solve system if there are states for which the probability is unknown.
if (maybeStates.getNumberOfSetBits() > 0) {
typedef Eigen::Matrix<Type, -1, 1, 0, -1, 1> VectorType;
typedef Eigen::Map<VectorType> MapType;
// Now we can eliminate the rows and columns from the original transition probability matrix.
mrmc::storage::SquareSparseMatrix<double>* submatrix = this->getModel().getTransitionProbabilityMatrix()->getSubmatrix(maybeStates);
// Converting the matrix to the form needed for the equation system. That is, we go from
// x = A*x + b to (I-A)x = b.
submatrix->convertToEquationSystem();
// Transform the submatric matrix to the eigen format to use its solvers
Eigen::SparseMatrix<Type, 1, int_fast32_t>* eigenSubMatrix = submatrix->toEigenSparseMatrix();
// Initialize the x vector with 0.5 for each element. This is the initial guess for
// the iterative solvers. It should be safe as for all 'maybe' states we know that the
// probability is strictly larger than 0.
std::vector<Type> x(maybeStates.getNumberOfSetBits(), Type(0.5));
// Map for x
Type *px = &(x[0]); // get the address storing the data for x
MapType vectorX(px, x.size()); // vectorX shares data
// Prepare the right-hand side of the equation system. For entry i this corresponds to
// the accumulated probability of going from state i to some 'yes' state.
std::vector<double> b(maybeStates.getNumberOfSetBits());
Type *pb = &(b[0]); // get the address storing the data for b
MapType vectorB(pb, b.size()); // vectorB shares data
this->getModel().getTransitionProbabilityMatrix()->getConstrainedRowCountVector(maybeStates, alwaysPhiUntilPsiStates, &x);
Eigen::BiCGSTAB<Eigen::SparseMatrix<Type, 1, int_fast32_t>> solver;
solver.compute(*eigenSubMatrix);
if(solver.info()!= Eigen::ComputationInfo::Success) {
// decomposition failed
LOG4CPLUS_ERROR(logger, "Decomposition of Submatrix failed!");
}
// Now do the actual solving.
LOG4CPLUS_INFO(logger, "Starting iterative solver.");
solver.setTolerance(0.000001);
bool hasConverged = false;
int turns = 6;
while (!hasConverged) {
vectorX = solver.solve(vectorB);
hasConverged = (solver.info() != Eigen::ComputationInfo::NoConvergence) || (turns <= 0);
if (!hasConverged) {
LOG4CPLUS_INFO(logger, "EigenDtmcPrctlModelChecker did not converge with " << solver.iterations() << " of max. " << solver.maxIterations() << "Iterations, restarting ");
solver.setMaxIterations(solver.maxIterations() * 2);
}
--turns;
}
if(solver.info() == Eigen::ComputationInfo::InvalidInput) {
// solving failed
LOG4CPLUS_ERROR(logger, "Solving of Submatrix failed: InvalidInput");
} else if(solver.info() == Eigen::ComputationInfo::NoConvergence) {
// NoConvergence
throw mrmc::exceptions::NoConvergence("Solving of Submatrix with Eigen failed", solver.iterations(), solver.maxIterations());
} else if(solver.info() == Eigen::ComputationInfo::NumericalIssue) {
// NumericalIssue
LOG4CPLUS_ERROR(logger, "Solving of Submatrix failed: NumericalIssue");
} else if(solver.info() == Eigen::ComputationInfo::Success) {
// solving Success
LOG4CPLUS_INFO(logger, "Solving of Submatrix succeeded: Success");
}
// Set values of resulting vector according to result.
mrmc::utility::setVectorValues<Type>(result, maybeStates, x);
// Delete temporary matrix.
delete eigenSubMatrix;
}
// Dummy Type variable for const templates
Type dummy;
mrmc::utility::setVectorValues<Type>(result, notExistsPhiUntilPsiStates, mrmc::utility::constGetZero(dummy));
mrmc::utility::setVectorValues<Type>(result, alwaysPhiUntilPsiStates, mrmc::utility::constGetOne(dummy));
return result;
}
};
} //namespace modelChecker
} //namespace mrmc
#endif /* EIGENDTMCPRCTLMODELCHECKER_H_ */

5
src/modelChecker/GmmxxDtmcPrctlModelChecker.h

@ -38,6 +38,11 @@ public:
virtual ~GmmxxDtmcPrctlModelChecker() { }
virtual mrmc::storage::BitVector* checkProbabilisticOperator(const mrmc::formula::ProbabilisticOperator<Type>& formula) const {
//FIXME: Implementation needed
return NULL;
}
virtual mrmc::storage::BitVector* checkProbabilisticIntervalOperator(const mrmc::formula::ProbabilisticIntervalOperator<Type>& formula) const {
std::vector<Type>* probabilisticResult = this->checkPathFormula(formula.getPathFormula());
mrmc::storage::BitVector* result = new mrmc::storage::BitVector(this->getModel().getNumberOfStates());

30
src/models/AtomicPropositionsLabeling.h

@ -33,10 +33,10 @@ public:
* @param stateCount The number of states of the model.
* @param apCountMax The number of atomic propositions.
*/
AtomicPropositionsLabeling(const uint_fast32_t stateCount, const uint_fast32_t apCountMax)
AtomicPropositionsLabeling(const uint_fast64_t stateCount, const uint_fast64_t apCountMax)
: stateCount(stateCount), apCountMax(apCountMax), apsCurrent(0) {
this->singleLabelings = new mrmc::storage::BitVector*[apCountMax];
for (uint_fast32_t i = 0; i < apCountMax; ++i) {
for (uint_fast64_t i = 0; i < apCountMax; ++i) {
this->singleLabelings[i] = new mrmc::storage::BitVector(stateCount);
}
}
@ -53,7 +53,7 @@ public:
apsCurrent(atomicPropositionsLabeling.apsCurrent),
nameToLabelingMap(atomicPropositionsLabeling.nameToLabelingMap) {
this->singleLabelings = new mrmc::storage::BitVector*[apCountMax];
for (uint_fast32_t i = 0; i < apCountMax; ++i) {
for (uint_fast64_t i = 0; i < apCountMax; ++i) {
this->singleLabelings[i] = new mrmc::storage::BitVector(*atomicPropositionsLabeling.singleLabelings[i]);
}
}
@ -64,7 +64,7 @@ public:
*/
virtual ~AtomicPropositionsLabeling() {
// delete all the single atomic proposition labelings in the map
for (uint_fast32_t i = 0; i < apCountMax; ++i) {
for (uint_fast64_t i = 0; i < apCountMax; ++i) {
delete this->singleLabelings[i];
this->singleLabelings[i] = NULL;
}
@ -79,7 +79,7 @@ public:
* @param ap The name of the atomic proposition to add.
* @return The index of the new proposition.
*/
uint_fast32_t addAtomicProposition(std::string ap) {
uint_fast64_t addAtomicProposition(std::string ap) {
if (nameToLabelingMap.count(ap) != 0) {
throw std::out_of_range("Atomic Proposition already exists.");
}
@ -89,7 +89,7 @@ public:
}
nameToLabelingMap[ap] = apsCurrent;
uint_fast32_t returnValue = apsCurrent++;
uint_fast64_t returnValue = apsCurrent++;
return returnValue;
}
@ -107,7 +107,7 @@ public:
* @param ap The name of the atomic proposition.
* @param state The index of the state to label.
*/
void addAtomicPropositionToState(std::string ap, const uint_fast32_t state) {
void addAtomicPropositionToState(std::string ap, const uint_fast64_t state) {
if (nameToLabelingMap.count(ap) == 0) {
throw std::out_of_range("Atomic Proposition '" + ap + "' unknown.");
}
@ -122,7 +122,7 @@ public:
* @param state The index of a state
* @returns The list of propositions for the given state
*/
std::set<std::string> getPropositionsForState(uint_fast32_t state) {
std::set<std::string> getPropositionsForState(uint_fast64_t state) {
if (state >= stateCount) {
throw std::out_of_range("State index out of range.");
}
@ -144,7 +144,7 @@ public:
* @return True if the node is labeled with the atomic proposition, false
* otherwise.
*/
bool stateHasAtomicProposition(std::string ap, const uint_fast32_t state) {
bool stateHasAtomicProposition(std::string ap, const uint_fast64_t state) {
return this->singleLabelings[nameToLabelingMap[ap]]->get(state);
}
@ -153,7 +153,7 @@ public:
* the initialization).
* @return The number of atomic propositions.
*/
uint_fast32_t getNumberOfAtomicPropositions() {
uint_fast64_t getNumberOfAtomicPropositions() {
return apCountMax;
}
@ -174,7 +174,7 @@ public:
uint_fast64_t getSizeInMemory() {
uint_fast64_t size = sizeof(*this);
// Add sizes of all single labelings.
for (uint_fast32_t i = 0; i < apCountMax; i++) {
for (uint_fast64_t i = 0; i < apCountMax; i++) {
size += this->singleLabelings[i]->getSizeInMemory();
}
return size;
@ -197,24 +197,24 @@ public:
private:
/*! The number of states whose labels are to be stored by this object. */
uint_fast32_t stateCount;
uint_fast64_t stateCount;
/*! The number of different atomic propositions this object can store. */
uint_fast32_t apCountMax;
uint_fast64_t apCountMax;
/*!
* The number of different atomic propositions currently associated with
* this labeling. Used to prevent too many atomic propositions from being
* added to this object.
*/
uint_fast32_t apsCurrent;
uint_fast64_t apsCurrent;
/*!
* Associates a name of an atomic proposition to its corresponding labeling
* by mapping the name to a specific index in the array of all
* individual labelings.
*/
std::unordered_map<std::string, uint_fast32_t> nameToLabelingMap;
std::unordered_map<std::string, uint_fast64_t> nameToLabelingMap;
/*!
* Stores all individual labelings. To find the labeling associated with

2
src/models/Dtmc.h

@ -102,7 +102,7 @@ public:
/*!
*
*/
std::set<std::string> getPropositionsForState(uint_fast32_t state) {
std::set<std::string> getPropositionsForState(uint_fast64_t state) {
return stateLabeling->getPropositionsForState(state);
}

45
src/mrmc.cpp

@ -12,6 +12,7 @@
* Description: Central part of the application containing the main() Method
*/
#include "src/utility/osDetection.h"
#include <iostream>
#include <cstdio>
#include <sstream>
@ -21,6 +22,7 @@
#include "src/models/Dtmc.h"
#include "src/storage/SquareSparseMatrix.h"
#include "src/models/AtomicPropositionsLabeling.h"
#include "src/modelChecker/EigenDtmcPrctlModelChecker.h"
#include "src/modelChecker/GmmxxDtmcPrctlModelChecker.h"
#include "src/parser/readLabFile.h"
#include "src/parser/readTraFile.h"
@ -28,6 +30,7 @@
#include "src/solver/GraphAnalyzer.h"
#include "src/utility/settings.h"
#include "src/formula/Formulas.h"
#include "src/exceptions/NoConvergence.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
@ -105,14 +108,48 @@ int main(const int argc, const char* argv[]) {
dtmc.printModelInformationToStream(std::cout);
// Uncomment this if you want to see the first model checking procedure in action. :)
/*
mrmc::modelChecker::GmmxxDtmcPrctlModelChecker<double> mc(dtmc);
mrmc::modelChecker::EigenDtmcPrctlModelChecker<double> mc(dtmc);
mrmc::formula::AP<double>* trueFormula = new mrmc::formula::AP<double>(std::string("true"));
mrmc::formula::AP<double>* ap = new mrmc::formula::AP<double>(std::string("observe0Greater1"));
mrmc::formula::Until<double>* until = new mrmc::formula::Until<double>(trueFormula, ap);
mc.checkPathFormula(*until);
std::vector<double>* eigenResult = NULL;
try {
eigenResult = mc.checkPathFormula(*until);
} catch (mrmc::exceptions::NoConvergence& nce) {
// solver did not converge
LOG4CPLUS_ERROR(logger, "EigenDtmcPrctlModelChecker did not converge with " << nce.getIterationCount() << " of max. " << nce.getMaxIterationCount() << "Iterations!");
return -1;
}
delete until;
*/
mrmc::modelChecker::GmmxxDtmcPrctlModelChecker<double> mcG(dtmc);
mrmc::formula::AP<double>* trueFormulaG = new mrmc::formula::AP<double>(std::string("true"));
mrmc::formula::AP<double>* apG = new mrmc::formula::AP<double>(std::string("observe0Greater1"));
mrmc::formula::Until<double>* untilG = new mrmc::formula::Until<double>(trueFormulaG, apG);
std::vector<double>* gmmResult = mcG.checkPathFormula(*untilG);
delete untilG;
if (eigenResult->size() != gmmResult->size()) {
LOG4CPLUS_ERROR(logger, "Warning: Eigen and GMM produced different results (Eigen: " << eigenResult->size() << ", Gmm: " << gmmResult->size() << ") in size!");
} else {
LOG4CPLUS_INFO(logger, "Testing for different entries");
for (int i = 0; i < eigenResult->size(); ++i) {
if (std::abs((eigenResult->at(i) - gmmResult->at(i))) > 0) {
LOG4CPLUS_ERROR(logger, "Warning: Eigen and GMM produced different results in entry " << i << " (Eigen: " << eigenResult->at(i) << ", Gmm: " << gmmResult->at(i) << ")!");
}
if (eigenResult->at(i) != 0.0) {
LOG4CPLUS_INFO(logger, "Non zero entry " << eigenResult->at(i) << " at " << i);
}
}
}
/*
LOG4CPLUS_INFO(logger, "Result: ");
LOG4CPLUS_INFO(logger, "Entry : EigenResult at Entry : GmmResult at Entry");
for (int i = 0; i < eigenResult->size(); ++i) {
LOG4CPLUS_INFO(logger, i << " : " << eigenResult->at(i) << " : " << gmmResult->at(i));
}*/
if (s != nullptr) {
delete s;

6
src/parser/parser.cpp

@ -1,15 +1,13 @@
#include "src/parser/parser.h"
#if defined LINUX || defined MACOSX
#include <sys/mman.h>
# include <sys/mman.h>
# include <unistd.h>
#elif defined WINDOWS
#endif
#include <sys/stat.h>
#include <fcntl.h>
//#if defined MACOSX
#include <unistd.h>
//#endif
#include <errno.h>
#include <iostream>
#include <cstring>

5
src/parser/parser.h

@ -11,8 +11,10 @@
#include "src/utility/osDetection.h"
#if defined LINUX || defined MACOSX
#include <sys/mman.h>
# include <sys/mman.h>
#elif defined WINDOWS
# include <Windows.h>
# include <winnt.h>
#endif
#include <sys/stat.h>
@ -20,6 +22,7 @@
#include <errno.h>
#include <iostream>
#include <boost/integer/integer_mask.hpp>
#include "src/exceptions/file_IO_exception.h"
#include "src/exceptions/wrong_file_format.h"

6
src/parser/readLabFile.cpp

@ -57,7 +57,11 @@ LabParser::LabParser(uint_fast64_t node_count, const char * filename)
/*
* first run: obtain number of propositions
*/
#ifdef WINDOWS
char separator[] = " \r\n\t";
#else
char separator[] = " \n\t";
#endif
bool foundDecl = false, foundEnd = false;
uint_fast32_t proposition_count = 0;
{
@ -159,7 +163,7 @@ LabParser::LabParser(uint_fast64_t node_count, const char * filename)
/*
* now parse node label assignments
*/
uint_fast32_t node;
uint_fast64_t node;
char proposition[128];
size_t cnt;
/*

10
src/parser/readTraFile.cpp

@ -48,9 +48,9 @@ namespace parser{
* @param buf Data to scan. Is expected to be some char array.
* @param maxnode Is set to highest id of all nodes.
*/
uint_fast32_t TraParser::firstPass(char* buf, uint_fast32_t &maxnode)
uint_fast64_t TraParser::firstPass(char* buf, uint_fast64_t &maxnode)
{
uint_fast32_t non_zero = 0;
uint_fast64_t non_zero = 0;
/*
* check file header and extract number of transitions
@ -74,7 +74,7 @@ uint_fast32_t TraParser::firstPass(char* buf, uint_fast32_t &maxnode)
/*
* check all transitions for non-zero diagonal entrys
*/
uint_fast32_t row, col;
uint_fast64_t row, col;
double val;
maxnode = 0;
char* tmp;
@ -134,8 +134,8 @@ TraParser::TraParser(const char * filename)
/*
* perform first pass, i.e. count entries that are not zero and not on the diagonal
*/
uint_fast32_t maxnode;
uint_fast32_t non_zero = this->firstPass(file.data, maxnode);
uint_fast64_t maxnode;
uint_fast64_t non_zero = this->firstPass(file.data, maxnode);
/*
* if first pass returned zero, the file format was wrong
*/

2
src/parser/readTraFile.h

@ -30,7 +30,7 @@ class TraParser : Parser
private:
std::shared_ptr<mrmc::storage::SquareSparseMatrix<double>> matrix;
uint_fast32_t firstPass(char* buf, uint_fast32_t &maxnode);
uint_fast64_t firstPass(char* buf, uint_fast64_t &maxnode);
};

5
src/storage/BitVector.h

@ -10,6 +10,7 @@
#include "src/exceptions/invalid_argument.h"
#include "src/exceptions/out_of_range.h"
#include "src/utility/osDetection.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
@ -394,6 +395,10 @@ public:
// Check if we are using g++ or clang++ and, if so, use the built-in function
#if (defined (__GNUG__) || defined(__clang__))
result += __builtin_popcountll(this->bucketArray[i]);
#elif defined WINDOWS
#include <nmmintrin.h>
// if the target machine does not support SSE4, this will fail.
result += _mm_popcnt_u64(this->bucketArray[i]);
#else
uint_fast32_t cnt;
uint_fast64_t bitset = this->bucketArray[i];

4
src/storage/SquareSparseMatrix.h

@ -509,7 +509,7 @@ public:
rowEnd = rowIndications[row + 1];
while (rowStart < rowEnd) {
if (valueStorage[rowStart] == 0) zeroCount++;
tripletList.push_back(IntTriplet(row, columnIndications[rowStart], valueStorage[rowStart]));
tripletList.push_back(IntTriplet(static_cast<int_fast32_t>(row), static_cast<int_fast32_t>(columnIndications[rowStart]), valueStorage[rowStart]));
++rowStart;
}
}
@ -517,7 +517,7 @@ public:
// Then add the elements on the diagonal.
for (uint_fast64_t i = 0; i < rowCount; ++i) {
if (diagonalStorage[i] == 0) zeroCount++;
tripletList.push_back(IntTriplet(i, i, diagonalStorage[i]));
tripletList.push_back(IntTriplet(static_cast<int_fast32_t>(i), static_cast<int_fast32_t>(i), diagonalStorage[i]));
}
// Let Eigen create a matrix from the given list of triplets.

13
src/utility/osDetection.h

@ -1,12 +1,15 @@
#pragma once
#if defined __linux__ || defined __linux
#define LINUX
# define LINUX
#elif defined TARGET_OS_MAC || defined __apple__ || defined __APPLE__
#define MACOSX
#define _DARWIN_USE_64_BIT_INODE
# define MACOSX
# define _DARWIN_USE_64_BIT_INODE
#elif defined _WIN32 || defined _WIN64
#define WINDOWS
# define WINDOWS
# define NOMINMAX
# include <Windows.h>
# include <winnt.h>
#else
#error Could not detect Operating System
# error Could not detect Operating System
#endif

9
src/utility/vector.h

@ -8,6 +8,8 @@
#ifndef VECTOR_H_
#define VECTOR_H_
#include "Eigen/src/Core/Matrix.h"
namespace mrmc {
namespace utility {
@ -27,6 +29,13 @@ void setVectorValues(std::vector<T>* vector, const mrmc::storage::BitVector& pos
}
}
template<class T>
void setVectorValues(Eigen::Matrix<T, -1, 1, 0, -1, 1>* eigenVector, const mrmc::storage::BitVector& positions, T value) {
for (auto position : positions) {
(*eigenVector)(position, 0) = value;
}
}
} //namespace utility
} //namespace mrmc

Loading…
Cancel
Save