Browse Source

Added computation of dynamic behavior vector for DFTs

main
Alexander Bork 6 years ago
parent
commit
bec75813b1
  1. 86
      src/storm-dft/builder/DFTBuilder.cpp
  2. 2
      src/storm-dft/builder/DFTBuilder.h
  3. 5
      src/storm-dft/storage/dft/DFT.cpp
  4. 8
      src/storm-dft/storage/dft/DFT.h

86
src/storm-dft/builder/DFTBuilder.cpp

@ -97,7 +97,7 @@ namespace storm {
}
STORM_LOG_THROW(!mTopLevelIdentifier.empty(), storm::exceptions::WrongFormatException, "No top level element defined.");
storm::storage::DFT<ValueType> dft(elems, mElements[mTopLevelIdentifier]);
storm::storage::DFT<ValueType> dft(elems, mElements[mTopLevelIdentifier], computeHasDynamicBehavior(elems));
// Set layout info
for (auto& elem : mElements) {
@ -135,6 +135,90 @@ namespace storm {
return elem->rank();
}
template<typename ValueType>
std::vector<bool> DFTBuilder<ValueType>::computeHasDynamicBehavior(DFTElementVector elements) {
std::vector<bool> dynamicBehaviorVector(elements.size());
// Initialize with false
std::fill(dynamicBehaviorVector.begin(), dynamicBehaviorVector.end(), false);
std::queue<DFTElementPointer> elementQueue;
// deal with all dynamic elements
for (auto const &element : elements) {
switch (element->type()) {
case storage::DFTElementType::PAND:
case storage::DFTElementType::POR:
// TODO check SPAREs, SEQs, MUTEXs
case storage::DFTElementType::SPARE:
case storage::DFTElementType::SEQ:
case storage::DFTElementType::MUTEX: {
auto gate = std::static_pointer_cast<storm::storage::DFTGate<ValueType>>(element);
dynamicBehaviorVector[gate->id()] = true;
for (auto const &child : gate->children()) {
// only enqueue static children
if (!dynamicBehaviorVector.at(child->id())) {
elementQueue.push(child);
}
}
break;
}
default: {
break;
}
}
}
// propagate dynamic behavior
while (!elementQueue.empty()) {
DFTElementPointer currentElement = elementQueue.front();
elementQueue.pop();
switch (currentElement->type()) {
// Static Gates
case storage::DFTElementType::AND:
case storage::DFTElementType::OR:
case storage::DFTElementType::VOT: {
// check all parents and if one has dynamic behavior, propagate it
dynamicBehaviorVector[currentElement->id()] = true;
auto gate = std::static_pointer_cast<storm::storage::DFTGate<ValueType>>(currentElement);
for (auto const &child : gate->children()) {
// only enqueue static children
if (!dynamicBehaviorVector.at(child->id())) {
elementQueue.push(child);
}
}
break;
}
//BEs
case storage::DFTElementType::BE_EXP:
case storage::DFTElementType::BE_CONST:
case storage::DFTElementType::BE: {
auto be = std::static_pointer_cast<storm::storage::DFTBE<ValueType>>(currentElement);
dynamicBehaviorVector[be->id()] = true;
// add all ingoing dependencies to queue
for (auto const &dep : be->ingoingDependencies()) {
if (!dynamicBehaviorVector.at(dep->id())) {
elementQueue.push(dep);
}
}
break;
}
case storage::DFTElementType::PDEP: {
auto dep = std::static_pointer_cast<storm::storage::DFTDependency<ValueType>>(currentElement);
dynamicBehaviorVector[dep->id()] = true;
// add all ingoing dependencies to queue
auto trigger = dep->triggerEvent();
if (!dynamicBehaviorVector.at(trigger->id())) {
elementQueue.push(trigger);
}
break;
}
default:
break;
}
}
return dynamicBehaviorVector;
}
template<typename ValueType>
bool DFTBuilder<ValueType>::addRestriction(std::string const& name, std::vector<std::string> const& children, storm::storage::DFTElementType tp) {
if (children.size() <= 1) {

2
src/storm-dft/builder/DFTBuilder.h

@ -237,6 +237,8 @@ namespace storm {
DFTElementVector topoSort();
std::vector<bool> computeHasDynamicBehavior(DFTElementVector elements);
// If true, the standard gate adders make a pand inclusive, and exclusive otherwise.
bool pandDefaultInclusive;
// If true, the standard gate adders make a pand inclusive, and exclusive otherwise.

5
src/storm-dft/storage/dft/DFT.cpp

@ -17,7 +17,10 @@ namespace storm {
namespace storage {
template<typename ValueType>
DFT<ValueType>::DFT(DFTElementVector const& elements, DFTElementPointer const& tle) : mElements(elements), mNrOfBEs(0), mNrOfSpares(0), mTopLevelIndex(tle->id()), mMaxSpareChildCount(0) {
DFT<ValueType>::DFT(DFTElementVector const &elements, DFTElementPointer const &tle,
std::vector<bool> const &dynamicBehavior) :
mElements(elements), mNrOfBEs(0), mNrOfSpares(0), mTopLevelIndex(tle->id()), mMaxSpareChildCount(0),
mDynamicBehavior(dynamicBehavior) {
// Check that ids correspond to indices in the element vector
STORM_LOG_ASSERT(elementIndicesCorrect(), "Ids incorrect.");
size_t nrRepresentatives = 0;

8
src/storm-dft/storage/dft/DFT.h

@ -67,9 +67,11 @@ namespace storm {
std::map<size_t, size_t> mRepresentants; // id element -> id representative
std::vector<std::vector<size_t>> mSymmetries;
std::map<size_t, DFTLayoutInfo> mLayoutInfo;
std::vector<bool> mDynamicBehavior;
public:
DFT(DFTElementVector const& elements, DFTElementPointer const& tle);
DFT(DFTElementVector const &elements, DFTElementPointer const &tle,
std::vector<bool> const &dynamicBehavior);
DFTStateGenerationInfo buildStateGenerationInfo(storm::storage::DFTIndependentSymmetries const& symmetries) const;
@ -133,6 +135,10 @@ namespace storm {
return mDependencies;
}
std::vector<bool> const &getDynamicBehavior() const {
return mDynamicBehavior;
}
std::vector<size_t> nonColdBEs() const {
std::vector<size_t> result;
for (DFTElementPointer elem : mElements) {

Loading…
Cancel
Save