Browse Source

Refactored DftToGspnTransformator

main
Matthias Volk 7 years ago
parent
commit
ec8304c386
  1. 695
      src/storm-dft/transformations/DftToGspnTransformator.cpp
  2. 160
      src/storm-dft/transformations/DftToGspnTransformator.h

695
src/storm-dft/transformations/DftToGspnTransformator.cpp

@ -20,65 +20,64 @@ namespace storm {
this->smart = smart; this->smart = smart;
builder.setGspnName("DftToGspnTransformation"); builder.setGspnName("DftToGspnTransformation");
// Loop through every DFT element and draw them as a GSPN. // Translate all GSPN elements
drawGSPNElements(); translateGSPNElements();
// Draw restrictions into the GSPN (i.e. SEQ or MUTEX). // Create initial template
// TODO // TODO
//drawGSPNRestrictions();
} }
template<typename ValueType> template<typename ValueType>
uint64_t DftToGspnTransformator<ValueType>::toplevelFailedPlaceId() { uint64_t DftToGspnTransformator<ValueType>::toplevelFailedPlaceId() {
assert(failedNodes.size() > mDft.getTopLevelIndex()); STORM_LOG_ASSERT(failedPlaces.size() > mDft.getTopLevelIndex(), "Failed place for top level element does not exist.");
return failedNodes[mDft.getTopLevelIndex()]; return failedPlaces.at(mDft.getTopLevelIndex());
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawGSPNElements() { gspn::GSPN* DftToGspnTransformator<ValueType>::obtainGSPN() {
return builder.buildGspn();
}
// Loop through every DFT element and draw them as a GSPN. template <typename ValueType>
void DftToGspnTransformator<ValueType>::translateGSPNElements() {
// Loop through every DFT element and create its corresponding GSPN template.
for (std::size_t i = 0; i < mDft.nrElements(); i++) { for (std::size_t i = 0; i < mDft.nrElements(); i++) {
auto dftElement = mDft.getElement(i); auto dftElement = mDft.getElement(i);
bool isRepresentative = mDft.isRepresentative(i);
// Check which type the element is and call the corresponding drawing-function. // Check which type the element is and call the corresponding translate-function.
switch (dftElement->type()) { switch (dftElement->type()) {
case storm::storage::DFTElementType::BE:
translateBE(std::static_pointer_cast<storm::storage::DFTBE<ValueType> const>(dftElement));
break;
case storm::storage::DFTElementType::CONSTF:
translateCONSTF(dftElement);
break;
case storm::storage::DFTElementType::CONSTS:
translateCONSTS(dftElement);
break;
case storm::storage::DFTElementType::AND: case storm::storage::DFTElementType::AND:
drawAND(std::static_pointer_cast<storm::storage::DFTAnd<ValueType> const>(dftElement), isRepresentative); translateAND(std::static_pointer_cast<storm::storage::DFTAnd<ValueType> const>(dftElement));
break; break;
case storm::storage::DFTElementType::OR: case storm::storage::DFTElementType::OR:
drawOR(std::static_pointer_cast<storm::storage::DFTOr<ValueType> const>(dftElement), isRepresentative); translateOR(std::static_pointer_cast<storm::storage::DFTOr<ValueType> const>(dftElement));
break; break;
case storm::storage::DFTElementType::VOT: case storm::storage::DFTElementType::VOT:
drawVOT(std::static_pointer_cast<storm::storage::DFTVot<ValueType> const>(dftElement), isRepresentative); translateVOT(std::static_pointer_cast<storm::storage::DFTVot<ValueType> const>(dftElement));
break; break;
case storm::storage::DFTElementType::PAND: case storm::storage::DFTElementType::PAND:
drawPAND(std::static_pointer_cast<storm::storage::DFTPand<ValueType> const>(dftElement), isRepresentative); translatePAND(std::static_pointer_cast<storm::storage::DFTPand<ValueType> const>(dftElement), std::static_pointer_cast<storm::storage::DFTPand<ValueType> const>(dftElement)->isInclusive());
break;
case storm::storage::DFTElementType::SPARE:
drawSPARE(std::static_pointer_cast<storm::storage::DFTSpare<ValueType> const>(dftElement), isRepresentative);
break; break;
case storm::storage::DFTElementType::POR: case storm::storage::DFTElementType::POR:
drawPOR(std::static_pointer_cast<storm::storage::DFTPor<ValueType> const>(dftElement), isRepresentative); translatePOR(std::static_pointer_cast<storm::storage::DFTPor<ValueType> const>(dftElement), std::static_pointer_cast<storm::storage::DFTPor<ValueType> const>(dftElement)->isInclusive());
break;
case storm::storage::DFTElementType::SEQ:
drawSeq(std::static_pointer_cast<storm::storage::DFTSeq<ValueType> const>(dftElement));
break; break;
case storm::storage::DFTElementType::MUTEX: case storm::storage::DFTElementType::SPARE:
// No method call needed here. MUTEX only consists of restrictions, which are handled later. translateSPARE(std::static_pointer_cast<storm::storage::DFTSpare<ValueType> const>(dftElement));
break;
case storm::storage::DFTElementType::BE:
drawBE(std::static_pointer_cast<storm::storage::DFTBE<ValueType> const>(dftElement), isRepresentative);
break;
case storm::storage::DFTElementType::CONSTF:
drawCONSTF(dftElement, isRepresentative);
break;
case storm::storage::DFTElementType::CONSTS:
drawCONSTS(dftElement, isRepresentative);
break; break;
case storm::storage::DFTElementType::PDEP: case storm::storage::DFTElementType::PDEP:
drawPDEP(std::static_pointer_cast<storm::storage::DFTDependency<ValueType> const>(dftElement)); translatePDEP(std::static_pointer_cast<storm::storage::DFTDependency<ValueType> const>(dftElement));
break;
case storm::storage::DFTElementType::SEQ:
translateSeq(std::static_pointer_cast<storm::storage::DFTSeq<ValueType> const>(dftElement));
break; break;
default: default:
STORM_LOG_ASSERT(false, "DFT type " << dftElement->type() << " unknown."); STORM_LOG_ASSERT(false, "DFT type " << dftElement->type() << " unknown.");
@ -89,282 +88,282 @@ namespace storm {
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawBE(std::shared_ptr<storm::storage::DFTBE<ValueType> const> dftBE, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translateBE(std::shared_ptr<storm::storage::DFTBE<ValueType> const> dftBE) {
uint64_t beActive = builder.addPlace(defaultCapacity, isActiveInitially(dftBE) ? 1 : 0, dftBE->name() + STR_ACTIVATED);
activeNodes.emplace(dftBE->id(), beActive);
uint64_t beFailed = builder.addPlace(defaultCapacity, 0, dftBE->name() + STR_FAILED);
double xcenter = mDft.getElementLayoutInfo(dftBE->id()).x; double xcenter = mDft.getElementLayoutInfo(dftBE->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftBE->id()).y; double ycenter = mDft.getElementLayoutInfo(dftBE->id()).y;
builder.setPlaceLayoutInfo(beActive, storm::gspn::LayoutInfo(xcenter - 3.0, ycenter));
builder.setPlaceLayoutInfo(beFailed, storm::gspn::LayoutInfo(xcenter + 3.0, ycenter));
uint64_t disabledNode = 0; uint64_t failedPlace = addFailedPlace(dftBE, storm::gspn::LayoutInfo(xcenter + 3.0, ycenter));
if (!smart || dftBE->nrRestrictions() > 0) {
disabledNode = addDisabledPlace(dftBE, storm::gspn::LayoutInfo(xcenter-9.0, ycenter));
}
uint64_t unavailableNode = 0; uint64_t activePlace = builder.addPlace(defaultCapacity, isActiveInitially(dftBE) ? 1 : 0, dftBE->name() + STR_ACTIVATED);
if (!smart || isRepresentative) { activePlaces.emplace(dftBE->id(), activePlace);
unavailableNode = addUnavailableNode(dftBE, storm::gspn::LayoutInfo(xcenter+9.0, ycenter)); builder.setPlaceLayoutInfo(activePlace, storm::gspn::LayoutInfo(xcenter - 3.0, ycenter));
}
assert(failedNodes.size() == dftBE->id());
failedNodes.push_back(beFailed);
uint64_t tActive = builder.addTimedTransition(defaultPriority, dftBE->activeFailureRate(), dftBE->name() + "_activeFailing"); uint64_t tActive = builder.addTimedTransition(defaultPriority, dftBE->activeFailureRate(), dftBE->name() + "_activeFailing");
builder.setTransitionLayoutInfo(tActive, storm::gspn::LayoutInfo(xcenter, ycenter + 3.0)); builder.setTransitionLayoutInfo(tActive, storm::gspn::LayoutInfo(xcenter, ycenter + 3.0));
builder.addInputArc(beActive, tActive); builder.addInputArc(activePlace, tActive);
builder.addInhibitionArc(beFailed, tActive); builder.addInhibitionArc(failedPlace, tActive);
builder.addOutputArc(tActive, beActive); builder.addOutputArc(tActive, activePlace);
builder.addOutputArc(tActive, beFailed); builder.addOutputArc(tActive, failedPlace);
uint64_t tPassive = builder.addTimedTransition(defaultPriority, dftBE->passiveFailureRate(), dftBE->name() + "_passiveFailing"); uint64_t tPassive = builder.addTimedTransition(defaultPriority, dftBE->passiveFailureRate(), dftBE->name() + "_passiveFailing");
builder.setTransitionLayoutInfo(tPassive, storm::gspn::LayoutInfo(xcenter, ycenter - 3.0)); builder.setTransitionLayoutInfo(tPassive, storm::gspn::LayoutInfo(xcenter, ycenter - 3.0));
builder.addInhibitionArc(beActive, tPassive); builder.addInhibitionArc(activePlace, tPassive);
builder.addInhibitionArc(beFailed, tPassive); builder.addInhibitionArc(failedPlace, tPassive);
builder.addOutputArc(tPassive, beFailed); builder.addOutputArc(tPassive, failedPlace);
if (!smart || dftBE->nrRestrictions() > 0) { if (!smart || dftBE->nrRestrictions() > 0) {
builder.addInhibitionArc(disabledNode, tActive); uint64_t disabledPlace = addDisabledPlace(dftBE, storm::gspn::LayoutInfo(xcenter-9.0, ycenter));
builder.addInhibitionArc(disabledNode, tPassive); builder.addInhibitionArc(disabledPlace, tActive);
builder.addInhibitionArc(disabledPlace, tPassive);
} }
if (!smart || isRepresentative) { if (!smart || mDft.isRepresentative(dftBE->id())) {
builder.addOutputArc(tActive, unavailableNode); uint64_t unavailablePlace = addUnavailablePlace(dftBE, storm::gspn::LayoutInfo(xcenter+9.0, ycenter));
builder.addOutputArc(tPassive, unavailableNode); builder.addOutputArc(tActive, unavailablePlace);
builder.addOutputArc(tPassive, unavailablePlace);
}
}
template <typename ValueType>
void DftToGspnTransformator<ValueType>::translateCONSTF(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstF) {
double xcenter = mDft.getElementLayoutInfo(dftConstF->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftConstF->id()).y;
addFailedPlace(dftConstF, storm::gspn::LayoutInfo(xcenter, ycenter - 3.0), true);
if (!smart || mDft.isRepresentative(dftConstF->id())) {
addUnavailablePlace(dftConstF, storm::gspn::LayoutInfo(xcenter, ycenter + 3.0), false);
} }
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawAND(std::shared_ptr<storm::storage::DFTAnd<ValueType> const> dftAnd, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translateCONSTS(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstS) {
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftAnd->name() + STR_FAILED); double xcenter = mDft.getElementLayoutInfo(dftConstS->id()).x;
assert(failedNodes.size() == dftAnd->id()); double ycenter = mDft.getElementLayoutInfo(dftConstS->id()).y;
failedNodes.push_back(nodeFailed); size_t capacity = 0; // It cannot contain a token, because it cannot fail.
uint64_t failedPlace = builder.addPlace(capacity, 0, dftConstS->name() + STR_FAILED);
assert(failedPlaces.size() == dftConstS->id());
failedPlaces.push_back(failedPlace);
builder.setPlaceLayoutInfo(failedPlace, storm::gspn::LayoutInfo(xcenter, ycenter - 3.0));
if (!smart || mDft.isRepresentative(dftConstS->id())) {
uint64_t unavailablePlace = builder.addPlace(capacity, 0, dftConstS->name() + "_unavail");
unavailablePlaces.emplace(dftConstS->id(), unavailablePlace);
builder.setPlaceLayoutInfo(unavailablePlace, storm::gspn::LayoutInfo(xcenter, ycenter + 3.0));
}
}
template <typename ValueType>
void DftToGspnTransformator<ValueType>::translateAND(std::shared_ptr<storm::storage::DFTAnd<ValueType> const> dftAnd) {
double xcenter = mDft.getElementLayoutInfo(dftAnd->id()).x; double xcenter = mDft.getElementLayoutInfo(dftAnd->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftAnd->id()).y; double ycenter = mDft.getElementLayoutInfo(dftAnd->id()).y;
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter, ycenter-3.0));
uint64_t unavailableNode = 0; uint64_t failedPlace = addFailedPlace(dftAnd, storm::gspn::LayoutInfo(xcenter, ycenter-3.0));
if (!smart || isRepresentative) {
unavailableNode = addUnavailableNode(dftAnd, storm::gspn::LayoutInfo(xcenter+6.0, ycenter-3.0));
}
uint64_t tFailed = builder.addImmediateTransition(getFailPriority(dftAnd), 0.0, dftAnd->name() + STR_FAILING );
builder.setTransitionLayoutInfo(tFailed, storm::gspn::LayoutInfo(xcenter, ycenter+3.0));
builder.addInhibitionArc(failedPlace, tFailed);
builder.addOutputArc(tFailed, failedPlace);
uint64_t tAndFailed = builder.addImmediateTransition( getFailPriority(dftAnd), 0.0, dftAnd->name() + STR_FAILING ); if (!smart || mDft.isRepresentative(dftAnd->id())) {
builder.setTransitionLayoutInfo(tAndFailed, storm::gspn::LayoutInfo(xcenter, ycenter+3.0)); uint64_t unavailablePlace = addUnavailablePlace(dftAnd, storm::gspn::LayoutInfo(xcenter+6.0, ycenter-3.0));
builder.addInhibitionArc(nodeFailed, tAndFailed); builder.addOutputArc(tFailed, unavailablePlace);
builder.addOutputArc(tAndFailed, nodeFailed);
if (!smart || isRepresentative) {
builder.addOutputArc(tAndFailed, unavailableNode);
} }
for (auto const& child : dftAnd->children()) { for (auto const& child : dftAnd->children()) {
assert(failedNodes.size() > child->id()); builder.addInputArc(getFailedPlace(child), tFailed);
builder.addInputArc(failedNodes[child->id()], tAndFailed); builder.addOutputArc(tFailed, getFailedPlace(child));
builder.addOutputArc(tAndFailed, failedNodes[child->id()]);
} }
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawOR(std::shared_ptr<storm::storage::DFTOr<ValueType> const> dftOr, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translateOR(std::shared_ptr<storm::storage::DFTOr<ValueType> const> dftOr) {
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftOr->name() + STR_FAILED);
assert(failedNodes.size() == dftOr->id());
failedNodes.push_back(nodeFailed);
double xcenter = mDft.getElementLayoutInfo(dftOr->id()).x; double xcenter = mDft.getElementLayoutInfo(dftOr->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftOr->id()).y; double ycenter = mDft.getElementLayoutInfo(dftOr->id()).y;
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter, ycenter-3.0));
uint64_t unavailableNode = 0; uint64_t failedPlace = addFailedPlace(dftOr, storm::gspn::LayoutInfo(xcenter, ycenter-3.0));
bool isRepresentative = mDft.isRepresentative(dftOr->id());
uint64_t unavailablePlace = 0;
if (!smart || isRepresentative) { if (!smart || isRepresentative) {
unavailableNode = addUnavailableNode(dftOr, storm::gspn::LayoutInfo(xcenter+6.0, ycenter-3.0)); unavailablePlace = addUnavailablePlace(dftOr, storm::gspn::LayoutInfo(xcenter+6.0, ycenter-3.0));
} }
uint64_t i = 0; for (size_t i = 0; i < dftOr->nrChildren(); ++i) {
for (auto const& child : dftOr->children()) { auto const& child = dftOr->children().at(i);
uint64_t tNodeFailed = builder.addImmediateTransition( getFailPriority(dftOr), 0.0, dftOr->name() + STR_FAILING + std::to_string(i) ); uint64_t tFailed = builder.addImmediateTransition(getFailPriority(dftOr), 0.0, dftOr->name() + STR_FAILING + std::to_string(i) );
builder.setTransitionLayoutInfo(tNodeFailed, storm::gspn::LayoutInfo(xcenter-5.0+i*3.0, ycenter+3.0)); builder.setTransitionLayoutInfo(tFailed, storm::gspn::LayoutInfo(xcenter-5.0+i*3.0, ycenter+3.0));
builder.addInhibitionArc(nodeFailed, tNodeFailed); builder.addInhibitionArc(failedPlace, tFailed);
builder.addOutputArc(tNodeFailed, nodeFailed); builder.addOutputArc(tFailed, failedPlace);
if (!smart || isRepresentative) { if (!smart || isRepresentative) {
builder.addOutputArc(tNodeFailed, unavailableNode); builder.addOutputArc(tFailed, unavailablePlace);
} }
assert(failedNodes.size() > child->id()); builder.addInputArc(getFailedPlace(child), tFailed);
builder.addInputArc(failedNodes[child->id()], tNodeFailed); builder.addOutputArc(tFailed, getFailedPlace(child));
builder.addOutputArc(tNodeFailed, failedNodes[child->id()]);
++i;
} }
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawVOT(std::shared_ptr<storm::storage::DFTVot<ValueType> const> dftVot, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translateVOT(std::shared_ptr<storm::storage::DFTVot<ValueType> const> dftVot) {
// TODO: finish layouting // TODO: finish layouting
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftVot->name() + STR_FAILED);
assert(failedNodes.size() == dftVot->id());
failedNodes.push_back(nodeFailed);
double xcenter = mDft.getElementLayoutInfo(dftVot->id()).x; double xcenter = mDft.getElementLayoutInfo(dftVot->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftVot->id()).y; double ycenter = mDft.getElementLayoutInfo(dftVot->id()).y;
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter, ycenter-3.0));
uint64_t unavailableNode = 0; uint64_t failedPlace = addFailedPlace(dftVot, storm::gspn::LayoutInfo(xcenter, ycenter-3.0));
if (!smart || isRepresentative) {
unavailableNode = addUnavailableNode(dftVot, storm::gspn::LayoutInfo(xcenter+6.0, ycenter-3.0));
}
uint64_t nodeCollector = builder.addPlace(dftVot->nrChildren(), 0, dftVot->name() + "_collector"); uint64_t tFailed = builder.addImmediateTransition(getFailPriority(dftVot), 0.0, dftVot->name() + STR_FAILING);
builder.setPlaceLayoutInfo(nodeCollector, storm::gspn::LayoutInfo(xcenter, ycenter)); builder.addOutputArc(tFailed, failedPlace);
builder.addInhibitionArc(failedPlace, tFailed);
uint64_t tNodeFailed = builder.addImmediateTransition(getFailPriority(dftVot), 0.0, dftVot->name() + STR_FAILING); if (!smart || mDft.isRepresentative(dftVot->id())) {
builder.addOutputArc(tNodeFailed, nodeFailed); uint64_t unavailablePlace = addUnavailablePlace(dftVot, storm::gspn::LayoutInfo(xcenter+6.0, ycenter-3.0));
if (!smart || isRepresentative) { builder.addOutputArc(tFailed, unavailablePlace);
builder.addOutputArc(tNodeFailed, unavailableNode);
} }
builder.addInhibitionArc(nodeFailed, tNodeFailed); uint64_t collectorPlace = builder.addPlace(dftVot->nrChildren(), 0, dftVot->name() + "_collector");
builder.addInputArc(nodeCollector, tNodeFailed, dftVot->threshold()); builder.setPlaceLayoutInfo(collectorPlace, storm::gspn::LayoutInfo(xcenter, ycenter));
uint64_t i = 0; builder.addInputArc(collectorPlace, tFailed, dftVot->threshold());
for (auto const& child : dftVot->children()) { for (size_t i = 0; i < dftVot->nrChildren(); ++i) {
uint64_t childInhibPlace = builder.addPlace(1, 0, dftVot->name() + "_child_fail_inhib" + std::to_string(i)); auto const& child = dftVot->children().at(i);
uint64_t childNextPlace = builder.addPlace(defaultCapacity, 1, dftVot->name() + "_child_next" + std::to_string(i));
uint64_t tCollect = builder.addImmediateTransition(getFailPriority(dftVot), 0.0, dftVot->name() + "_child_collect" + std::to_string(i)); uint64_t tCollect = builder.addImmediateTransition(getFailPriority(dftVot), 0.0, dftVot->name() + "_child_collect" + std::to_string(i));
builder.addOutputArc(tCollect, nodeCollector); builder.addOutputArc(tCollect, collectorPlace);
builder.addOutputArc(tCollect, childInhibPlace); builder.addInputArc(childNextPlace, tCollect);
builder.addInhibitionArc(childInhibPlace, tCollect); builder.addInputArc(getFailedPlace(child), tCollect);
builder.addInputArc(failedNodes[child->id()], tCollect); builder.addOutputArc(tCollect, getFailedPlace(child));
builder.addOutputArc(tCollect, failedNodes[child->id()]);
++i;
} }
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawPAND(std::shared_ptr<storm::storage::DFTPand<ValueType> const> dftPand, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translatePAND(std::shared_ptr<storm::storage::DFTPand<ValueType> const> dftPand, bool inclusive) {
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftPand->name() + STR_FAILED);
assert(failedNodes.size() == dftPand->id());
failedNodes.push_back(nodeFailed);
double xcenter = mDft.getElementLayoutInfo(dftPand->id()).x; double xcenter = mDft.getElementLayoutInfo(dftPand->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftPand->id()).y; double ycenter = mDft.getElementLayoutInfo(dftPand->id()).y;
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter+3.0, ycenter-3.0));
uint64_t unavailableNode = 0; uint64_t failedPlace = addFailedPlace(dftPand, storm::gspn::LayoutInfo(xcenter+3.0, ycenter-3.0));
if (!smart || isRepresentative) {
unavailableNode = addUnavailableNode(dftPand, storm::gspn::LayoutInfo(xcenter+9.0, ycenter-3.0));
}
uint64_t tNodeFailed = builder.addImmediateTransition(getFailPriority(dftPand), 0.0, dftPand->name() + STR_FAILING); uint64_t tFailed = builder.addImmediateTransition(getFailPriority(dftPand), 0.0, dftPand->name() + STR_FAILING);
builder.setTransitionLayoutInfo(tNodeFailed, storm::gspn::LayoutInfo(xcenter+3.0, ycenter+3.0)); builder.setTransitionLayoutInfo(tFailed, storm::gspn::LayoutInfo(xcenter+3.0, ycenter+3.0));
builder.addInhibitionArc(nodeFailed, tNodeFailed); builder.addInhibitionArc(failedPlace, tFailed);
builder.addOutputArc(tNodeFailed, nodeFailed); builder.addOutputArc(tFailed, failedPlace);
if (!smart || isRepresentative) { if (!smart || mDft.isRepresentative(dftPand->id())) {
builder.addOutputArc(tNodeFailed, unavailableNode); uint64_t unavailablePlace = addUnavailablePlace(dftPand, storm::gspn::LayoutInfo(xcenter+9.0, ycenter-3.0));
builder.addOutputArc(tFailed, unavailablePlace);
} }
if(dftPand->isInclusive()) { if (inclusive) {
// Inclusive PAND // Inclusive PAND
uint64_t nodeFS = builder.addPlace(defaultCapacity, 0, dftPand->name() + STR_FAILSAVE); uint64_t failSafePlace = builder.addPlace(defaultCapacity, 0, dftPand->name() + STR_FAILSAVE);
builder.setPlaceLayoutInfo(nodeFS, storm::gspn::LayoutInfo(xcenter-3.0, ycenter-3.0)); builder.setPlaceLayoutInfo(failSafePlace, storm::gspn::LayoutInfo(xcenter-3.0, ycenter-3.0));
builder.addInhibitionArc(failSafePlace, tFailed);
builder.addInhibitionArc(nodeFS, tNodeFailed); // Transitions for failed place
// Transition for failed
for (auto const& child : dftPand->children()) { for (auto const& child : dftPand->children()) {
builder.addInputArc(failedNodes[child->id()], tNodeFailed); builder.addInputArc(getFailedPlace(child), tFailed);
builder.addOutputArc(tNodeFailed, failedNodes[child->id()]); builder.addOutputArc(tFailed, getFailedPlace(child));
} }
// Transitions for fail-safe // Transitions for fail-safe place
for (uint64_t j = 1; j < dftPand->nrChildren(); ++j) { for (uint64_t i = 1; i < dftPand->nrChildren(); ++i) {
uint64_t tfs = builder.addImmediateTransition(getFailPriority(dftPand), 0.0, dftPand->name() + STR_FAILSAVING + std::to_string(j)); auto const& child = dftPand->children().at(i);
builder.setTransitionLayoutInfo(tfs, storm::gspn::LayoutInfo(xcenter-6.0+j*3.0, ycenter+3.0)); uint64_t tFailSafe = builder.addImmediateTransition(getFailPriority(dftPand), 0.0, dftPand->name() + STR_FAILSAVING + std::to_string(i));
builder.setTransitionLayoutInfo(tFailSafe, storm::gspn::LayoutInfo(xcenter-6.0+i*3.0, ycenter+3.0));
builder.addInputArc(failedNodes[dftPand->children().at(j)->id()], tfs);
builder.addOutputArc(tfs, failedNodes[dftPand->children().at(j)->id()]);
builder.addInhibitionArc(failedNodes[dftPand->children().at(j-1)->id()], tfs);
builder.addOutputArc(tfs, nodeFS);
builder.addInhibitionArc(nodeFS, tfs);
builder.addInputArc(getFailedPlace(child), tFailSafe);
builder.addOutputArc(tFailSafe, getFailedPlace(child));
builder.addInhibitionArc(getFailedPlace(dftPand->children().at(i-1)), tFailSafe);
builder.addOutputArc(tFailSafe, failSafePlace);
builder.addInhibitionArc(failSafePlace, tFailSafe);
} }
} else { } else {
// Exclusive PAND // Exclusive PAND
uint64_t fi = 0; uint64_t failSafeXPlace = 0;
uint64_t tn = 0; uint64_t tFailSafeX = 0;
for(uint64_t j = 0; j < dftPand->nrChildren(); ++j) { for (size_t i = 0; i < dftPand->nrChildren(); ++i) {
auto const& child = dftPand->children()[j]; auto const& child = dftPand->children().at(i);
if (j > 0) { if (i > 0) {
builder.addInhibitionArc(failedNodes.at(child->id()), tn); // Set inhibition arc to previous transition
} builder.addInhibitionArc(getFailedPlace(child), tFailSafeX);
if (j != dftPand->nrChildren() - 1) { }
if (i < dftPand->nrChildren() - 1) {
// Not last child // Not last child
tn = builder.addImmediateTransition(getFailPriority(dftPand), 0.0, dftPand->name() + STR_FAILING + "_" +std::to_string(j)); tFailSafeX = builder.addImmediateTransition(getFailPriority(dftPand), 0.0, dftPand->name() + STR_FAILING + "_" +std::to_string(i));
builder.setTransitionLayoutInfo(tn, storm::gspn::LayoutInfo(xcenter-3.0, ycenter+3.0)); builder.setTransitionLayoutInfo(tFailSafeX, storm::gspn::LayoutInfo(xcenter-3.0, ycenter+3.0));
} else { } else {
// Last child // Last child
tn = tNodeFailed; tFailSafeX = tFailed;
}
builder.addInputArc(failedNodes.at(child->id()), tn);
builder.addOutputArc(tn, failedNodes.at(child->id()));
if (j > 0) {
builder.addInputArc(fi, tn);
} }
if (j != dftPand->nrChildren() - 1) { builder.addInputArc(getFailedPlace(child), tFailSafeX);
fi = builder.addPlace(defaultCapacity, 0, dftPand->name() + "_F_" + std::to_string(j)); builder.addOutputArc(tFailSafeX, getFailedPlace(child));
builder.setPlaceLayoutInfo(fi, storm::gspn::LayoutInfo(xcenter-3.0+j*3.0, ycenter)); if (i > 0) {
builder.addOutputArc(tn, fi); builder.addInputArc(failSafeXPlace, tFailSafeX);
} }
if (i < dftPand->nrChildren() - 1) {
// Add fail-safe X place
failSafeXPlace = builder.addPlace(defaultCapacity, 0, dftPand->name() + "_F_" + std::to_string(i));
builder.setPlaceLayoutInfo(failSafeXPlace, storm::gspn::LayoutInfo(xcenter-3.0+i*3.0, ycenter));
builder.addOutputArc(tFailSafeX, failSafeXPlace);
builder.addInhibitionArc(failSafeXPlace, tFailSafeX);
}
} }
} }
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawPOR(std::shared_ptr<storm::storage::DFTPor<ValueType> const> dftPor, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translatePOR(std::shared_ptr<storm::storage::DFTPor<ValueType> const> dftPor, bool inclusive) {
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftPor->name() + STR_FAILED);
failedNodes.push_back(nodeFailed);
double xcenter = mDft.getElementLayoutInfo(dftPor->id()).x; double xcenter = mDft.getElementLayoutInfo(dftPor->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftPor->id()).y; double ycenter = mDft.getElementLayoutInfo(dftPor->id()).y;
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter+3.0, ycenter-3.0));
uint64_t unavailableNode = 0; uint64_t failedPlace = addFailedPlace(dftPor, storm::gspn::LayoutInfo(xcenter+3.0, ycenter-3.0));
if (!smart || isRepresentative) {
unavailableNode = addUnavailableNode(dftPor, storm::gspn::LayoutInfo(xcenter+9.0, ycenter-3.0));
}
uint64_t tfail = builder.addImmediateTransition(getFailPriority(dftPor), 0.0, dftPor->name() + STR_FAILING); uint64_t tFailed = builder.addImmediateTransition(getFailPriority(dftPor), 0.0, dftPor->name() + STR_FAILING);
builder.setTransitionLayoutInfo(tfail, storm::gspn::LayoutInfo(xcenter+3.0, ycenter+3.0)); builder.setTransitionLayoutInfo(tFailed, storm::gspn::LayoutInfo(xcenter+3.0, ycenter+3.0));
builder.addOutputArc(tfail, nodeFailed); builder.addOutputArc(tFailed, failedPlace);
builder.addInhibitionArc(nodeFailed, tfail); builder.addInhibitionArc(failedPlace, tFailed);
builder.addInputArc(failedNodes.at(dftPor->children().front()->id()), tfail); // Arcs from first child
builder.addOutputArc(tfail, failedNodes.at(dftPor->children().front()->id())); builder.addInputArc(getFailedPlace(dftPor->children().front()), tFailed);
builder.addOutputArc(tFailed, getFailedPlace(dftPor->children().front()));
if(!smart || isRepresentative) { if (!smart || mDft.isRepresentative(dftPor->id())) {
builder.addOutputArc(tfail, unavailableNode); uint64_t unavailablePlace = addUnavailablePlace(dftPor, storm::gspn::LayoutInfo(xcenter+9.0, ycenter-3.0));
builder.addOutputArc(tFailed, unavailablePlace);
} }
if(dftPor->isInclusive()) { if (inclusive) {
// Inclusive POR // Inclusive POR
uint64_t nodeFS = builder.addPlace(defaultCapacity, 0, dftPor->name() + STR_FAILSAVE); uint64_t failSafePlace = builder.addPlace(defaultCapacity, 0, dftPor->name() + STR_FAILSAVE);
builder.setPlaceLayoutInfo(nodeFS, storm::gspn::LayoutInfo(xcenter-3.0, ycenter-3.0)); builder.setPlaceLayoutInfo(failSafePlace, storm::gspn::LayoutInfo(xcenter-3.0, ycenter-3.0));
builder.addInhibitionArc(nodeFS, tfail); builder.addInhibitionArc(failSafePlace, tFailed);
uint64_t j = 0; // For all children except the first one
for (auto const& child : dftPor->children()) { for (size_t i = 1; i < dftPor->nrChildren(); ++i) {
if(j > 0) { auto const& child = dftPor->children().at(i);
uint64_t tfailsf = builder.addImmediateTransition(getFailPriority(dftPor), 0.0, dftPor->name() + STR_FAILSAVING + std::to_string(j)); uint64_t tFailSafe = builder.addImmediateTransition(getFailPriority(dftPor), 0.0, dftPor->name() + STR_FAILSAVING + std::to_string(i));
builder.setTransitionLayoutInfo(tfailsf, storm::gspn::LayoutInfo(xcenter-3.0+j*3.0, ycenter+3.0)); builder.setTransitionLayoutInfo(tFailSafe, storm::gspn::LayoutInfo(xcenter-3.0+i*3.0, ycenter+3.0));
builder.addInputArc(failedNodes.at(child->id()), tfailsf); builder.addInputArc(getFailedPlace(child), tFailSafe);
builder.addOutputArc(tfailsf, failedNodes.at(child->id())); builder.addOutputArc(tFailSafe, getFailedPlace(child));
builder.addOutputArc(tfailsf, nodeFS); builder.addOutputArc(tFailSafe, failSafePlace);
builder.addInhibitionArc(nodeFS, tfailsf); builder.addInhibitionArc(failSafePlace, tFailSafe);
builder.addInhibitionArc(failedNodes.at(dftPor->children().front()->id()), tfailsf); builder.addInhibitionArc(getFailedPlace(dftPor->children().front()), tFailSafe);
}
++j;
} }
} else { } else {
// Exclusive POR // Exclusive POR
uint64_t j = 0; // For all children except the first one
for (auto const& child : dftPor->children()) { for (auto const& child : dftPor->children()) {
if(j > 0) { builder.addInhibitionArc(getFailedPlace(child), tFailed);
builder.addInhibitionArc(failedNodes.at(child->id()), tfail);
}
++j;
} }
} }
@ -372,212 +371,199 @@ namespace storm {
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawSPARE(std::shared_ptr<storm::storage::DFTSpare<ValueType> const> dftSpare, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translateSPARE(std::shared_ptr<storm::storage::DFTSpare<ValueType> const> dftSpare) {
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftSpare->name() + STR_FAILED);
failedNodes.push_back(nodeFailed);
double xcenter = mDft.getElementLayoutInfo(dftSpare->id()).x; double xcenter = mDft.getElementLayoutInfo(dftSpare->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftSpare->id()).y; double ycenter = mDft.getElementLayoutInfo(dftSpare->id()).y;
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter+10.0, ycenter-8.0));
uint64_t unavailableNode = 0; uint64_t failedPlace = addFailedPlace(dftSpare, storm::gspn::LayoutInfo(xcenter+10.0, ycenter-8.0));
bool isRepresentative = mDft.isRepresentative(dftSpare->id());
uint64_t unavailablePlace = 0;
if (!smart || isRepresentative) { if (!smart || isRepresentative) {
unavailableNode = addUnavailableNode(dftSpare, storm::gspn::LayoutInfo(xcenter+16.0, ycenter-8.0)); unavailablePlace = addUnavailablePlace(dftSpare, storm::gspn::LayoutInfo(xcenter+16.0, ycenter-8.0));
} }
uint64_t spareActive = builder.addPlace(defaultCapacity, isActiveInitially(dftSpare) ? 1 : 0, dftSpare->name() + STR_ACTIVATED);
builder.setPlaceLayoutInfo(spareActive, storm::gspn::LayoutInfo(xcenter-20.0, ycenter-12.0));
activeNodes.emplace(dftSpare->id(), spareActive);
std::vector<uint64_t> nextclTransitions; uint64_t activePlace = builder.addPlace(defaultCapacity, isActiveInitially(dftSpare) ? 1 : 0, dftSpare->name() + STR_ACTIVATED);
std::vector<uint64_t> nextconsiderTransitions; builder.setPlaceLayoutInfo(activePlace, storm::gspn::LayoutInfo(xcenter-20.0, ycenter-12.0));
uint64_t j = 0; activePlaces.emplace(dftSpare->id(), activePlace);
for(auto const& child : dftSpare->children()) { std::vector<uint64_t> tNextClaims;
std::vector<uint64_t> tNextConsiders;
for (size_t i = 0; i < dftSpare->nrChildren(); ++i) {
auto const& child = dftSpare->children().at(i);
// Consider next child // Consider next child
size_t nodeConsider = builder.addPlace(defaultCapacity, j == 0 ? 1 : 0, dftSpare->name()+ "_consider_" + child->name()); size_t considerPlace = builder.addPlace(defaultCapacity, i == 0 ? 1 : 0, dftSpare->name()+ "_consider_" + child->name());
builder.setPlaceLayoutInfo(nodeConsider, storm::gspn::LayoutInfo(xcenter-15.0+j*14.0, ycenter-8.0)); builder.setPlaceLayoutInfo(considerPlace, storm::gspn::LayoutInfo(xcenter-15.0+i*14.0, ycenter-8.0));
if (j > 0) { if (i > 0) {
// Set output transition from previous next_claim // Set output transition from previous next_claim
builder.addOutputArc(nextclTransitions.back(), nodeConsider); builder.addOutputArc(tNextClaims.back(), considerPlace);
// Set output transition from previous cannot_claim // Set output transition from previous cannot_claim
builder.addOutputArc(nextconsiderTransitions.back(), nodeConsider); builder.addOutputArc(tNextConsiders.back(), considerPlace);
} }
// Cannot claim child // Cannot claim child
uint64_t tnextconsider = builder.addImmediateTransition(getFailPriority(dftSpare), 0.0, dftSpare->name() + "_cannot_claim_" + child->name()); uint64_t tConsiderNext = builder.addImmediateTransition(getFailPriority(dftSpare), 0.0, dftSpare->name() + "_cannot_claim_" + child->name());
builder.setTransitionLayoutInfo(tnextconsider, storm::gspn::LayoutInfo(xcenter-7.0+j*14.0, ycenter-8.0)); builder.setTransitionLayoutInfo(tConsiderNext, storm::gspn::LayoutInfo(xcenter-7.0+i*14.0, ycenter-8.0));
builder.addInputArc(nodeConsider, tnextconsider); builder.addInputArc(considerPlace, tConsiderNext);
builder.addInputArc(unavailableNodes.at(child->id()), tnextconsider); builder.addInputArc(unavailablePlaces.at(child->id()), tConsiderNext);
builder.addOutputArc(tnextconsider, unavailableNodes.at(child->id())); builder.addOutputArc(tConsiderNext, unavailablePlaces.at(child->id()));
nextconsiderTransitions.push_back(tnextconsider); tNextConsiders.push_back(tConsiderNext);
// Claimed child // Claimed child
size_t nodeCUC = builder.addPlace(defaultCapacity, 0, dftSpare->name() + "_claimed_" + child->name()); size_t claimedPlace = builder.addPlace(defaultCapacity, 0, dftSpare->name() + "_claimed_" + child->name());
builder.setPlaceLayoutInfo(nodeCUC, storm::gspn::LayoutInfo(xcenter-15.0+j*14.0, ycenter+5.0)); builder.setPlaceLayoutInfo(claimedPlace, storm::gspn::LayoutInfo(xcenter-15.0+i*14.0, ycenter+5.0));
uint64_t tclaim = builder.addImmediateTransition(getFailPriority(dftSpare), 0.0, dftSpare->name() + "_claim_" + child->name()); uint64_t tClaim = builder.addImmediateTransition(getFailPriority(dftSpare), 0.0, dftSpare->name() + "_claim_" + child->name());
builder.setTransitionLayoutInfo(tclaim, storm::gspn::LayoutInfo(xcenter-15.0+j*14.0, ycenter)); builder.setTransitionLayoutInfo(tClaim, storm::gspn::LayoutInfo(xcenter-15.0+i*14.0, ycenter));
builder.addInhibitionArc(unavailableNodes.at(child->id()), tclaim); builder.addInhibitionArc(unavailablePlaces.at(child->id()), tClaim);
builder.addInputArc(nodeConsider, tclaim); builder.addInputArc(considerPlace, tClaim);
builder.addOutputArc(tclaim, nodeCUC); builder.addOutputArc(tClaim, claimedPlace);
builder.addOutputArc(tclaim, unavailableNodes.at(child->id())); builder.addOutputArc(tClaim, unavailablePlaces.at(child->id()));
// Claim next // Claim next
uint64_t tnextcl = builder.addImmediateTransition(getFailPriority(dftSpare), 0.0, dftSpare->name() + "_next_claim_" + std::to_string(j)); uint64_t tClaimNext = builder.addImmediateTransition(getFailPriority(dftSpare), 0.0, dftSpare->name() + "_next_claim_" + std::to_string(i));
builder.setTransitionLayoutInfo(tnextcl, storm::gspn::LayoutInfo(xcenter-7.0+j*14.0, ycenter+5.0)); builder.setTransitionLayoutInfo(tClaimNext, storm::gspn::LayoutInfo(xcenter-7.0+i*14.0, ycenter+5.0));
builder.addInputArc(nodeCUC, tnextcl); builder.addInputArc(claimedPlace, tClaimNext);
builder.addInputArc(failedNodes.at(child->id()), tnextcl); builder.addInputArc(getFailedPlace(child), tClaimNext);
builder.addOutputArc(tnextcl, failedNodes.at(child->id())); builder.addOutputArc(tClaimNext, getFailedPlace(child));
nextclTransitions.push_back(tnextcl); tNextClaims.push_back(tClaimNext);
// Activate all elements in spare module
++j;
// Activate all nodes in spare module
uint64_t l = 0; uint64_t l = 0;
for (uint64_t k : mDft.module(child->id())) { for (uint64_t k : mDft.module(child->id())) {
uint64_t tactive = builder.addImmediateTransition(defaultPriority, 0.0, dftSpare->name() + "_activate_" + std::to_string(j) + "_" + std::to_string(k)); uint64_t tActivate = builder.addImmediateTransition(defaultPriority, 0.0, dftSpare->name() + "_activate_" + std::to_string(i) + "_" + std::to_string(k));
builder.setTransitionLayoutInfo(tactive, storm::gspn::LayoutInfo(xcenter-18.0+(j+l)*3, ycenter-12.0)); builder.setTransitionLayoutInfo(tActivate, storm::gspn::LayoutInfo(xcenter-18.0+(i+l)*3, ycenter-12.0));
builder.addInhibitionArc(activeNodes.at(k), tactive); builder.addInhibitionArc(activePlaces.at(k), tActivate);
builder.addInputArc(nodeCUC, tactive); builder.addInputArc(claimedPlace, tActivate);
builder.addInputArc(spareActive, tactive); builder.addInputArc(activePlace, tActivate);
builder.addOutputArc(tactive, nodeCUC); builder.addOutputArc(tActivate, claimedPlace);
builder.addOutputArc(tactive, spareActive); builder.addOutputArc(tActivate, activePlace);
builder.addOutputArc(tactive, activeNodes.at(k)); builder.addOutputArc(tActivate, activePlaces.at(k));
++l; ++l;
} }
} }
// Set arcs to failed // Set arcs to failed
builder.addOutputArc(nextconsiderTransitions.back(), nodeFailed); builder.addOutputArc(tNextConsiders.back(), failedPlace);
builder.addOutputArc(nextclTransitions.back(), nodeFailed); builder.addOutputArc(tNextClaims.back(), failedPlace);
if (!smart || isRepresentative) { if (!smart || isRepresentative) {
builder.addOutputArc(nextconsiderTransitions.back(), unavailableNode); builder.addOutputArc(tNextConsiders.back(), unavailablePlace);
builder.addOutputArc(nextclTransitions.back(), unavailableNode); builder.addOutputArc(tNextClaims.back(), unavailablePlace);
} }
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawCONSTF(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstF, bool isRepresentative) { void DftToGspnTransformator<ValueType>::translatePDEP(std::shared_ptr<storm::storage::DFTDependency<ValueType> const> dftDependency) {
failedNodes.push_back(builder.addPlace(defaultCapacity, 1, dftConstF->name() + STR_FAILED));
uint64_t unavailableNode = 0;
if (isRepresentative) {
// TODO set position
unavailableNode = addUnavailableNode(dftConstF, storm::gspn::LayoutInfo(0, 0), false);
}
}
//
template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawCONSTS(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstS, bool isRepresentative) {
// storm::gspn::Place placeCONSTSFailed;
// placeCONSTSFailed.setName(dftConstS->name() + STR_FAILED);
// placeCONSTSFailed.setNumberOfInitialTokens(0);
// placeCONSTSFailed.setCapacity(0); // It cannot contain a token, because it cannot fail.
// mGspn.addPlace(placeCONSTSFailed);
}
//
template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawPDEP(std::shared_ptr<storm::storage::DFTDependency<ValueType> const> dftDependency) {
double xcenter = mDft.getElementLayoutInfo(dftDependency->id()).x; double xcenter = mDft.getElementLayoutInfo(dftDependency->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftDependency->id()).y; double ycenter = mDft.getElementLayoutInfo(dftDependency->id()).y;
if (!smart) { if (!smart) {
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftDependency->name() + STR_FAILED); addFailedPlace(dftDependency, storm::gspn::LayoutInfo(xcenter+10.0, ycenter-8.0));
failedNodes.push_back(nodeFailed); addUnavailablePlace(dftDependency, storm::gspn::LayoutInfo(xcenter+16.0, ycenter-8.0));
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter+10.0, ycenter-8.0));
addUnavailableNode(dftDependency, storm::gspn::LayoutInfo(xcenter+16.0, ycenter-8.0));
} }
uint64_t forwardPlace = 0;
if (dftDependency->probability() < 1.0) {
// PDEP
forwardPlace = builder.addPlace(defaultCapacity, 0, dftDependency->name() + "_forward");
builder.setPlaceLayoutInfo(forwardPlace, storm::gspn::LayoutInfo(xcenter+1.0, ycenter+2.0));
uint64_t coinPlace = builder.addPlace(defaultCapacity, 1, dftDependency->name() + "_coin"); uint64_t coinPlace = builder.addPlace(defaultCapacity, 1, dftDependency->name() + "_coin");
builder.setPlaceLayoutInfo(coinPlace, storm::gspn::LayoutInfo(xcenter-5.0, ycenter+2.0)); builder.setPlaceLayoutInfo(coinPlace, storm::gspn::LayoutInfo(xcenter-5.0, ycenter+2.0));
uint64_t t1 = builder.addImmediateTransition(defaultPriority, 0.0, dftDependency->name() + "_start_flip");
builder.addInputArc(coinPlace, t1); uint64_t tStartFlip = builder.addImmediateTransition(defaultPriority, 0.0, dftDependency->name() + "_start_flip");
builder.addInputArc(failedNodes.at(dftDependency->triggerEvent()->id()), t1); builder.addInputArc(coinPlace, tStartFlip);
builder.addOutputArc(t1, failedNodes.at(dftDependency->triggerEvent()->id())); builder.addInputArc(getFailedPlace(dftDependency->triggerEvent()), tStartFlip);
uint64_t forwardPlace = builder.addPlace(defaultCapacity, 0, dftDependency->name() + "_forward"); builder.addOutputArc(tStartFlip, getFailedPlace(dftDependency->triggerEvent()));
builder.setPlaceLayoutInfo(forwardPlace, storm::gspn::LayoutInfo(xcenter+1.0, ycenter+2.0));
if (!smart || dftDependency->probability() < 1.0) {
uint64_t flipPlace = builder.addPlace(defaultCapacity, 0, dftDependency->name() + "_flip"); uint64_t flipPlace = builder.addPlace(defaultCapacity, 0, dftDependency->name() + "_flip");
builder.addOutputArc(t1, flipPlace);
builder.setPlaceLayoutInfo(flipPlace, storm::gspn::LayoutInfo(xcenter-2.0, ycenter+2.0)); builder.setPlaceLayoutInfo(flipPlace, storm::gspn::LayoutInfo(xcenter-2.0, ycenter+2.0));
uint64_t t2 = builder.addImmediateTransition(defaultPriority, dftDependency->probability(), "_win_flip"); builder.addOutputArc(tStartFlip, flipPlace);
builder.addInputArc(flipPlace, t2); uint64_t tWinFlip = builder.addImmediateTransition(defaultPriority, dftDependency->probability(), "_win_flip");
builder.addOutputArc(t2, forwardPlace); builder.addInputArc(flipPlace, tWinFlip);
if (dftDependency->probability() < 1.0) { builder.addOutputArc(tWinFlip, forwardPlace);
uint64_t t3 = builder.addImmediateTransition(defaultPriority, 1 - dftDependency->probability(), "_loose_flip"); uint64_t tLooseFlip = builder.addImmediateTransition(defaultPriority, storm::utility::one<ValueType>() - dftDependency->probability(), "_loose_flip");
builder.addInputArc(flipPlace, t3); builder.addInputArc(flipPlace, tLooseFlip);
}
} else { } else {
builder.addOutputArc(t1, forwardPlace); // FDEP
forwardPlace = getFailedPlace(dftDependency->triggerEvent());
} }
for(auto const& depEv : dftDependency->dependentEvents()) { for (auto const& child : dftDependency->dependentEvents()) {
uint64_t tx = builder.addImmediateTransition(defaultPriority, 0.0, dftDependency->name() + "_propagate_" + depEv->name()); uint64_t tForwardFailure = builder.addImmediateTransition(defaultPriority, 0.0, dftDependency->name() + "_propagate_" + child->name());
builder.addInputArc(forwardPlace, tx); builder.addInputArc(forwardPlace, tForwardFailure);
builder.addOutputArc(tx, forwardPlace); builder.addOutputArc(tForwardFailure, forwardPlace);
builder.addOutputArc(tx, failedNodes.at(depEv->id())); builder.addOutputArc(tForwardFailure, getFailedPlace(child));
builder.addInhibitionArc(failedNodes.at(depEv->id()), tx); builder.addInhibitionArc(getFailedPlace(child), tForwardFailure);
if (!smart || depEv->nrRestrictions() > 0) { if (!smart || child->nrRestrictions() > 0) {
builder.addInhibitionArc(disabledNodes.at(depEv->id()), tx); builder.addInhibitionArc(disabledPlaces.at(child->id()), tForwardFailure);
} }
if (!smart || mDft.isRepresentative(depEv->id())) { if (!smart || mDft.isRepresentative(child->id())) {
builder.addOutputArc(tx, unavailableNodes.at(depEv->id())); builder.addOutputArc(tForwardFailure, unavailablePlaces.at(child->id()));
} }
} }
} }
template <typename ValueType> template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawSeq(std::shared_ptr<storm::storage::DFTSeq<ValueType> const> dftSeq) { void DftToGspnTransformator<ValueType>::translateSeq(std::shared_ptr<storm::storage::DFTSeq<ValueType> const> dftSeq) {
STORM_LOG_THROW(dftSeq->allChildrenBEs(), storm::exceptions::NotImplementedException, "Sequence enforcers with gates as children are currently not supported"); STORM_LOG_THROW(dftSeq->allChildrenBEs(), storm::exceptions::NotImplementedException, "Sequence enforcers with gates as children are currently not supported");
double xcenter = mDft.getElementLayoutInfo(dftSeq->id()).x; double xcenter = mDft.getElementLayoutInfo(dftSeq->id()).x;
double ycenter = mDft.getElementLayoutInfo(dftSeq->id()).y; double ycenter = mDft.getElementLayoutInfo(dftSeq->id()).y;
if (!smart) { if (!smart) {
uint64_t nodeFailed = builder.addPlace(defaultCapacity, 0, dftSeq->name() + STR_FAILED); addFailedPlace(dftSeq, storm::gspn::LayoutInfo(xcenter+10.0, ycenter-8.0));
failedNodes.push_back(nodeFailed); addUnavailablePlace(dftSeq, storm::gspn::LayoutInfo(xcenter+16.0, ycenter-8.0));
builder.setPlaceLayoutInfo(nodeFailed, storm::gspn::LayoutInfo(xcenter+10.0, ycenter-8.0));
addUnavailableNode(dftSeq, storm::gspn::LayoutInfo(xcenter+16.0, ycenter-8.0));
} }
uint64_t j = 0;
uint64_t tEnable = 0; uint64_t tEnable = 0;
uint64_t nextPlace = 0; uint64_t nextPlace = 0;
for(auto const& child : dftSeq->children()) { for (size_t i = 0; i < dftSeq->nrChildren(); ++i) {
nextPlace = builder.addPlace(defaultCapacity, j==0 ? 1 : 0, dftSeq->name() + "_next_" + child->name()); auto const& child = dftSeq->children().at(i);
builder.setPlaceLayoutInfo(nextPlace, storm::gspn::LayoutInfo(xcenter-5.0+j*3.0, ycenter-3.0)); nextPlace = builder.addPlace(defaultCapacity, i==0 ? 1 : 0, dftSeq->name() + "_next_" + child->name());
if (j>0) { builder.setPlaceLayoutInfo(nextPlace, storm::gspn::LayoutInfo(xcenter-5.0+i*3.0, ycenter-3.0));
if (i>0) {
builder.addOutputArc(tEnable, nextPlace); builder.addOutputArc(tEnable, nextPlace);
} }
tEnable = builder.addImmediateTransition(defaultPriority, 0.0, dftSeq->name() + "_unblock_" +child->name()); tEnable = builder.addImmediateTransition(defaultPriority, 0.0, dftSeq->name() + "_unblock_" +child->name());
builder.setTransitionLayoutInfo(tEnable, storm::gspn::LayoutInfo(xcenter-5.0+j*3.0, ycenter+3.0)); builder.setTransitionLayoutInfo(tEnable, storm::gspn::LayoutInfo(xcenter-5.0+i*3.0, ycenter+3.0));
builder.addInputArc(nextPlace, tEnable); builder.addInputArc(nextPlace, tEnable);
builder.addInputArc(disabledNodes.at(child->id()), tEnable); builder.addInputArc(disabledPlaces.at(child->id()), tEnable);
if (j>0) { if (i>0) {
builder.addInputArc(failedNodes.at(dftSeq->children().at(j-1)->id()), tEnable); builder.addInputArc(getFailedPlace(dftSeq->children().at(i-1)), tEnable);
} }
++j;
} }
} }
template<typename ValueType> template<typename ValueType>
uint64_t DftToGspnTransformator<ValueType>::addUnavailableNode(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftElement, storm::gspn::LayoutInfo const& layoutInfo, bool initialAvailable) { uint64_t DftToGspnTransformator<ValueType>::addFailedPlace(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftElement, storm::gspn::LayoutInfo const& layoutInfo, bool initialFailed) {
uint64_t unavailableNode = builder.addPlace(defaultCapacity, initialAvailable ? 0 : 1, dftElement->name() + "_unavail"); uint64_t failedPlace = builder.addPlace(defaultCapacity, initialFailed ? 1 : 0, dftElement->name() + STR_FAILED);
assert(unavailableNode != 0); assert(failedPlaces.size() == dftElement->id());
unavailableNodes.emplace(dftElement->id(), unavailableNode); failedPlaces.push_back(failedPlace);
builder.setPlaceLayoutInfo(unavailableNode, layoutInfo); builder.setPlaceLayoutInfo(failedPlace, layoutInfo);
return unavailableNode; return failedPlace;
}
template<typename ValueType>
uint64_t DftToGspnTransformator<ValueType>::addUnavailablePlace(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftElement, storm::gspn::LayoutInfo const& layoutInfo, bool initialAvailable) {
uint64_t unavailablePlace = builder.addPlace(defaultCapacity, initialAvailable ? 0 : 1, dftElement->name() + "_unavail");
unavailablePlaces.emplace(dftElement->id(), unavailablePlace);
builder.setPlaceLayoutInfo(unavailablePlace, layoutInfo);
return unavailablePlace;
} }
template<typename ValueType> template<typename ValueType>
uint64_t DftToGspnTransformator<ValueType>::addDisabledPlace(std::shared_ptr<const storm::storage::DFTBE<ValueType> > dftBe, storm::gspn::LayoutInfo const& layoutInfo) { uint64_t DftToGspnTransformator<ValueType>::addDisabledPlace(std::shared_ptr<const storm::storage::DFTBE<ValueType> > dftBe, storm::gspn::LayoutInfo const& layoutInfo) {
uint64_t disabledNode = builder.addPlace(dftBe->nrRestrictions(), dftBe->nrRestrictions(), dftBe->name() + "_dabled"); uint64_t disabledPlace = builder.addPlace(dftBe->nrRestrictions(), dftBe->nrRestrictions(), dftBe->name() + "_dabled");
assert(disabledNode != 0); disabledPlaces.emplace(dftBe->id(), disabledPlace);
disabledNodes.emplace(dftBe->id(), disabledNode); builder.setPlaceLayoutInfo(disabledPlace, layoutInfo);
builder.setPlaceLayoutInfo(disabledNode, layoutInfo); return disabledPlace;
return disabledNode;
} }
template <typename ValueType> template <typename ValueType>
@ -595,20 +581,9 @@ namespace storm {
} }
template <typename ValueType>
void DftToGspnTransformator<ValueType>::drawGSPNRestrictions() {
// TODO
}
template <typename ValueType>
gspn::GSPN* DftToGspnTransformator<ValueType>::obtainGSPN() {
return builder.buildGspn();
}
// Explicitly instantiate the class. // Explicitly instantiate the class.
template class DftToGspnTransformator<double>; template class DftToGspnTransformator<double>;
#ifdef STORM_HAVE_CARL #ifdef STORM_HAVE_CARL
// template class DftToGspnTransformator<storm::RationalFunction>; // template class DftToGspnTransformator<storm::RationalFunction>;
#endif #endif

160
src/storm-dft/transformations/DftToGspnTransformator.h

@ -33,101 +33,106 @@ namespace storm {
*/ */
gspn::GSPN* obtainGSPN(); gspn::GSPN* obtainGSPN();
/*!
* Get failed place id of top level element.
*/
uint64_t toplevelFailedPlaceId(); uint64_t toplevelFailedPlaceId();
private: private:
/* /*!
* Draw all elements of the GSPN. * Translate all elements of the GSPN.
*/
void translateGSPNElements();
/*!
* Translate a GSPN Basic Event.
*
* @param dftBE The Basic Event.
*/ */
void drawGSPNElements(); void translateBE(std::shared_ptr<storm::storage::DFTBE<ValueType> const> dftBE);
/* /*!
* Draw restrictions between the elements of the GSPN (i.e. SEQ or MUTEX). * Translate a GSPN CONSTF (Constant Failure, a Basic Event that has already failed).
*
* @param dftPor The CONSTF Basic Event.
*/ */
void drawGSPNRestrictions(); void translateCONSTF(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstF);
/* /*!
* Draw a Petri net Basic Event. * Translate a GSPN CONSTS (Constant Save, a Basic Event that cannot fail).
* *
* @param dftBE The Basic Event. * @param dftPor The CONSTS Basic Event.
*/ */
void drawBE(std::shared_ptr<storm::storage::DFTBE<ValueType> const> dftBE, bool isRepresentative); void translateCONSTS(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstS);
/* /*!
* Draw a Petri net AND. * Translate a GSPN AND.
* *
* @param dftAnd The AND gate. * @param dftAnd The AND gate.
*/ */
void drawAND(std::shared_ptr<storm::storage::DFTAnd<ValueType> const> dftAnd, bool isRepresentative); void translateAND(std::shared_ptr<storm::storage::DFTAnd<ValueType> const> dftAnd);
/* /*!
* Draw a Petri net OR. * Translate a GSPN OR.
* *
* @param dftOr The OR gate. * @param dftOr The OR gate.
*/ */
void drawOR(std::shared_ptr<storm::storage::DFTOr<ValueType> const> dftOr, bool isRepresentative); void translateOR(std::shared_ptr<storm::storage::DFTOr<ValueType> const> dftOr);
/* /*!
* Draw a Petri net VOT. * Translate a GSPN VOT.
* *
* @param dftVot The VOT gate. * @param dftVot The VOT gate.
*/ */
void drawVOT(std::shared_ptr<storm::storage::DFTVot<ValueType> const> dftVot, bool isRepresentative); void translateVOT(std::shared_ptr<storm::storage::DFTVot<ValueType> const> dftVot);
/* /*!
* Draw a Petri net PAND. * Translate a GSPN PAND.
* This PAND is inklusive (children are allowed to fail simultaneously and the PAND will fail nevertheless).
* *
* @param dftPand The PAND gate. * @param dftPand The PAND gate.
* @param inclusive Flag wether the PAND is inclusive (children are allowed to fail simultaneously and the PAND will fail nevertheless)
*/ */
void drawPAND(std::shared_ptr<storm::storage::DFTPand<ValueType> const> dftPand, bool isRepresentative); void translatePAND(std::shared_ptr<storm::storage::DFTPand<ValueType> const> dftPand, bool inclusive = true);
/*
* Draw a Petri net SPARE.
*
* @param dftSpare The SPARE gate.
*/
void drawSPARE(std::shared_ptr<storm::storage::DFTSpare<ValueType> const> dftSpare, bool isRepresentative);
/* /*!
* Draw a Petri net POR. * Translate a GSPN POR.
* This POR is inklusive (children are allowed to fail simultaneously and the POR will fail nevertheless).
* *
* @param dftPor The POR gate. * @param dftPor The POR gate.
* @param inclusive Flag wether the POR is inclusive (children are allowed to fail simultaneously and the POR will fail nevertheless)
*/ */
void drawPOR(std::shared_ptr<storm::storage::DFTPor<ValueType> const> dftPor, bool isRepresentative); void translatePOR(std::shared_ptr<storm::storage::DFTPor<ValueType> const> dftPor, bool inclusive = true);
/* /*!
* Draw a Petri net CONSTF (Constant Failure, a Basic Event that has already failed). * Translate a GSPN SPARE.
* *
* @param dftPor The CONSTF Basic Event. * @param dftSpare The SPARE gate.
*/ */
void drawCONSTF(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstF, bool isRepresentative); void translateSPARE(std::shared_ptr<storm::storage::DFTSpare<ValueType> const> dftSpare);
/* /*!
* Draw a Petri net CONSTS (Constant Save, a Basic Event that cannot fail). * Translate a GSPN PDEP (FDEP is included with a probability of 1).
* *
* @param dftPor The CONSTS Basic Event. * @param dftDependency The PDEP gate.
*/ */
void drawCONSTS(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftConstS, bool isRepresentative); void translatePDEP(std::shared_ptr<storm::storage::DFTDependency<ValueType> const> dftDependency);
/* /*!
* Draw a Petri net PDEP (FDEP is included with a firerate of 1). * Translate a GSPN SEQ.
*
* @param dftSeq The SEQ gate.
*/ */
void drawPDEP(std::shared_ptr<storm::storage::DFTDependency<ValueType> const> dftDependency); void translateSeq(std::shared_ptr<storm::storage::DFTSeq<ValueType> const> dftSeq);
void drawSeq(std::shared_ptr<storm::storage::DFTSeq<ValueType> const> dftSeq); /*!
* Check if the element is active intially.
/*
* Return true if BE is active (corresponding place contains one initial token) or false if BE is inactive (corresponding place contains no initial token).
* *
* @param dFTElement DFT element. * @param dFTElement DFT element.
*
* @return True iff element is active initially.
*/ */
bool isActiveInitially(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dFTElement); bool isActiveInitially(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dFTElement);
/* /*!
* Get the priority of the element. * Get the priority of the element.
* The priority is two times the length of the shortest path to the top event. * The priority is two times the length of the shortest path to the top event.
* *
@ -137,16 +142,57 @@ namespace storm {
*/ */
uint64_t getFailPriority(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dFTElement); uint64_t getFailPriority(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dFTElement);
uint64_t addUnavailableNode(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftElement, storm::gspn::LayoutInfo const& layoutInfo, bool initialAvailable = true); /*!
* Add failed place for an element.
*
* @param dftElement Element.
* @param layoutInfo Information about layout.
* @param initialFailed Flag indicating whether the element is initially failed.
*
* @return Id of added failed place.
*/
uint64_t addFailedPlace(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftElement, storm::gspn::LayoutInfo const& layoutInfo, bool initialFailed = false);
/*!
* Add unavailable place for element.
*
* @param dftElement Element.
* @param layoutInfo Information about layout.
* @param initialAvailable Flag indicating whether the element is available initially.
*
* @return Id of added unavailable place.
*/
uint64_t addUnavailablePlace(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftElement, storm::gspn::LayoutInfo const& layoutInfo, bool initialAvailable = true);
/*!
* Add disabled place for element.
*
* @param dftBe Basic Element.
* @param layoutInfo Information about layout.
*
* @return Id of added disabled place.
*/
uint64_t addDisabledPlace(std::shared_ptr<storm::storage::DFTBE<ValueType> const> dftBe, storm::gspn::LayoutInfo const& layoutInfo); uint64_t addDisabledPlace(std::shared_ptr<storm::storage::DFTBE<ValueType> const> dftBe, storm::gspn::LayoutInfo const& layoutInfo);
/*!
* Get failed place for element.
*
* @param dftElement Element.
*
* @return Id of failed place corresponding to the given element.
*/
uint64_t getFailedPlace(std::shared_ptr<storm::storage::DFTElement<ValueType> const> dftElement) {
return failedPlaces.at(dftElement->id());
}
storm::storage::DFT<ValueType> const& mDft; storm::storage::DFT<ValueType> const& mDft;
storm::gspn::GspnBuilder builder; storm::gspn::GspnBuilder builder;
std::vector<uint64_t> failedNodes; // Interface places for DFT elements
std::map<uint64_t, uint64_t> unavailableNodes; std::vector<uint64_t> failedPlaces;
std::map<uint64_t, uint64_t> activeNodes; std::map<uint64_t, uint64_t> unavailablePlaces;
std::map<uint64_t, uint64_t> disabledNodes; std::map<uint64_t, uint64_t> activePlaces;
std::map<uint64_t, uint64_t> disabledPlaces;
bool smart; bool smart;
static constexpr const char* STR_FAILING = "_failing"; // Name standard for transitions that point towards a place, which in turn indicates the failure of a gate. static constexpr const char* STR_FAILING = "_failing"; // Name standard for transitions that point towards a place, which in turn indicates the failure of a gate.

|||||||
100:0
Loading…
Cancel
Save