Matthias Volk
4 years ago
No known key found for this signature in database
GPG Key ID: 83A57678F739FCD3
11 changed files with 200 additions and 165 deletions
-
6src/storm-dft-cli/storm-dft.cpp
-
23src/storm-dft/api/storm-dft.h
-
4src/storm-dft/builder/ExplicitDFTModelBuilder.cpp
-
44src/storm-dft/modelchecker/dft/DFTModelChecker.cpp
-
34src/storm-dft/modelchecker/dft/DFTModelChecker.h
-
14src/storm-dft/storage/dft/DFT.cpp
-
11src/storm-dft/storage/dft/DFT.h
-
155src/storm-dft/utility/RelevantEvents.h
-
6src/test/storm-dft/api/DftApproximationTest.cpp
-
31src/test/storm-dft/api/DftModelBuildingTest.cpp
-
37src/test/storm-dft/api/DftModelCheckerTest.cpp
@ -1,69 +1,122 @@ |
|||
#pragma once |
|||
|
|||
#include "storm/exceptions/InvalidArgumentException.h" |
|||
#include "storm/logic/AtomicLabelFormula.h" |
|||
#include "storm/logic/Formula.h" |
|||
#include "storm/settings/SettingsManager.h" |
|||
|
|||
#include "storm-dft/storage/dft/DFT.h" |
|||
#include "storm-dft/settings/modules/FaultTreeSettings.h" |
|||
|
|||
namespace storm { |
|||
namespace utility { |
|||
|
|||
/*! |
|||
* Get relevant event names from labels in properties. |
|||
* |
|||
* @param dft DFT. |
|||
* @param properties List of properties. All events occurring in a property are relevant. |
|||
* @return List of relevant event names. |
|||
*/ |
|||
template <typename ValueType> |
|||
std::vector<std::string> getRelevantEventNames(storm::storage::DFT<ValueType> const& dft, std::vector<std::shared_ptr<storm::logic::Formula const>> const& properties) { |
|||
// Get necessary labels from properties |
|||
std::vector<std::shared_ptr<storm::logic::AtomicLabelFormula const>> atomicLabels; |
|||
for (auto property : properties) { |
|||
property->gatherAtomicLabelFormulas(atomicLabels); |
|||
class RelevantEvents { |
|||
public: |
|||
|
|||
/*! |
|||
* Create relevant events from given event names. |
|||
* If name 'all' occurs, all elements are stored as relevant. |
|||
* |
|||
* @param relevantEvents List of relevant event names. |
|||
* @param allowDCForRelevant Whether to allow Don't Care propagation for relevant events. |
|||
*/ |
|||
RelevantEvents(std::vector<std::string> const& relevantEvents = {}, bool allowDCForRelevant = false) : names(), allRelevant(false), allowDC(allowDCForRelevant) { |
|||
for (auto const& name: relevantEvents) { |
|||
if (name == "all") { |
|||
this->allRelevant = true; |
|||
this->names.clear(); |
|||
break; |
|||
} else { |
|||
this->addEvent(name); |
|||
} |
|||
} |
|||
} |
|||
// Add relevant event names from properties |
|||
std::vector<std::string> relevantEventNames; |
|||
for (auto atomic : atomicLabels) { |
|||
std::string label = atomic->getLabel(); |
|||
if (label == "failed" or label == "skipped") { |
|||
// Ignore as these label will always be added if necessary |
|||
} else { |
|||
// Get name of event |
|||
if (boost::ends_with(label, "_failed")) { |
|||
relevantEventNames.push_back(label.substr(0, label.size() - 7)); |
|||
} else if (boost::ends_with(label, "_dc")) { |
|||
relevantEventNames.push_back(label.substr(0, label.size() - 3)); |
|||
} else if (label.find("_claimed_") != std::string::npos) { |
|||
STORM_LOG_THROW(storm::settings::getModule<storm::settings::modules::FaultTreeSettings>().isAddLabelsClaiming(), storm::exceptions::InvalidArgumentException, "Claiming labels will not be exported but are required for label '" << label << "'. Try setting --labels-claiming."); |
|||
|
|||
/*! |
|||
* Add relevant event names required by the labels in properties. |
|||
* |
|||
* @param properties List of properties. All events occurring in a property are relevant. |
|||
*/ |
|||
void addNamesFromProperty(std::vector<std::shared_ptr<storm::logic::Formula const>> const& properties) { |
|||
if (this->allRelevant) { |
|||
return; |
|||
} |
|||
|
|||
// Get necessary labels from properties |
|||
std::vector<std::shared_ptr<storm::logic::AtomicLabelFormula const>> atomicLabels; |
|||
for (auto property : properties) { |
|||
property->gatherAtomicLabelFormulas(atomicLabels); |
|||
} |
|||
|
|||
// Add relevant event names from properties |
|||
for (auto atomic : atomicLabels) { |
|||
std::string label = atomic->getLabel(); |
|||
if (label == "failed" or label == "skipped") { |
|||
// Ignore as these label will always be added if necessary |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Label '" << label << "' not known."); |
|||
// Get name of event |
|||
if (boost::ends_with(label, "_failed")) { |
|||
this->addEvent(label.substr(0, label.size() - 7)); |
|||
} else if (boost::ends_with(label, "_dc")) { |
|||
this->addEvent(label.substr(0, label.size() - 3)); |
|||
} else if (label.find("_claimed_") != std::string::npos) { |
|||
STORM_LOG_THROW(storm::settings::getModule<storm::settings::modules::FaultTreeSettings>().isAddLabelsClaiming(), storm::exceptions::InvalidArgumentException, "Claiming labels will not be exported but are required for label '" << label << "'. Try setting --labels-claiming."); |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Label '" << label << "' not known."); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/*! |
|||
* Check that the relevant names correspond to existing elements in the DFT. |
|||
* |
|||
* @param dft DFT. |
|||
* @return True iff relevant names are consistent with DFT elements. |
|||
*/ |
|||
template <typename ValueType> |
|||
bool checkRelevantNames(storm::storage::DFT<ValueType> const& dft) const { |
|||
for (std::string const& relevantName : this->names) { |
|||
if (!dft.existsName(relevantName)) { |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
return relevantEventNames; |
|||
} |
|||
|
|||
/*! |
|||
* Get relevant event id from relevant event name. |
|||
* |
|||
* @param dft DFT. |
|||
* @param relevantEventNames Names of relevant events. |
|||
* @return Set of relevant event ids. |
|||
*/ |
|||
template <typename ValueType> |
|||
std::set<size_t> getRelevantEvents(storm::storage::DFT<ValueType> const& dft, std::vector<std::string> const& relevantEventNames) { |
|||
// Set relevant elements |
|||
std::set<size_t> relevantEvents; // Per default no event (except the toplevel event) is relevant |
|||
for (std::string const& relevantName : relevantEventNames) { |
|||
if (relevantName == "all") { |
|||
// All events are relevant |
|||
return dft.getAllIds(); |
|||
|
|||
bool isRelevant(std::string const& name) const { |
|||
if (this->allRelevant) { |
|||
return true; |
|||
} else { |
|||
// Find and add corresponding event id |
|||
relevantEvents.insert(dft.getIndex(relevantName)); |
|||
return this->names.find(name) != this->names.end(); |
|||
} |
|||
} |
|||
return relevantEvents; |
|||
} |
|||
|
|||
bool isAllowDC() const { |
|||
return this->allowDC; |
|||
} |
|||
|
|||
private: |
|||
|
|||
/*! |
|||
* Add relevant event. |
|||
* |
|||
* @param name Name of relevant event. |
|||
*/ |
|||
void addEvent(std::string const& name) { |
|||
names.insert(name); |
|||
} |
|||
|
|||
// Names of relevant events. |
|||
std::set<std::string> names; |
|||
|
|||
// Whether all elements are relevant. |
|||
bool allRelevant; |
|||
|
|||
// Whether to allow Don't Care propagation for relevant events. |
|||
bool allowDC; |
|||
}; |
|||
|
|||
} // namespace utility |
|||
} // namespace storm |
|||
} // namespace storm |
Write
Preview
Loading…
Cancel
Save
Reference in new issue