#include "DFT.h" namespace storm { namespace storage { template DFT::DFT(std::vector> const& elements, std::shared_ptr const& tle) : mElements(elements), mNrOfBEs(0), mNrOfSpares(0) { assert(elementIndicesCorrect()); size_t stateIndex = 0; mUsageInfoBits = storm::utility::math::uint64_log2(mElements.size()-1)+1; for(auto& elem : mElements) { mIdToFailureIndex.push_back(stateIndex); stateIndex += 2; if(elem->isBasicElement()) { ++mNrOfBEs; } else if(elem->isSpareGate()) { ++mNrOfSpares; for(auto const& spareReprs : std::static_pointer_cast(elem)->children()) { if(mActivationIndex.count(spareReprs->id()) == 0) { mActivationIndex[spareReprs->id()] = stateIndex++; } std::set module = {spareReprs->id()}; spareReprs->extendSpareModule(module); std::vector sparesAndBes; for(auto const& modelem : module) { if(mElements[modelem]->isSpareGate() || mElements[modelem]->isBasicElement()) { sparesAndBes.push_back(modelem); } } mSpareModules.insert(std::make_pair(spareReprs->id(), sparesAndBes)); } std::static_pointer_cast(elem)->setUseIndex(stateIndex); mUsageIndex.insert(std::make_pair(elem->id(), stateIndex)); stateIndex += mUsageInfoBits; } } // For the top module, we assume, contrary to [Jun15], that we have all spare gates and basic elements which are not in another module. std::set topModuleSet; // Initialize with all ids. for(auto const& elem : mElements) { if (elem->isBasicElement() || elem->isSpareGate()) { topModuleSet.insert(elem->id()); } } for(auto const& module : mSpareModules) { for(auto const& index : module.second) { topModuleSet.erase(index); } } mTopModule = std::vector(topModuleSet.begin(), topModuleSet.end()); mStateSize = stateIndex; mTopLevelIndex = tle->id(); } template std::string DFT::getElementsString() const { std::stringstream stream; for (auto const& elem : mElements) { stream << "[" << elem->id() << "]" << elem->toString() << std::endl; } return stream.str(); } template std::string DFT::getInfoString() const { std::stringstream stream; stream << "Top level index: " << mTopLevelIndex << ", Nr BEs" << mNrOfBEs; return stream.str(); } template std::string DFT::getSpareModulesString() const { std::stringstream stream; stream << "[" << mElements[mTopLevelIndex]->id() << "] {"; std::vector::const_iterator it = mTopModule.begin(); assert(it != mTopModule.end()); stream << mElements[(*it)]->name(); ++it; while(it != mTopModule.end()) { stream << ", " << mElements[(*it)]->name(); ++it; } stream << "}" << std::endl; for(auto const& spareModule : mSpareModules) { stream << "[" << mElements[spareModule.first]->name() << "] = {"; std::vector::const_iterator it = spareModule.second.begin(); assert(it != spareModule.second.end()); stream << mElements[(*it)]->name(); ++it; while(it != spareModule.second.end()) { stream << ", " << mElements[(*it)]->name(); ++it; } stream << "}" << std::endl; } return stream.str(); } template std::string DFT::getElementsWithStateString(DFTState const& state) const{ std::stringstream stream; for (auto const& elem : mElements) { stream << "[" << elem->id() << "]"; stream << elem->toString(); stream << "\t** " << state.getElementState(elem->id()); if(elem->isSpareGate()) { if(state.isActiveSpare(elem->id())) { stream << " actively"; } stream << " using " << state.uses(elem->id()); } stream << std::endl; } return stream.str(); } template std::string DFT::getStateString(DFTState const& state) const{ std::stringstream stream; stream << "(" << state.getId() << ") "; for (auto const& elem : mElements) { stream << state.getElementStateInt(elem->id()); /*if(elem->isSpareGate()) { if(state.isActiveSpare(elem->id())) { os << " actively"; } os << " using " << state.uses(elem->id()); }*/ } return stream.str(); } // Explicitly instantiate the class. template class DFT; #ifdef STORM_HAVE_CARL template class DFT; #endif } }