Browse Source

Some more refactoring

tempestpy_adaptions
Matthias Volk 6 years ago
parent
commit
8090448564
  1. 24
      src/storm-dft/storage/dft/elements/DFTDependency.h
  2. 6
      src/storm-dft/storage/dft/elements/DFTElement.cpp
  3. 197
      src/storm-dft/storage/dft/elements/DFTElement.h
  4. 5
      src/storm-dft/storage/dft/elements/DFTGate.h
  5. 2
      src/storm-dft/storage/dft/elements/DFTRestriction.h

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

@ -55,6 +55,18 @@ namespace storm {
return mProbability; return mProbability;
} }
bool isDependency() const override {
return true;
}
/*!
* Check whether the dependency is an FDEP, i.e., p=1.
* @return True iff p=1.
*/
bool isFDEP() const {
return storm::utility::isOne(this->probability());
}
/*! /*!
* Get trigger event, i.e., the first child. * Get trigger event, i.e., the first child.
* @return Trigger event. * @return Trigger event.
@ -106,18 +118,6 @@ namespace storm {
return 1; return 1;
} }
bool isDependency() const override {
return true;
}
/*!
* Check whether the dependency is an FDEP, i.e., p=1.
* @return True iff p=1.
*/
bool isFDEP() const {
return storm::utility::isOne(this->probability());
}
bool isTypeEqualTo(DFTElement<ValueType> const& other) const override { bool isTypeEqualTo(DFTElement<ValueType> const& other) const override {
if (!DFTElement<ValueType>::isTypeEqualTo(other)) { if (!DFTElement<ValueType>::isTypeEqualTo(other)) {
return false; return false;

6
src/storm-dft/storage/dft/elements/DFTElement.cpp

@ -111,15 +111,9 @@ namespace storm {
} }
// Explicitly instantiate the class. // Explicitly instantiate the class.
template class DFTElement<double>; template class DFTElement<double>;
#ifdef STORM_HAVE_CARL
template class DFTElement<RationalFunction>; template class DFTElement<RationalFunction>;
#endif
} }
} }

197
src/storm-dft/storage/dft/elements/DFTElement.h

