Browse Source

Some refactoring

Former-commit-id: 95441da721
tempestpy_adaptions
Mavo 9 years ago
parent
commit
7dd1bb67ea
  1. 13
      src/builder/ExplicitDFTModelBuilder.cpp
  2. 3
      src/storage/dft/DFTBuilder.cpp
  3. 8
      src/storage/dft/DFTElements.h
  4. 18
      src/storage/dft/DFTState.cpp
  5. 4
      src/storage/dft/DFTState.h

13
src/builder/ExplicitDFTModelBuilder.cpp

@ -77,7 +77,6 @@ namespace storm {
while (!stateQueue.empty()) {
// Initialization
outgoingTransitions.clear();
ValueType sum = storm::utility::zero<ValueType>();
// Consider next state
DFTStatePointer state = stateQueue.front();
@ -147,7 +146,9 @@ namespace storm {
bool isUsed = true;
if (mDft.hasRepresentant(nextBE->id())) {
DFTElementPointer representant = mDft.getRepresentant(nextBE->id());
isUsed = newState->isUsed(representant->id());
// Used must be checked for the state we are coming from as this state is responsible for the
// rate and not the new state we are going to
isUsed = state->isUsed(representant->id());
}
STORM_LOG_TRACE("BE " << nextBE->name() << " is " << (isUsed ? "used" : "not used"));
ValueType rate = isUsed ? nextBE->activeFailureRate() : nextBE->passiveFailureRate();
@ -155,20 +156,18 @@ namespace storm {
if (resultFind != outgoingTransitions.end()) {
// Add to existing transition
resultFind->second += rate;
STORM_LOG_TRACE("Updated transition from " << state->getId() << " to " << resultFind->first << " with " << rate << " to " << resultFind->second);
} else {
// Insert new transition
outgoingTransitions.insert(std::make_pair(newState->getId(), rate));
STORM_LOG_TRACE("Added transition from " << state->getId() << " to " << newState->getId() << " with " << rate);
}
sum += rate;
} // end while failing BE
// Add all transitions
for (auto it = outgoingTransitions.begin(); it != outgoingTransitions.end(); ++it)
{
// TODO Matthias: correct?
ValueType rate = it->second;// / sum;
transitionMatrixBuilder.addNextValue(state->getId(), it->first, rate);
STORM_LOG_TRACE("Added transition from " << state->getId() << " to " << it->first << " with " << rate);
transitionMatrixBuilder.addNextValue(state->getId(), it->first, it->second);
}
} // end while queue

3
src/storage/dft/DFTBuilder.cpp

@ -16,15 +16,14 @@ namespace storm {
template<typename ValueType>
DFT<ValueType> DFTBuilder<ValueType>::build() {
for(auto& elem : mChildNames) {
DFTGatePointer gate = std::static_pointer_cast<DFTGate<ValueType>>(elem.first);
for(auto const& child : elem.second) {
DFTGatePointer gate = std::static_pointer_cast<DFTGate<ValueType>>(elem.first);
gate->pushBackChild(mElements[child]);
mElements[child]->addParent(gate);
}
}
// Sort elements topologically
// compute rank
for (auto& elem : mElements) {
computeRank(elem.second);

8
src/storage/dft/DFTElements.h

@ -657,13 +657,7 @@ namespace storm {
if(state.isOperational(this->mId)) {
size_t uses = state.extractUses(mUseIndex);
if(!state.isOperational(uses)) {
// TODO compute children ids before.
std::vector<size_t> childrenIds;
for(auto const& child : this->mChildren) {
childrenIds.push_back(child->id());
}
bool claimingSuccessful = state.claimNew(this->mId, mUseIndex, uses, childrenIds);
bool claimingSuccessful = state.claimNew(this->mId, mUseIndex, uses, this->mChildren);
if(!claimingSuccessful) {
this->fail(state, queues);
}

18
src/storage/dft/DFTState.cpp

@ -134,15 +134,19 @@ namespace storm {
}
template<typename ValueType>
bool DFTState<ValueType>::claimNew(size_t spareId, size_t usageIndex, size_t currentlyUses, std::vector<size_t> const& childIds) {
auto it = find(childIds.begin(), childIds.end(), currentlyUses);
assert(it != childIds.end());
bool DFTState<ValueType>::claimNew(size_t spareId, size_t usageIndex, size_t currentlyUses, std::vector<std::shared_ptr<DFTElement<ValueType>>> const& children) {
auto it = children.begin();
while ((*it)->id() != currentlyUses) {
assert(it != children.end());
++it;
}
++it;
while(it != childIds.end()) {
if(!hasFailed(*it) && !isUsed(*it)) {
setUsesAtPosition(usageIndex, *it);
while(it != children.end()) {
size_t childId = (*it)->id();
if(!hasFailed(childId) && !isUsed(childId)) {
setUsesAtPosition(usageIndex, childId);
if(isActiveSpare(spareId)) {
mDft.propagateActivation(*this,*it);
mDft.propagateActivation(*this, childId);
}
return true;
}

4
src/storage/dft/DFTState.h

@ -13,6 +13,8 @@ namespace storm {
class DFT;
template<typename ValueType>
class DFTBE;
template<typename ValueType>
class DFTElement;
template<typename ValueType>
class DFTState {
@ -97,7 +99,7 @@ namespace storm {
*/
void setUsesAtPosition(size_t usageIndex, size_t child);
bool claimNew(size_t spareId, size_t usageIndex, size_t currentlyUses, std::vector<size_t> const& childIds);
bool claimNew(size_t spareId, size_t usageIndex, size_t currentlyUses, std::vector<std::shared_ptr<DFTElement<ValueType>>> const& children);
bool hasOutgoingEdges() const {
return !mIsCurrentlyFailableBE.empty();

Loading…
Cancel
Save