Browse Source

towards support for n-ary pdeps

tempestpy_adaptions
sjunges 8 years ago
parent
commit
a42703a49a
  1. 32
      src/storm-dft/storage/dft/DFTBuilder.cpp
  2. 33
      src/storm-dft/storage/dft/DFTBuilder.h
  3. 19
      src/storm-dft/storage/dft/elements/DFTDependency.h

32
src/storm-dft/storage/dft/DFTBuilder.cpp

@ -50,17 +50,29 @@ namespace storm {
}
}
// Initialize dependencies
for (auto& dependency : mDependencies) {
DFTGatePointer triggerEvent = std::static_pointer_cast<DFTGate<ValueType>>(mElements[dependency->nameTrigger()]);
STORM_LOG_ASSERT(mElements[dependency->nameDependent()]->isBasicElement(), "Dependent element is not BE.");
std::shared_ptr<DFTBE<ValueType>> dependentEvent = std::static_pointer_cast<DFTBE<ValueType>>(mElements[dependency->nameDependent()]);
dependency->initialize(triggerEvent, dependentEvent);
triggerEvent->addOutgoingDependency(dependency);
dependentEvent->addIngoingDependency(dependency);
for(auto& elem : mDependencyChildNames) {
bool first = true;
std::vector<std::shared_ptr<DFTBE<ValueType>>> dependencies;
for(auto const& childName : elem.second) {
auto itFind = mElements.find(childName);
STORM_LOG_ASSERT(itFind != mElements.end(), "Child '" << childName << "' not found");
DFTElementPointer childElement = itFind->second;
if (!first) {
dependencies.push_back(std::static_pointer_cast<DFTBE<ValueType>>(childElement));
} else {
elem.first->setTriggerElement(std::static_pointer_cast<DFTGate<ValueType>>(childElement));
childElement->addOutgoingDependency(elem.first);
}
first = false;
}
if (binaryDependencies) {
assert(dependencies.size() == 1);
}
assert(binaryDependencies);
elem.first->setDependentEvent(dependencies[0]);
dependencies[0]->addIngoingDependency(elem.first);
}
// Sort elements topologically
// compute rank

33
src/storm-dft/storage/dft/DFTBuilder.h

@ -31,6 +31,7 @@ namespace storm {
std::unordered_map<std::string, DFTElementPointer> mElements;
std::unordered_map<DFTElementPointer, std::vector<std::string>> mChildNames;
std::unordered_map<DFTRestrictionPointer, std::vector<std::string>> mRestrictionChildNames;
std::unordered_map<DFTDependencyPointer, std::vector<std::string>> mDependencyChildNames;
std::vector<DFTDependencyPointer> mDependencies;
std::vector<DFTRestrictionPointer> mRestrictions;
std::unordered_map<std::string, DFTLayoutInfo> mLayoutInfo;
@ -101,7 +102,7 @@ namespace storm {
//TODO Matthias: collect constraints for SMT solving
//0 <= probability <= 1
if (!storm::utility::isOne(probability) && children.size() > 2) {
if (binaryDependencies && !storm::utility::isOne(probability) && children.size() > 2) {
// Introduce additional element for first capturing the proabilistic dependency
std::string nameAdditional = name + "_additional";
addBasicElement(nameAdditional, storm::utility::zero<ValueType>(), storm::utility::zero<ValueType>());
@ -114,17 +115,25 @@ namespace storm {
return true;
} else {
// Add dependencies
for (size_t i = 1; i < children.size(); ++i) {
std::string nameDep = name + "_" + std::to_string(i);
if(mElements.count(nameDep) != 0) {
// Element with that name already exists.
STORM_LOG_ERROR("Element with name: " << nameDep << " already exists.");
return false;
if(binaryDependencies) {
for (size_t i = 1; i < children.size(); ++i) {
std::string nameDep = name + "_" + std::to_string(i);
if (mElements.count(nameDep) != 0) {
// Element with that name already exists.
STORM_LOG_ERROR("Element with name: " << nameDep << " already exists.");
return false;
}
STORM_LOG_ASSERT(storm::utility::isOne(probability) || children.size() == 2,
"PDep with multiple children supported.");
DFTDependencyPointer element = std::make_shared<DFTDependency<ValueType>>(mNextId++,
nameDep,
probability);
mElements[element->name()] = element;
mDependencyChildNames[element] = {trigger, children[i]};
mDependencies.push_back(element);
}
STORM_LOG_ASSERT(storm::utility::isOne(probability) || children.size() == 2, "PDep with multiple children supported.");
DFTDependencyPointer element = std::make_shared<DFTDependency<ValueType>>(mNextId++, nameDep, trigger, children[i], probability);
mElements[element->name()] = element;
mDependencies.push_back(element);
} else {
}
return true;
}
@ -213,6 +222,8 @@ namespace storm {
bool pandDefaultInclusive;
// If true, the standard gate adders make a pand inclusive, and exclusive otherwise.
bool porDefaultInclusive;
bool binaryDependencies;
};
}

19
src/storm-dft/storage/dft/elements/DFTDependency.h

@ -12,35 +12,28 @@ namespace storm {
using DFTBEPointer = std::shared_ptr<DFTBE<ValueType>>;
protected:
std::string mNameTrigger;
std::string mNameDependent;
ValueType mProbability;
DFTGatePointer mTriggerEvent;
DFTBEPointer mDependentEvent;
public:
DFTDependency(size_t id, std::string const& name, std::string const& trigger, std::string const& dependent, ValueType probability) :
DFTElement<ValueType>(id, name), mNameTrigger(trigger), mNameDependent(dependent), mProbability(probability)
DFTDependency(size_t id, std::string const& name, ValueType probability) :
DFTElement<ValueType>(id, name), mProbability(probability)
{
}
virtual ~DFTDependency() {}
void initialize(DFTGatePointer triggerEvent, DFTBEPointer dependentEvent) {
STORM_LOG_ASSERT(triggerEvent->name() == mNameTrigger, "Name does not match.");
STORM_LOG_ASSERT(dependentEvent->name() == mNameDependent, "Name does not match.");
void setTriggerElement(DFTGatePointer const& triggerEvent) {
mTriggerEvent = triggerEvent;
mDependentEvent = dependentEvent;
}
std::string nameTrigger() const {
return mNameTrigger;
}
std::string nameDependent() const {
return mNameDependent;
void setDependentEvent(DFTBEPointer const& dependentEvent) {
mDependentEvent = dependentEvent;
}
ValueType const& probability() const {
return mProbability;
}

Loading…
Cancel
Save