Browse Source

More refactoring with templates

Former-commit-id: 6b614ed7f3
tempestpy_adaptions
Mavo 9 years ago
parent
commit
7737205149
  1. 4
      src/builder/ExplicitDFTModelBuilder.h
  2. 19
      src/parser/DFTGalileoParser.cpp
  3. 2
      src/parser/DFTGalileoParser.h
  4. 30
      src/storage/dft/DFT.cpp
  5. 15
      src/storage/dft/DFT.h
  6. 4
      src/storage/dft/DFTBuilder.cpp
  7. 3
      src/storage/dft/DFTBuilder.h
  8. 5
      src/storage/dft/DFTState.cpp
  9. 9
      src/storage/dft/DFTState.h
  10. 10
      src/storm-dyftee.cpp

4
src/builder/ExplicitDFTModelBuilder.h

@ -35,12 +35,12 @@ namespace storm {
boost::optional<std::vector<boost::container::flat_set<uint_fast64_t>>> choiceLabeling;
};
storm::storage::DFT const &mDft;
storm::storage::DFT<ValueType> const &mDft;
std::unordered_set<storm::storage::DFTState> mStates;
size_t newIndex = 0;
public:
ExplicitDFTModelBuilder(storm::storage::DFT const &dft) : mDft(dft) {
ExplicitDFTModelBuilder(storm::storage::DFT<ValueType> const &dft) : mDft(dft) {
}

19
src/parser/DFTGalileoParser.cpp

@ -4,6 +4,7 @@
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <src/exceptions/NotImplementedException.h>
#include "../exceptions/FileIoException.h"
#include "../exceptions/NotSupportedException.h"
#include "src/utility/macros.h"
@ -12,9 +13,9 @@ namespace storm {
namespace parser {
template<typename ValueType>
storm::storage::DFT DFTGalileoParser<ValueType>::parseDFT(const std::string& filename) {
storm::storage::DFT<ValueType> DFTGalileoParser<ValueType>::parseDFT(const std::string& filename) {
if(readFile(filename)) {
storm::storage::DFT dft = mBuilder.build();
storm::storage::DFT<ValueType> dft = mBuilder.build();
STORM_LOG_DEBUG("Elements:" << std::endl << dft.getElementsString());
STORM_LOG_DEBUG("Spare Modules:" << std::endl << dft.getSpareModulesString());
return dft;
@ -95,8 +96,18 @@ namespace storm {
} else if(tokens[1] == "wsp" || tokens[1] == "csp") {
success = mBuilder.addSpareElement(name, childNames);
} else if(boost::starts_with(tokens[1], "lambda=")) {
//TODO Matthias: Use ValueType instead of fixed double
success = mBuilder.addBasicElement(name, boost::lexical_cast<double>(tokens[1].substr(7)), boost::lexical_cast<double>(tokens[2].substr(5)));
ValueType failureRate = 0;
ValueType dormancyFactor = 0;
if (std::is_same<ValueType, double>::value) {
failureRate = boost::lexical_cast<double>(tokens[1].substr(7));
dormancyFactor = boost::lexical_cast<double>(tokens[2].substr(5));
} else {
// TODO Matthias: Parse RationalFunction
failureRate;
dormancyFactor;
STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Parsing into rational function not supported.");
}
success = mBuilder.addBasicElement(name, failureRate, dormancyFactor);
} else {
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Type name: " + tokens[1] + " not recognized.");
success = false;

2
src/parser/DFTGalileoParser.h

@ -13,7 +13,7 @@ namespace storm {
class DFTGalileoParser {
storm::storage::DFTBuilder<ValueType> mBuilder;
public:
storm::storage::DFT parseDFT(std::string const& filename);
storm::storage::DFT<ValueType> parseDFT(std::string const& filename);
private:
bool readFile(std::string const& filename);

30
src/storage/dft/DFT.cpp

@ -2,8 +2,9 @@
namespace storm {
namespace storage {
DFT::DFT(std::vector<std::shared_ptr<DFTElement>> const& elements, std::shared_ptr<DFTElement> const& tle) : mElements(elements), mNrOfBEs(0), mNrOfSpares(0)
template<typename ValueType>
DFT<ValueType>::DFT(std::vector<std::shared_ptr<DFTElement>> const& elements, std::shared_ptr<DFTElement> const& tle) : mElements(elements), mNrOfBEs(0), mNrOfSpares(0)
{
assert(elementIndicesCorrect());
@ -60,8 +61,9 @@ namespace storm {
mTopLevelIndex = tle->id();
}
std::string DFT::getElementsString() const {
template<typename ValueType>
std::string DFT<ValueType>::getElementsString() const {
std::stringstream stream;
for (auto const& elem : mElements) {
stream << "[" << elem->id() << "]" << elem->toString() << std::endl;
@ -69,13 +71,15 @@ namespace storm {
return stream.str();
}
std::string DFT::getInfoString() const {
template<typename ValueType>
std::string DFT<ValueType>::getInfoString() const {
std::stringstream stream;
stream << "Top level index: " << mTopLevelIndex << ", Nr BEs" << mNrOfBEs;
return stream.str();
}
std::string DFT::getSpareModulesString() const {
template<typename ValueType>
std::string DFT<ValueType>::getSpareModulesString() const {
std::stringstream stream;
stream << "[" << mElements[mTopLevelIndex]->id() << "] {";
std::vector<size_t>::const_iterator it = mTopModule.begin();
@ -103,7 +107,8 @@ namespace storm {
return stream.str();
}
std::string DFT::getElementsWithStateString(DFTState const& state) const{
template<typename ValueType>
std::string DFT<ValueType>::getElementsWithStateString(DFTState const& state) const{
std::stringstream stream;
for (auto const& elem : mElements) {
stream << "[" << elem->id() << "]";
@ -120,7 +125,8 @@ namespace storm {
return stream.str();
}
std::string DFT::getStateString(DFTState const& state) const{
template<typename ValueType>
std::string DFT<ValueType>::getStateString(DFTState const& state) const{
std::stringstream stream;
stream << "(" << state.getId() << ") ";
for (auto const& elem : mElements) {
@ -134,5 +140,13 @@ namespace storm {
}
return stream.str();
}
// Explicitly instantiate the class.
template class DFT<double>;
#ifdef STORM_HAVE_CARL
template class DFT<RationalFunction>;
#endif
}
}

15
src/storage/dft/DFT.h

@ -26,7 +26,8 @@ namespace storm {
}
}
};
template<typename ValueType>
class DFT {
private:
@ -132,18 +133,16 @@ namespace storm {
return mElements[index];
}
// TODO Matthias: template
std::shared_ptr<DFTBE<double>> getBasicElement(size_t index) const {
std::shared_ptr<DFTBE<ValueType>> getBasicElement(size_t index) const {
assert(mElements[index]->isBasicElement());
return std::static_pointer_cast<DFTBE<double>>(mElements[index]);
return std::static_pointer_cast<DFTBE<ValueType>>(mElements[index]);
}
// TODO Matthias: template
std::vector<std::shared_ptr<DFTBE<double>>> getBasicElements() const {
std::vector<std::shared_ptr<DFTBE<double>>> elements;
std::vector<std::shared_ptr<DFTBE<ValueType>>> getBasicElements() const {
std::vector<std::shared_ptr<DFTBE<ValueType>>> elements;
for (std::shared_ptr<storm::storage::DFTElement> elem : mElements) {
if (elem->isBasicElement()) {
elements.push_back(std::static_pointer_cast<DFTBE<double>>(elem));
elements.push_back(std::static_pointer_cast<DFTBE<ValueType>>(elem));
}
}
return elements;

4
src/storage/dft/DFTBuilder.cpp

@ -14,7 +14,7 @@ namespace storm {
namespace storage {
template<typename ValueType>
DFT DFTBuilder<ValueType>::build() {
DFT<ValueType> DFTBuilder<ValueType>::build() {
for(auto& elem : mChildNames) {
for(auto const& child : elem.second) {
std::shared_ptr<DFTGate> gate = std::static_pointer_cast<DFTGate>(elem.first);
@ -35,7 +35,7 @@ namespace storm {
for(std::shared_ptr<DFTElement> e : elems) {
e->setId(id++);
}
return DFT(elems, mElements[topLevelIdentifier]);
return DFT<ValueType>(elems, mElements[topLevelIdentifier]);
}
template<typename ValueType>

3
src/storage/dft/DFTBuilder.h

@ -9,6 +9,7 @@
namespace storm {
namespace storage {
template<typename ValueType>
class DFT;
template<typename ValueType>
@ -90,7 +91,7 @@ namespace storm {
return mElements.count(tle) > 0;
}
DFT build();
DFT<ValueType> build();
private:

5
src/storage/dft/DFTState.cpp

@ -4,8 +4,9 @@
namespace storm {
namespace storage {
DFTState::DFTState(DFT const& dft, size_t id) : mStatus(dft.stateSize()), mId(id), mDft(dft) {
// TODO Matthias: template
DFTState::DFTState(DFT<double> const& dft, size_t id) : mStatus(dft.stateSize()), mId(id), mDft(dft) {
mInactiveSpares = dft.getSpareIndices();
dft.initializeUses(*this);
dft.initializeActivation(*this);

9
src/storage/dft/DFTState.h

@ -8,7 +8,8 @@
namespace storm {
namespace storage {
template<typename ValueType>
class DFT;
template<typename ValueType>
class DFTBE;
@ -23,10 +24,12 @@ namespace storm {
std::vector<size_t> mIsCurrentlyFailableBE;
std::vector<size_t> mUsedRepresentants;
bool mValid = true;
const DFT& mDft;
// TODO Matthias: template
const DFT<double>& mDft;
public:
DFTState(DFT const& dft, size_t id);
// TODO Matthias: template
DFTState(DFT<double> const& dft, size_t id);
DFTElementState getElementState(size_t id) const;

10
src/storm-dyftee.cpp

@ -5,6 +5,8 @@
#include "modelchecker/results/CheckResult.h"
#include "utility/storm.h"
#define VALUE_TYPE double
/*
* Entry point for the DyFTeE backend.
*/
@ -19,14 +21,14 @@ int main(int argc, char** argv) {
logger.getAppender("mainConsoleAppender")->setThreshold(level);
std::cout << "Parsing DFT file..." << std::endl;
storm::parser::DFTGalileoParser<double> parser;
storm::storage::DFT dft = parser.parseDFT(argv[1]);
storm::parser::DFTGalileoParser<VALUE_TYPE> parser;
storm::storage::DFT<VALUE_TYPE> dft = parser.parseDFT(argv[1]);
std::cout << "Built data structure" << std::endl;
std::cout << "Building CTMC..." << std::endl;
storm::builder::ExplicitDFTModelBuilder<double> builder(dft);
std::shared_ptr<storm::models::sparse::Model<double>> model = builder.buildCTMC();
storm::builder::ExplicitDFTModelBuilder<VALUE_TYPE> builder(dft);
std::shared_ptr<storm::models::sparse::Model<VALUE_TYPE>> model = builder.buildCTMC();
std::cout << "Built CTMC" << std::endl;
std::cout << "Model checking..." << std::endl;

Loading…
Cancel
Save