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.

306 lines
11 KiB

  1. /*
  2. * STORM - a C++ Rebuild of MRMC
  3. *
  4. * STORM (Stochastic Reward Model Checker) is a model checker for discrete-time and continuous-time Markov
  5. * reward models. It supports reward extensions of PCTL and CSL (PRCTL
  6. * and CSRL), and allows for the automated verification of properties
  7. * concerning long-run and instantaneous rewards as well as cumulative
  8. * rewards.
  9. *
  10. * Authors: Philipp Berger
  11. *
  12. * Description: Central part of the application containing the main() Method
  13. */
  14. #include "src/utility/OsDetection.h"
  15. #include <iostream>
  16. #include <cstdio>
  17. #include <sstream>
  18. #include <vector>
  19. #include "storm-config.h"
  20. #include "src/models/Dtmc.h"
  21. #include "src/storage/SparseMatrix.h"
  22. #include "src/models/AtomicPropositionsLabeling.h"
  23. #include "src/modelchecker/EigenDtmcPrctlModelChecker.h"
  24. #include "src/modelchecker/GmmxxDtmcPrctlModelChecker.h"
  25. #include "src/modelchecker/GmmxxMdpPrctlModelChecker.h"
  26. #include "src/parser/AutoParser.h"
  27. #include "src/parser/PrctlParser.h"
  28. #include "src/utility/Settings.h"
  29. #include "src/formula/Formulas.h"
  30. #include "log4cplus/logger.h"
  31. #include "log4cplus/loggingmacros.h"
  32. #include "log4cplus/consoleappender.h"
  33. #include "log4cplus/fileappender.h"
  34. #include "src/exceptions/InvalidSettingsException.h"
  35. log4cplus::Logger logger;
  36. /*!
  37. * Initializes the logging framework and sets up logging to console.
  38. */
  39. void initializeLogger() {
  40. logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main"));
  41. logger.setLogLevel(log4cplus::INFO_LOG_LEVEL);
  42. log4cplus::SharedAppenderPtr consoleLogAppender(new log4cplus::ConsoleAppender());
  43. consoleLogAppender->setName("mainConsoleAppender");
  44. consoleLogAppender->setLayout(std::auto_ptr<log4cplus::Layout>(new log4cplus::PatternLayout("%-5p - %D{%H:%M:%S} (%r ms) - %b:%L: %m%n")));
  45. logger.addAppender(consoleLogAppender);
  46. }
  47. /*!
  48. * Sets up the logging to file.
  49. */
  50. void setUpFileLogging() {
  51. storm::settings::Settings* s = storm::settings::instance();
  52. log4cplus::SharedAppenderPtr fileLogAppender(new log4cplus::FileAppender(s->getString("logfile")));
  53. fileLogAppender->setName("mainFileAppender");
  54. fileLogAppender->setLayout(std::auto_ptr<log4cplus::Layout>(new log4cplus::PatternLayout("%-5p - %D{%H:%M:%S} (%r ms) - %F:%L: %m%n")));
  55. logger.addAppender(fileLogAppender);
  56. }
  57. /*!
  58. * Prints the header.
  59. */
  60. void printHeader(const int argc, const char* argv[]) {
  61. std::cout << "StoRM" << std::endl;
  62. std::cout << "-----" << std::endl << std::endl;
  63. std::cout << "Version: 1.0 Alpha" << std::endl;
  64. // "Compute" the command line argument string with which STORM was invoked.
  65. std::stringstream commandStream;
  66. for (int i = 0; i < argc; ++i) {
  67. commandStream << argv[i] << " ";
  68. }
  69. std::cout << "Command line: " << commandStream.str() << std::endl << std::endl;
  70. }
  71. /*!
  72. * Prints the footer.
  73. */
  74. void printFooter() {
  75. std::cout << "Nothing more to do, exiting." << std::endl;
  76. }
  77. /*!
  78. * Function that parses the command line options.
  79. * @param argc The argc argument of main().
  80. * @param argv The argv argument of main().
  81. * @return True iff the program should continue to run after parsing the options.
  82. */
  83. bool parseOptions(const int argc, const char* argv[]) {
  84. storm::settings::Settings* s = nullptr;
  85. try {
  86. storm::settings::Settings::registerModule<storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>>();
  87. s = storm::settings::newInstance(argc, argv, nullptr);
  88. } catch (storm::exceptions::InvalidSettingsException& e) {
  89. std::cout << "Could not recover from settings error: " << e.what() << "." << std::endl;
  90. std::cout << std::endl << storm::settings::help;
  91. return false;
  92. }
  93. if (s->isSet("help")) {
  94. std::cout << storm::settings::help;
  95. return false;
  96. }
  97. if (s->isSet("test-prctl")) {
  98. storm::parser::PrctlParser parser(s->getString("test-prctl").c_str());
  99. return false;
  100. }
  101. if (!s->isSet("verbose") && !s->isSet("logfile")) {
  102. logger.setLogLevel(log4cplus::FATAL_LOG_LEVEL);
  103. } else if (!s->isSet("verbose")) {
  104. logger.removeAppender("mainConsoleAppender");
  105. setUpFileLogging();
  106. } else if (!s->isSet("logfile")) {
  107. LOG4CPLUS_INFO(logger, "Enable verbose mode, log output gets printed to console.");
  108. } else {
  109. setUpFileLogging();
  110. LOG4CPLUS_INFO(logger, "Enable verbose mode, log output gets printed to console.");
  111. }
  112. return true;
  113. }
  114. void setUp() {
  115. std::cout.precision(10);
  116. }
  117. /*!
  118. * Function to perform some cleanup.
  119. */
  120. void cleanUp() {
  121. // nothing here
  122. }
  123. void testCheckingDie(storm::models::Dtmc<double>& dtmc) {
  124. storm::formula::Ap<double>* oneFormula = new storm::formula::Ap<double>("one");
  125. storm::formula::Eventually<double>* eventuallyFormula = new storm::formula::Eventually<double>(oneFormula);
  126. storm::formula::ProbabilisticNoBoundOperator<double>* probFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula);
  127. storm::formula::Ap<double>* done = new storm::formula::Ap<double>("done");
  128. storm::formula::ReachabilityReward<double>* reachabilityRewardFormula = new storm::formula::ReachabilityReward<double>(done);
  129. storm::formula::RewardNoBoundOperator<double>* rewardFormula = new storm::formula::RewardNoBoundOperator<double>(reachabilityRewardFormula);
  130. storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>* mc = new storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>(dtmc);
  131. mc->check(*probFormula);
  132. mc->check(*rewardFormula);
  133. delete mc;
  134. delete probFormula;
  135. delete rewardFormula;
  136. }
  137. void testCheckingCrowds(storm::models::Dtmc<double>& dtmc) {
  138. storm::formula::Ap<double>* observe0Greater1Formula = new storm::formula::Ap<double>("observe0Greater1");
  139. storm::formula::Eventually<double>* eventuallyFormula = new storm::formula::Eventually<double>(observe0Greater1Formula);
  140. storm::formula::ProbabilisticNoBoundOperator<double>* probFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula);
  141. storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>* mc = new storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>(dtmc);
  142. mc->check(*probFormula);
  143. delete probFormula;
  144. storm::formula::Ap<double>* observeIGreater1Formula = new storm::formula::Ap<double>("observeIGreater1");
  145. eventuallyFormula = new storm::formula::Eventually<double>(observeIGreater1Formula);
  146. probFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula);
  147. mc->check(*probFormula);
  148. delete probFormula;
  149. storm::formula::Ap<double>* observeOnlyTrueSenderFormula = new storm::formula::Ap<double>("observeOnlyTrueSender");
  150. eventuallyFormula = new storm::formula::Eventually<double>(observeOnlyTrueSenderFormula);
  151. probFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula);
  152. mc->check(*probFormula);
  153. delete probFormula;
  154. delete mc;
  155. }
  156. void testCheckingSynchronousLeader(storm::models::Dtmc<double>& dtmc, uint_fast64_t n) {
  157. storm::formula::Ap<double>* electedFormula = new storm::formula::Ap<double>("elected");
  158. storm::formula::Eventually<double>* eventuallyFormula = new storm::formula::Eventually<double>(electedFormula);
  159. storm::formula::ProbabilisticNoBoundOperator<double>* probFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula);
  160. storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>* mc = new storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>(dtmc);
  161. mc->check(*probFormula);
  162. delete probFormula;
  163. electedFormula = new storm::formula::Ap<double>("elected");
  164. storm::formula::BoundedUntil<double>* boundedUntilFormula = new storm::formula::BoundedUntil<double>(new storm::formula::Ap<double>("true"), electedFormula, 1);
  165. probFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(boundedUntilFormula);
  166. for (uint_fast64_t L = 1; L < 5; ++L) {
  167. boundedUntilFormula->setBound(L*(n + 1));
  168. mc->check(*probFormula);
  169. }
  170. delete probFormula;
  171. electedFormula = new storm::formula::Ap<double>("elected");
  172. storm::formula::ReachabilityReward<double>* reachabilityRewardFormula = new storm::formula::ReachabilityReward<double>(electedFormula);
  173. storm::formula::RewardNoBoundOperator<double>* rewardFormula = new storm::formula::RewardNoBoundOperator<double>(reachabilityRewardFormula);
  174. mc->check(*rewardFormula);
  175. delete rewardFormula;
  176. delete mc;
  177. }
  178. void testCheckingDice(storm::models::Mdp<double>& mdp) {
  179. storm::formula::Ap<double>* threeFormula = new storm::formula::Ap<double>("three");
  180. storm::formula::Eventually<double>* eventuallyFormula = new storm::formula::Eventually<double>(threeFormula);
  181. storm::formula::ProbabilisticNoBoundOperator<double>* probFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  182. storm::modelChecker::GmmxxMdpPrctlModelChecker<double>* mc = new storm::modelChecker::GmmxxMdpPrctlModelChecker<double>(mdp);
  183. mc->check(*probFormula);
  184. delete probFormula;
  185. delete mc;
  186. }
  187. void testCheckingAsynchLeader(storm::models::Mdp<double>& mdp) {
  188. storm::formula::Ap<double>* electedFormula = new storm::formula::Ap<double>("elected");
  189. storm::formula::Eventually<double>* eventuallyFormula = new storm::formula::Eventually<double>(electedFormula);
  190. storm::formula::ProbabilisticNoBoundOperator<double>* probMinFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  191. storm::modelChecker::GmmxxMdpPrctlModelChecker<double>* mc = new storm::modelChecker::GmmxxMdpPrctlModelChecker<double>(mdp);
  192. mc->check(*probMinFormula);
  193. delete probMinFormula;
  194. electedFormula = new storm::formula::Ap<double>("elected");
  195. eventuallyFormula = new storm::formula::Eventually<double>(electedFormula);
  196. storm::formula::ProbabilisticNoBoundOperator<double>* probMaxFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  197. mc->check(*probMaxFormula);
  198. delete probMaxFormula;
  199. electedFormula = new storm::formula::Ap<double>("elected");
  200. storm::formula::BoundedEventually<double>* boundedEventuallyFormula = new storm::formula::BoundedEventually<double>(electedFormula, 50);
  201. probMinFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  202. mc->check(*probMinFormula);
  203. delete probMinFormula;
  204. electedFormula = new storm::formula::Ap<double>("elected");
  205. boundedEventuallyFormula = new storm::formula::BoundedEventually<double>(electedFormula, 50);
  206. probMaxFormula = new storm::formula::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  207. mc->check(*probMaxFormula);
  208. delete probMaxFormula;
  209. delete mc;
  210. }
  211. /*!
  212. * Simple testing procedure.
  213. */
  214. void testChecking() {
  215. storm::settings::Settings* s = storm::settings::instance();
  216. storm::parser::AutoParser<double> parser(s->getString("trafile"), s->getString("labfile"), s->getString("staterew"), s->getString("transrew"));
  217. if (parser.getType() == storm::models::DTMC) {
  218. std::shared_ptr<storm::models::Dtmc<double>> dtmc = parser.getModel<storm::models::Dtmc<double>>();
  219. dtmc->printModelInformationToStream(std::cout);
  220. // testCheckingDie(*dtmc);
  221. // testCheckingCrowds(*dtmc);
  222. // testCheckingSynchronousLeader(*dtmc, 4);
  223. }
  224. else if (parser.getType() == storm::models::MDP) {
  225. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  226. mdp->printModelInformationToStream(std::cout);
  227. // testCheckingDice(*mdp);
  228. // testCheckingAsynchLeader(*mdp);
  229. } else {
  230. std::cout << "Input is neither a DTMC nor an MDP." << std::endl;
  231. }
  232. }
  233. /*!
  234. * Main entry point.
  235. */
  236. int main(const int argc, const char* argv[]) {
  237. initializeLogger();
  238. if (!parseOptions(argc, argv)) {
  239. return 0;
  240. }
  241. setUp();
  242. LOG4CPLUS_INFO(logger, "StoRM was invoked.");
  243. printHeader(argc, argv);
  244. testChecking();
  245. cleanUp();
  246. LOG4CPLUS_INFO(logger, "StoRM quit.");
  247. return 0;
  248. }