Browse Source

Display DFT stats

main
Matthias Volk 7 years ago
parent
commit
31821bc1d0
  1. 13
      src/storm-dft-cli/storm-dft.cpp
  2. 9
      src/storm-dft/settings/modules/DftIOSettings.cpp
  3. 10
      src/storm-dft/settings/modules/DftIOSettings.h
  4. 37
      src/storm-dft/storage/dft/DFT.cpp
  5. 4
      src/storm-dft/storage/dft/DFT.h

13
src/storm-dft-cli/storm-dft.cpp

@ -25,17 +25,24 @@
template<typename ValueType>
std::shared_ptr<storm::storage::DFT<ValueType>> loadDFT() {
storm::settings::modules::DftIOSettings const& dftIOSettings = storm::settings::getModule<storm::settings::modules::DftIOSettings>();
std::shared_ptr<storm::storage::DFT<ValueType>> dft;
// Build DFT from given file.
if (dftIOSettings.isDftJsonFileSet()) {
storm::parser::DFTJsonParser<ValueType> parser;
STORM_LOG_DEBUG("Loading DFT from file " << dftIOSettings.getDftJsonFilename());
return std::make_shared<storm::storage::DFT<ValueType>>(parser.parseJson(dftIOSettings.getDftJsonFilename()));
dft = std::make_shared<storm::storage::DFT<ValueType>>(parser.parseJson(dftIOSettings.getDftJsonFilename()));
} else {
storm::parser::DFTGalileoParser<ValueType> parser;
STORM_LOG_DEBUG("Loading DFT from file " << dftIOSettings.getDftFilename());
return std::make_shared<storm::storage::DFT<ValueType>>(parser.parseDFT(dftIOSettings.getDftFilename()));
dft = std::make_shared<storm::storage::DFT<ValueType>>(parser.parseDFT(dftIOSettings.getDftFilename()));
}
if (dftIOSettings.isDisplayStatsSet()) {
std::cout << "=============DFT Statistics==============" << std::endl;
dft->writeStatsToStream(std::cout);
std::cout << "=========================================" << std::endl;
}
return dft;
}
/*!

9
src/storm-dft/settings/modules/DftIOSettings.cpp

@ -26,6 +26,8 @@ namespace storm {
const std::string DftIOSettings::maxValueOptionName = "max";
const std::string DftIOSettings::transformToGspnOptionName = "gspn";
const std::string DftIOSettings::exportToJsonOptionName = "export-json";
const std::string DftIOSettings::displayStatsOptionName = "show-dft-stats";
DftIOSettings::DftIOSettings() : ModuleSettings(moduleName) {
this->addOption(storm::settings::OptionBuilder(moduleName, dftFileOptionName, false, "Parses the model given in the Galileo format.").setShortName(dftFileOptionShortName)
@ -40,6 +42,8 @@ namespace storm {
this->addOption(storm::settings::OptionBuilder(moduleName, maxValueOptionName, false, "Compute maximal value in case of non-determinism.").build());
this->addOption(storm::settings::OptionBuilder(moduleName, transformToGspnOptionName, false, "Transform DFT to GSPN.").build());
this->addOption(storm::settings::OptionBuilder(moduleName, exportToJsonOptionName, false, "Export the model to the Cytoscape JSON format.").addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "The name of the JSON file to export to.").build()).build());
this->addOption(storm::settings::OptionBuilder(moduleName, displayStatsOptionName, false, "Print stats to stdout").build());
}
bool DftIOSettings::isDftFileSet() const {
@ -109,6 +113,10 @@ namespace storm {
return this->getOption(exportToJsonOptionName).getArgumentByName("filename").getValueAsString();
}
bool DftIOSettings::isDisplayStatsSet() const {
return this->getOption(displayStatsOptionName).getHasOptionBeenSet();
}
void DftIOSettings::finalize() {
}
@ -121,3 +129,4 @@ namespace storm {
} // namespace modules
} // namespace settings
} // namespace storm

10
src/storm-dft/settings/modules/DftIOSettings.h

@ -121,6 +121,13 @@ namespace storm {
* @return The name of the json file to export to.
*/
std::string getExportJsonFilename() const;
/*!
* Retrieves whether statistics for the DFT should be displayed.
*
* @return True if the statistics option was set.
*/
bool isDisplayStatsSet() const;
bool check() const override;
void finalize() override;
@ -143,7 +150,8 @@ namespace storm {
static const std::string maxValueOptionName;
static const std::string transformToGspnOptionName;
static const std::string exportToJsonOptionName;
static const std::string displayStatsOptionName;
};
} // namespace modules

37
src/storm-dft/storage/dft/DFT.cpp

@ -378,7 +378,35 @@ namespace storm {
STORM_LOG_TRACE(newDft.getElementsString());
return newDft.optimize();
}
template<typename ValueType>
size_t DFT<ValueType>::nrDynamicElements() const {
size_t noDyn = 0;
for (auto const& elem : mElements) {
switch (elem->type()) {
case DFTElementType::AND:
case DFTElementType::OR:
case DFTElementType::VOT:
case DFTElementType::BE:
case DFTElementType::CONSTF:
case DFTElementType::CONSTS:
break;
case DFTElementType::PAND:
case DFTElementType::SPARE:
case DFTElementType::POR:
case DFTElementType::SEQ:
case DFTElementType::MUTEX:
case DFTElementType::PDEP:
noDyn += 1;
break;
default:
STORM_LOG_ASSERT(false, "DFT element type " << elem->type() << " not known.");
break;
}
}
return noDyn;
}
template<typename ValueType>
std::string DFT<ValueType>::getElementsString() const {
std::stringstream stream;
@ -766,6 +794,13 @@ namespace storm {
std::sort(outgoingDeps.begin(), outgoingDeps.end());
return std::make_tuple(parents, ingoingDeps, outgoingDeps);
}
template<typename ValueType>
void DFT<ValueType>::writeStatsToStream(std::ostream& stream) const {
stream << "Number of BEs: " << nrBasicElements() << std::endl;
stream << "Number of dynamic elements: " << nrDynamicElements() << std::endl;
stream << "Number of elements: " << nrElements() << std::endl;
}
// Explicitly instantiate the class.
template class DFT<double>;

4
src/storm-dft/storage/dft/DFT.h

@ -89,6 +89,8 @@ namespace storm {
size_t nrBasicElements() const {
return mNrOfBEs;
}
size_t nrDynamicElements() const;
size_t getTopLevelIndex() const {
return mTopLevelIndex;
@ -275,6 +277,8 @@ namespace storm {
return mLayoutInfo.at(id);
}
void writeStatsToStream(std::ostream& stream) const;
private:
std::tuple<std::vector<size_t>, std::vector<size_t>, std::vector<size_t>> getSortedParentAndDependencyIds(size_t index) const;

Loading…
Cancel
Save