@ -16,8 +16,6 @@
#include "storm/adapters/RationalFunctionAdapter.h" #include "storm/adapters/RationalFunctionAdapter.h"
namespace storm { namespace storm {
namespace storage { namespace storage {
@ -29,10 +27,14 @@ namespace storm {
template<typename ValueType> template<typename ValueType>
class DFTDependency; class DFTDependency;
template<typename ValueType> template<typename ValueType>
class DFTRestriction; class DFTRestriction;
/*!
* Abstract base class for DFT elements.
* It is the most general class.
*/
template<typename ValueType> template<typename ValueType>
class DFTElement { class DFTElement {
@ -43,16 +45,6 @@ namespace storm {
using DFTRestrictionPointer = std::shared_ptr<DFTRestriction<ValueType>>; using DFTRestrictionPointer = std::shared_ptr<DFTRestriction<ValueType>>;
using DFTRestrictionVector = std::vector<DFTRestrictionPointer>; using DFTRestrictionVector = std::vector<DFTRestrictionPointer>;
protected:
std::size_t mId;
std::string mName;
std::size_t mRank = -1;
DFTGateVector mParents;
DFTDependencyVector mOutgoingDependencies;
DFTRestrictionVector mRestrictions;
public: public:
/*! /*!
* Constructor. * Constructor.
@ -60,12 +52,14 @@ namespace storm {
* @param name Name. * @param name Name.
*/ */
DFTElement(size_t id, std::string const& name) : mId(id), mName(name) { DFTElement(size_t id, std::string const& name) : mId(id), mName(name) {
// Intentionally left empty.
} }
/*! /*!
* Destructor. * Destructor.
*/ */
virtual ~DFTElement() { virtual ~DFTElement() {
// Intentionally left empty.
} }
/*! /*!
@ -99,6 +93,10 @@ namespace storm {
*/ */
virtual DFTElementType type() const = 0; virtual DFTElementType type() const = 0;
/*!
* Get type as string.
* @return String with type information.
*/
virtual std::string typestring() const { virtual std::string typestring() const {
return storm::storage::toString(this->type()); return storm::storage::toString(this->type());
} }
@ -119,10 +117,6 @@ namespace storm {
this->mRank = rank; this->mRank = rank;
} }
virtual bool isConstant() const {
return false;
}
/*! /*!
* Checks whether the element is a basic element. * Checks whether the element is a basic element.
* @return True iff element is a BE. * @return True iff element is a BE.
@ -132,51 +126,90 @@ namespace storm {
} }
/*! /*!
* Check wether the element is a gate.
* Check whether the element is a gate.
* @return True iff element is a gate. * @return True iff element is a gate.
*/ */
virtual bool isGate() const { virtual bool isGate() const {
return false; return false;
} }
/**
* Returns true if the element is a spare gate
/*!
* Check whether the element is a SPARE gate.
* @return True iff element is a SPARE gate.
*/ */
virtual bool isSpareGate() const { virtual bool isSpareGate() const {
return false; return false;
} }
/*!
* Check whether the element is a dependency.
* @return True iff element is a dependency.
*/
virtual bool isDependency() const { virtual bool isDependency() const {
return false; return false;
} }
/*!
* Check whether the element is a restriction.
* @return True iff element is a restriction.
*/
virtual bool isRestriction() const { virtual bool isRestriction() const {
return false; return false;
} }
/*!
* Return whether the element has parents.
* @return True iff at least one parent exists.
*/
bool hasParents() const {
return !mParents.empty();
}
bool addParent(DFTGatePointer const& e) {
if(std::find(mParents.begin(), mParents.end(), e) != mParents.end()) {
return false;
/*!
* Return the number of parents.
* @return Number of parents.
*/
size_t nrParents() const {
return mParents.size();
} }
else
{
mParents.push_back(e);
return true;
/*!
* Get parents.
* @return Parents.
*/
DFTGateVector const& parents() const {
return mParents;
} }
/*!
* Add parent.
* @param parent Parent.
*/
void addParent(DFTGatePointer const& parent) {
if (std::find(this->parents().begin(), this->parents().end(), parent) == this->parents().end()) {
// Parent does not exist yet
mParents.push_back(parent);
};
} }
bool addRestriction(DFTRestrictionPointer const& e) {
if (std::find(mRestrictions.begin(), mRestrictions.end(), e) != mRestrictions.end()) {
return false;
} else {
mRestrictions.push_back(e);
return true;
/*!
* Return Ids of parents.
* @return Parent ids.
*/
std::vector<size_t> parentIds() const {
std::vector<size_t> ids;
for (auto parent : this->parents()) {
ids.push_back(parent->id());
} }
return ids;
} }
/*!
* Check whether the element has only static gates as parents.
* @return True iff all parents are static gates.
*/
bool hasOnlyStaticParents() const { bool hasOnlyStaticParents() const {
for(auto const& parent : mParents) {
for (auto const& parent : this->parents()) {
if (!isStaticGateType(parent->type())) { if (!isStaticGateType(parent->type())) {
return false; return false;
} }
@ -184,59 +217,77 @@ namespace storm {
return true; return true;
} }
bool hasParents() const {
return !mParents.empty();
}
size_t nrParents() const {
return mParents.size();
}
DFTGateVector const& parents() const {
return mParents;
}
/*!
* Return whether the element has restrictions.
* @return True iff at least one restriction exists.
*/
bool hasRestrictions() const { bool hasRestrictions() const {
return !mRestrictions.empty(); return !mRestrictions.empty();
} }
/*!
* Return the number of restrictions.
* @return Number of restrictions.
*/
size_t nrRestrictions() const { size_t nrRestrictions() const {
return mRestrictions.size(); return mRestrictions.size();
} }
/*!
* Get restrictions.
* @return Restrictions.
*/
DFTRestrictionVector const& restrictions() const { DFTRestrictionVector const& restrictions() const {
return mRestrictions; return mRestrictions;
} }
std::vector<size_t> parentIds() const {
std::vector<size_t> res;
for(auto parent : parents()) {
res.push_back(parent->id());
}
return res;
}
bool addOutgoingDependency(DFTDependencyPointer const& e) {
STORM_LOG_ASSERT(e->triggerEvent()->id() == this->id(), "Ids do not match.");
if(std::find(mOutgoingDependencies.begin(), mOutgoingDependencies.end(), e) != mOutgoingDependencies.end()) {
return false;
}
else
{
mOutgoingDependencies.push_back(e);
return true;
/*!
* Add restriction.
* @param restrictions Restriction.
*/
void addRestriction(DFTRestrictionPointer const& restriction) {
if (std::find(this->restrictions().begin(), this->restrictions().end(), restriction) == this->restrictions().end()) {
// Restriction does not exist yet
mRestrictions.push_back(restriction);
} }
} }
/*!
* Return whether the element has outgoing dependencies.
* @return True iff at least one restriction exists.
*/
bool hasOutgoingDependencies() const { bool hasOutgoingDependencies() const {
return !mOutgoingDependencies.empty(); return !mOutgoingDependencies.empty();
} }
/*!
* Return the number of outgoing dependencies.
* @return Number of outgoing dependencies.
*/
size_t nrOutgoingDependencies() const { size_t nrOutgoingDependencies() const {
return mOutgoingDependencies.size(); return mOutgoingDependencies.size();
} }
/*!
* Get outgoing dependencies.
* @return Outgoing dependencies.
*/
DFTDependencyVector const& outgoingDependencies() const {
return mOutgoingDependencies;
}
/*!
* Add outgoing dependency.
* @param outgoingDependency Outgoing dependency.
*/
void addOutgoingDependency(DFTDependencyPointer const& outgoingDependency) {
STORM_LOG_ASSERT(outgoingDependency->triggerEvent()->id() == this->id(), "Ids do not match.");
if (std::find(this->outgoingDependencies().begin(), this->outgoingDependencies().end(), outgoingDependency) == this->outgoingDependencies().end()) {
// Outgoing dependency does not exist yet
mOutgoingDependencies.push_back(outgoingDependency);
};
}
/** /**
* Obtains ids of elements which are the direct successor in the list of children of a restriction * Obtains ids of elements which are the direct successor in the list of children of a restriction
* @return A vector of ids * @return A vector of ids
@ -287,10 +338,6 @@ namespace storm {
return res; return res;
} }
DFTDependencyVector const& outgoingDependencies() const {
return mOutgoingDependencies;
}
virtual void extendSpareModule(std::set<size_t>& elementsInModule) const; virtual void extendSpareModule(std::set<size_t>& elementsInModule) const;
// virtual void extendImmediateFailureCausePathEvents(std::set<size_t>& ) const; // virtual void extendImmediateFailureCausePathEvents(std::set<size_t>& ) const;
@ -320,12 +367,18 @@ namespace storm {
* such that there exists a path from x to a child of this does not go through this. * such that there exists a path from x to a child of this does not go through this.
*/ */
virtual std::vector<size_t> independentSubDft(bool blockParents, bool sparesAsLeaves = false) const; virtual std::vector<size_t> independentSubDft(bool blockParents, bool sparesAsLeaves = false) const;
/** /**
* Helper to the independent subtree computation * Helper to the independent subtree computation
* @see independentSubDft * @see independentSubDft
*/ */
virtual void extendSubDft(std::set<size_t>& elemsInSubtree, std::vector<size_t> const& parentsOfSubRoot, bool blockParents, bool sparesAsLeaves) const; virtual void extendSubDft(std::set<size_t>& elemsInSubtree, std::vector<size_t> const& parentsOfSubRoot, bool blockParents, bool sparesAsLeaves) const;
/*!
* Check whether two elements have the same type.
* @param other Other element.
* @return True iff this and other have the same type.
*/
virtual bool isTypeEqualTo(DFTElement<ValueType> const& other) const { virtual bool isTypeEqualTo(DFTElement<ValueType> const& other) const {
return type() == other.type(); return type() == other.type();
} }
@ -338,8 +391,12 @@ namespace storm {
protected: protected:
// virtual bool checkIsomorphicSubDftHelper(DFTElement const& otherElem, std::vector<std::pair<DFTElement const&, DFTElement const&>>& mapping, std::vector<DFTElement const&> const& order ) const = 0;
std::size_t mId;
std::string mName;
std::size_t mRank = -1;
DFTGateVector mParents;
DFTDependencyVector mOutgoingDependencies;
DFTRestrictionVector mRestrictions;
}; };

5
src/storm-dft/storage/dft/elements/DFTGate.h

@ -90,6 +90,11 @@ namespace storm {
this->childrenDontCare(state, queues); this->childrenDontCare(state, queues);
} }
/*!
* Propagate Don't Care to children.
* @param state Current DFT state.
* @param queues Propagation queues.
*/
void childrenDontCare(DFTState<ValueType>& state, DFTStateSpaceGenerationQueues<ValueType>& queues) const { void childrenDontCare(DFTState<ValueType>& state, DFTStateSpaceGenerationQueues<ValueType>& queues) const {
queues.propagateDontCare(this->children()); queues.propagateDontCare(this->children());
} }

2
src/storm-dft/storage/dft/elements/DFTRestriction.h

@ -72,7 +72,7 @@ namespace storm {
} }
void failsafe(DFTState <ValueType>& state, DFTStateSpaceGenerationQueues <ValueType>& queues) const override { void failsafe(DFTState <ValueType>& state, DFTStateSpaceGenerationQueues <ValueType>& queues) const override {
// Do nothing
} }
}; };

Loading…
Cancel
Save