Browse Source

Refactored some classes into templates

Former-commit-id: b495cf93d4
tempestpy_adaptions
Mavo 9 years ago
parent
commit
4343b5b980
  1. 3
      src/builder/ExplicitDFTModelBuilder.cpp
  2. 21
      src/parser/DFTGalileoParser.cpp
  3. 10
      src/parser/DFTGalileoParser.h
  4. 4
      src/storage/dft/DFT.h
  5. 33
      src/storage/dft/DFTBuilder.cpp
  6. 7
      src/storage/dft/DFTBuilder.h
  7. 4
      src/storage/dft/DFTState.cpp
  8. 3
      src/storage/dft/DFTState.h
  9. 2
      src/storm-dyftee.cpp

3
src/builder/ExplicitDFTModelBuilder.cpp

@ -165,8 +165,7 @@ namespace storm {
}
// Explicitly instantiate the class.
template
class ExplicitDFTModelBuilder<double, storm::models::sparse::StandardRewardModel<double>, uint32_t>;
template class ExplicitDFTModelBuilder<double, storm::models::sparse::StandardRewardModel<double>, uint32_t>;
#ifdef STORM_HAVE_CARL
template class ExplicitDFTModelBuilder<double, storm::models::sparse::StandardRewardModel<storm::Interval>, uint32_t>;

21
src/parser/DFTGalileoParser.cpp

