You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
7.6 KiB

  1. #include "logic/Formula.h"
  2. #include "utility/initialize.h"
  3. #include "utility/storm.h"
  4. #include "modelchecker/DFTAnalyser.h"
  5. #include "src/cli/cli.h"
  6. #include "src/exceptions/BaseException.h"
  7. #include "src/utility/macros.h"
  8. #include <boost/lexical_cast.hpp>
  9. #include "src/settings/modules/GeneralSettings.h"
  10. #include "src/settings/modules/DFTSettings.h"
  11. #include "src/settings/modules/CoreSettings.h"
  12. #include "src/settings/modules/DebugSettings.h"
  13. //#include "src/settings/modules/CounterexampleGeneratorSettings.h"
  14. //#include "src/settings/modules/CuddSettings.h"
  15. //#include "src/settings/modules/SylvanSettings.h"
  16. #include "src/settings/modules/GmmxxEquationSolverSettings.h"
  17. #include "src/settings/modules/NativeEquationSolverSettings.h"
  18. //#include "src/settings/modules/BisimulationSettings.h"
  19. //#include "src/settings/modules/GlpkSettings.h"
  20. //#include "src/settings/modules/GurobiSettings.h"
  21. //#include "src/settings/modules/TopologicalValueIterationEquationSolverSettings.h"
  22. //#include "src/settings/modules/ParametricSettings.h"
  23. #include "src/settings/modules/EliminationSettings.h"
  24. /*!
  25. * Load DFT from filename, build corresponding Model and check against given property.
  26. *
  27. * @param filename Path to DFT file in Galileo format.
  28. * @param property PCTC formula capturing the property to check.
  29. */
  30. template <typename ValueType>
  31. void analyzeDFT(std::string filename, std::string property, bool symred = false, bool allowModularisation = false, bool enableDC = true) {
  32. std::cout << "Running DFT analysis on file " << filename << " with property " << property << std::endl;
  33. storm::parser::DFTGalileoParser<ValueType> parser;
  34. storm::storage::DFT<ValueType> dft = parser.parseDFT(filename);
  35. std::vector<std::shared_ptr<storm::logic::Formula const>> formulas = storm::parseFormulasForExplicit(property);
  36. STORM_LOG_ASSERT(formulas.size() == 1, "Wrong number of formulas.");
  37. DFTAnalyser<ValueType> analyser;
  38. analyser.check(dft, formulas[0], symred, allowModularisation, enableDC);
  39. analyser.printTimings();
  40. analyser.printResult();
  41. }
  42. /*!
  43. * Initialize the settings manager.
  44. */
  45. void initializeSettings() {
  46. storm::settings::mutableManager().setName("StoRM-DyFTeE", "storm-dft");
  47. // Register all known settings modules.
  48. storm::settings::addModule<storm::settings::modules::GeneralSettings>();
  49. storm::settings::addModule<storm::settings::modules::DFTSettings>();
  50. storm::settings::addModule<storm::settings::modules::CoreSettings>();
  51. storm::settings::addModule<storm::settings::modules::DebugSettings>();
  52. //storm::settings::addModule<storm::settings::modules::CounterexampleGeneratorSettings>();
  53. //storm::settings::addModule<storm::settings::modules::CuddSettings>();
  54. //storm::settings::addModule<storm::settings::modules::SylvanSettings>();
  55. storm::settings::addModule<storm::settings::modules::GmmxxEquationSolverSettings>();
  56. storm::settings::addModule<storm::settings::modules::NativeEquationSolverSettings>();
  57. //storm::settings::addModule<storm::settings::modules::BisimulationSettings>();
  58. //storm::settings::addModule<storm::settings::modules::GlpkSettings>();
  59. //storm::settings::addModule<storm::settings::modules::GurobiSettings>();
  60. //storm::settings::addModule<storm::settings::modules::TopologicalValueIterationEquationSolverSettings>();
  61. //storm::settings::addModule<storm::settings::modules::ParametricSettings>();
  62. storm::settings::addModule<storm::settings::modules::EliminationSettings>();
  63. }
  64. /*!
  65. * Entry point for the DyFTeE backend.
  66. *
  67. * @param argc The argc argument of main().
  68. * @param argv The argv argument of main().
  69. * @return Return code, 0 if successfull, not 0 otherwise.
  70. */
  71. int main(const int argc, const char** argv) {
  72. try {
  73. storm::utility::setUp();
  74. storm::cli::printHeader("StoRM-DyFTeE", argc, argv);
  75. initializeSettings();
  76. bool optionsCorrect = storm::cli::parseOptions(argc, argv);
  77. if (!optionsCorrect) {
  78. return -1;
  79. }
  80. storm::settings::modules::DFTSettings const& dftSettings = storm::settings::getModule<storm::settings::modules::DFTSettings>();
  81. storm::settings::modules::GeneralSettings const& generalSettings = storm::settings::getModule<storm::settings::modules::GeneralSettings>();
  82. if (!dftSettings.isDftFileSet()) {
  83. STORM_LOG_THROW(false, storm::exceptions::InvalidSettingsException, "No input model.");
  84. }
  85. // Set min or max
  86. bool minimal = true;
  87. if (dftSettings.isComputeMaximalValue()) {
  88. STORM_LOG_THROW(!dftSettings.isComputeMinimalValue(), storm::exceptions::InvalidSettingsException, "Cannot compute minimal and maximal values at the same time.");
  89. minimal = false;
  90. }
  91. // Construct pctlFormula
  92. std::string pctlFormula = "";
  93. bool allowModular = true;
  94. std::string operatorType = "";
  95. std::string targetFormula = "";
  96. if (generalSettings.isPropertySet()) {
  97. STORM_LOG_THROW(!dftSettings.usePropExpectedTime() && !dftSettings.usePropProbability() && !dftSettings.usePropTimebound(), storm::exceptions::InvalidSettingsException, "More than one property given.");
  98. pctlFormula = generalSettings.getProperty();
  99. } else if (dftSettings.usePropExpectedTime()) {
  100. STORM_LOG_THROW(!dftSettings.usePropProbability() && !dftSettings.usePropTimebound(), storm::exceptions::InvalidSettingsException, "More than one property given.");
  101. operatorType = "T";
  102. targetFormula = "F \"failed\"";
  103. allowModular = false;
  104. } else if (dftSettings.usePropProbability()) {
  105. STORM_LOG_THROW(!dftSettings.usePropTimebound(), storm::exceptions::InvalidSettingsException, "More than one property given.");
  106. operatorType = "P";;
  107. targetFormula = "F \"failed\"";
  108. } else {
  109. STORM_LOG_THROW(dftSettings.usePropTimebound(), storm::exceptions::InvalidSettingsException, "No property given.");
  110. std::stringstream stream;
  111. stream << "F<=" << dftSettings.getPropTimebound() << " \"failed\"";
  112. operatorType = "P";
  113. targetFormula = stream.str();
  114. }
  115. if (!targetFormula.empty()) {
  116. STORM_LOG_ASSERT(pctlFormula.empty(), "Pctl formula not empty.");
  117. pctlFormula = operatorType + (minimal ? "min" : "max") + "=?[" + targetFormula + "]";
  118. }
  119. STORM_LOG_ASSERT(!pctlFormula.empty(), "Pctl formula empty.");
  120. bool parametric = false;
  121. #ifdef STORM_HAVE_CARL
  122. parametric = generalSettings.isParametricSet();
  123. #endif
  124. // From this point on we are ready to carry out the actual computations.
  125. if (parametric) {
  126. analyzeDFT<storm::RationalFunction>(dftSettings.getDftFilename(), pctlFormula, dftSettings.useSymmetryReduction(), allowModular && dftSettings.useModularisation(), !dftSettings.isDisableDC() );
  127. } else {
  128. analyzeDFT<double>(dftSettings.getDftFilename(), pctlFormula, dftSettings.useSymmetryReduction(), allowModular && dftSettings.useModularisation(), !dftSettings.isDisableDC());
  129. }
  130. // All operations have now been performed, so we clean up everything and terminate.
  131. storm::utility::cleanUp();
  132. return 0;
  133. } catch (storm::exceptions::BaseException const& exception) {
  134. STORM_LOG_ERROR("An exception caused StoRM-DyFTeE to terminate. The message of the exception is: " << exception.what());
  135. } catch (std::exception const& exception) {
  136. STORM_LOG_ERROR("An unexpected exception occurred and caused StoRM-DyFTeE to terminate. The message of this exception is: " << exception.what());
  137. }
  138. }