@ -10,7 +10,9 @@
namespace storm {
namespace parser {
storm::storage::DFT DFTGalileoParser::parseDFT(const std::string& filename) {
template<typename ValueType>
storm::storage::DFT DFTGalileoParser<ValueType>::parseDFT(const std::string& filename) {
if(readFile(filename)) {
storm::storage::DFT dft = mBuilder.build();
STORM_LOG_DEBUG("Elements:" << std::endl << dft.getElementsString());
@ -20,8 +22,9 @@ namespace storm {
throw storm::exceptions::FileIoException();
}
}
std::string stripQuotsFromName(std::string const& name) {
template<typename ValueType>
std::string DFTGalileoParser<ValueType>::stripQuotsFromName(std::string const& name) {
size_t firstQuots = name.find("\"");
size_t secondQuots = name.find("\"", firstQuots+1);
@ -33,8 +36,9 @@ namespace storm {
return name.substr(firstQuots+1,secondQuots-1);
}
}
bool DFTGalileoParser::readFile(const std::string& filename) {
template<typename ValueType>
bool DFTGalileoParser<ValueType>::readFile(const std::string& filename) {
// constants
std::string topleveltoken = "toplevel";
std::string toplevelId;
@ -108,6 +112,13 @@ namespace storm {
file.close();
return generalSuccess;
}
// Explicitly instantiate the class.
template class DFTGalileoParser<double>;
#ifdef STORM_HAVE_CARL
template class DFTGalileoParser<RationalFunction>;
#endif
}
}

10
src/parser/DFTGalileoParser.h

@ -8,16 +8,18 @@
namespace storm {
namespace parser {
template<typename ValueType>
class DFTGalileoParser {
storm::storage::DFTBuilder mBuilder;
storm::storage::DFTBuilder<ValueType> mBuilder;
public:
storm::storage::DFT parseDFT(std::string const& filename);
private:
bool readFile(std::string const& filename);
};
std::string stripQuotsFromName(std::string const& name);
};
}
}

4
src/storage/dft/DFT.h

@ -131,12 +131,14 @@ namespace storm {
assert(index < nrElements());
return mElements[index];
}
// TODO Matthias: template
std::shared_ptr<DFTBE<double>> getBasicElement(size_t index) const {
assert(mElements[index]->isBasicElement());
return std::static_pointer_cast<DFTBE<double>>(mElements[index]);
}
// TODO Matthias: template
std::vector<std::shared_ptr<DFTBE<double>>> getBasicElements() const {
std::vector<std::shared_ptr<DFTBE<double>>> elements;
for (std::shared_ptr<storm::storage::DFTElement> elem : mElements) {

33
src/storage/dft/DFTBuilder.cpp

@ -12,8 +12,9 @@
namespace storm {
namespace storage {
DFT DFTBuilder::build() {
template<typename ValueType>
DFT 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);
@ -36,8 +37,9 @@ namespace storm {
}
return DFT(elems, mElements[topLevelIdentifier]);
}
unsigned DFTBuilder::computeRank(std::shared_ptr<DFTElement> const& elem) {
template<typename ValueType>
unsigned DFTBuilder<ValueType>::computeRank(std::shared_ptr<DFTElement> const& elem) {
if(elem->rank() == -1) {
if(elem->nrChildren() == 0) {
elem->setRank(0);
@ -58,8 +60,9 @@ namespace storm {
return elem->rank();
}
bool DFTBuilder::addStandardGate(std::string const& name, std::vector<std::string> const& children, DFTElementTypes tp) {
template<typename ValueType>
bool DFTBuilder<ValueType>::addStandardGate(std::string const& name, std::vector<std::string> const& children, DFTElementTypes tp) {
assert(children.size() > 0);
if(mElements.count(name) != 0) {
// Element with that name already exists.
@ -97,9 +100,9 @@ namespace storm {
mChildNames[element] = children;
return true;
}
void DFTBuilder::topoVisit(std::shared_ptr<DFTElement> const& n, std::map<std::shared_ptr<DFTElement>, topoSortColour>& visited, std::vector<std::shared_ptr<DFTElement>>& L) {
template<typename ValueType>
void DFTBuilder<ValueType>::topoVisit(std::shared_ptr<DFTElement> const& n, std::map<std::shared_ptr<DFTElement>, topoSortColour>& visited, std::vector<std::shared_ptr<DFTElement>>& L) {
if(visited[n] == topoSortColour::GREY) {
throw storm::exceptions::WrongFormatException("DFT is cyclic");
} else if(visited[n] == topoSortColour::WHITE) {
@ -114,7 +117,8 @@ namespace storm {
}
}
std::vector<std::shared_ptr<DFTElement>> DFTBuilder::topoSort() {
template<typename ValueType>
std::vector<std::shared_ptr<DFTElement>> DFTBuilder<ValueType>::topoSort() {
std::map<std::shared_ptr<DFTElement>, topoSortColour> visited;
for(auto const& e : mElements) {
visited.insert(std::make_pair(e.second, topoSortColour::WHITE));
@ -126,7 +130,14 @@ namespace storm {
}
//std::reverse(L.begin(), L.end());
return L;
}
}
// Explicitly instantiate the class.
template class DFTBuilder<double>;
#ifdef STORM_HAVE_CARL
template class DFTBuilder<RationalFunction>;
#endif
}
}

7
src/storage/dft/DFTBuilder.h

@ -10,7 +10,8 @@
namespace storm {
namespace storage {
class DFT;
template<typename ValueType>
class DFTBuilder {
std::size_t mNextId = 0;
@ -69,7 +70,7 @@ namespace storm {
return true;
}
bool addBasicElement(std::string const& name, double failureRate, double dormancyFactor) {
bool addBasicElement(std::string const& name, ValueType failureRate, ValueType dormancyFactor) {
if(failureRate <= 0.0) {
std::cerr << "Failure rate must be positive." << std::endl;
return false;
@ -80,7 +81,7 @@ namespace storm {
return false;
}
mElements[name] = std::make_shared<DFTBE<double>>(mNextId++, name, failureRate, dormancyFactor);
mElements[name] = std::make_shared<DFTBE<ValueType>>(mNextId++, name, failureRate, dormancyFactor);
return true;
}

4
src/storage/dft/DFTState.cpp

@ -65,8 +65,8 @@ namespace storm {
}
}
std::pair<std::shared_ptr<DFTBE<double>>, bool> DFTState::letNextBEFail(size_t index)
// TODO Matthias: template
std::pair<std::shared_ptr<DFTBE<double>>, bool> DFTState::letNextBEFail(size_t index)
{
assert(index < mIsCurrentlyFailableBE.size());
STORM_LOG_TRACE("currently failable: " << getCurrentlyFailableString());

3
src/storage/dft/DFTState.h

@ -105,7 +105,8 @@ namespace storm {
size_t nrFailableBEs() const {
return mIsCurrentlyFailableBE.size();
}
// TODO Matthias: template
std::pair<std::shared_ptr<DFTBE<double>>, bool> letNextBEFail(size_t smallestIndex = 0);
std::string getCurrentlyFailableString() {

2
src/storm-dyftee.cpp

@ -19,7 +19,7 @@ int main(int argc, char** argv) {
logger.getAppender("mainConsoleAppender")->setThreshold(level);
std::cout << "Parsing DFT file..." << std::endl;
storm::parser::DFTGalileoParser parser;
storm::parser::DFTGalileoParser<double> parser;
storm::storage::DFT dft = parser.parseDFT(argv[1]);
std::cout << "Built data structure" << std::endl;

Loading…
Cancel
Save