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.

618 lines
26 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 <fstream>
  17. #include <cstdio>
  18. #include <sstream>
  19. #include <vector>
  20. #include "storm-config.h"
  21. #include "src/models/Dtmc.h"
  22. #include "src/models/MarkovAutomaton.h"
  23. #include "src/storage/SparseMatrix.h"
  24. #include "src/storage/MaximalEndComponentDecomposition.h"
  25. #include "src/modelchecker/csl/SparseMarkovAutomatonCslModelChecker.h"
  26. #include "src/models/AtomicPropositionsLabeling.h"
  27. #include "src/modelchecker/prctl/SparseDtmcPrctlModelChecker.h"
  28. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  29. #include "src/solver/GmmxxLinearEquationSolver.h"
  30. #include "src/solver/GmmxxNondeterministicLinearEquationSolver.h"
  31. #include "src/solver/GurobiLpSolver.h"
  32. #include "src/counterexamples/MILPMinimalLabelSetGenerator.h"
  33. #include "src/counterexamples/SMTMinimalCommandSetGenerator.h"
  34. #include "src/counterexamples/PathBasedSubsystemGenerator.h"
  35. #include "src/parser/AutoParser.h"
  36. #include "src/parser/MarkovAutomatonParser.h"
  37. #include "src/parser/PrctlParser.h"
  38. #include "src/utility/ErrorHandling.h"
  39. #include "src/formula/Prctl.h"
  40. #include "src/utility/vector.h"
  41. #include "src/settings/Settings.h"
  42. // Registers all standard options
  43. #include "src/utility/StormOptions.h"
  44. #include "src/parser/PrctlFileParser.h"
  45. #include "src/parser/LtlFileParser.h"
  46. #include "log4cplus/logger.h"
  47. #include "log4cplus/loggingmacros.h"
  48. #include "log4cplus/consoleappender.h"
  49. #include "log4cplus/fileappender.h"
  50. #include "src/parser/PrismParser.h"
  51. #include "src/adapters/ExplicitModelAdapter.h"
  52. #include "src/adapters/SymbolicModelAdapter.h"
  53. #include "src/exceptions/InvalidSettingsException.h"
  54. // Includes for the linked libraries and versions header
  55. #ifdef STORM_HAVE_INTELTBB
  56. # include "tbb/tbb_stddef.h"
  57. #endif
  58. #ifdef STORM_HAVE_GLPK
  59. # include "glpk.h"
  60. #endif
  61. #ifdef STORM_HAVE_GUROBI
  62. # include "gurobi_c.h"
  63. #endif
  64. #ifdef STORM_HAVE_Z3
  65. # include "z3.h"
  66. #endif
  67. #include <iostream>
  68. #include <iomanip>
  69. #include <fstream>
  70. void printUsage() {
  71. #ifndef WINDOWS
  72. struct rusage ru;
  73. getrusage(RUSAGE_SELF, &ru);
  74. std::cout << "===== Statistics ==============================" << std::endl;
  75. std::cout << "peak memory usage: " << ru.ru_maxrss/1024/1024 << "MB" << std::endl;
  76. std::cout << "CPU time: " << ru.ru_utime.tv_sec << "." << std::setw(3) << std::setfill('0') << ru.ru_utime.tv_usec/1000 << " seconds" << std::endl;
  77. std::cout << "===============================================" << std::endl;
  78. #else
  79. HANDLE hProcess = GetCurrentProcess ();
  80. FILETIME ftCreation, ftExit, ftUser, ftKernel;
  81. PROCESS_MEMORY_COUNTERS pmc;
  82. if (GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc))) {
  83. std::cout << "Memory Usage: " << std::endl;
  84. std::cout << "\tPageFaultCount: " << pmc.PageFaultCount << std::endl;
  85. std::cout << "\tPeakWorkingSetSize: " << pmc.PeakWorkingSetSize << std::endl;
  86. std::cout << "\tWorkingSetSize: " << pmc.WorkingSetSize << std::endl;
  87. std::cout << "\tQuotaPeakPagedPoolUsage: " << pmc.QuotaPeakPagedPoolUsage << std::endl;
  88. std::cout << "\tQuotaPagedPoolUsage: " << pmc.QuotaPagedPoolUsage << std::endl;
  89. std::cout << "\tQuotaPeakNonPagedPoolUsage: " << pmc.QuotaPeakNonPagedPoolUsage << std::endl;
  90. std::cout << "\tQuotaNonPagedPoolUsage: " << pmc.QuotaNonPagedPoolUsage << std::endl;
  91. std::cout << "\tPagefileUsage:" << pmc.PagefileUsage << std::endl;
  92. std::cout << "\tPeakPagefileUsage: " << pmc.PeakPagefileUsage << std::endl;
  93. }
  94. GetProcessTimes (hProcess, &ftCreation, &ftExit, &ftKernel, &ftUser);
  95. ULARGE_INTEGER uLargeInteger;
  96. uLargeInteger.LowPart = ftKernel.dwLowDateTime;
  97. uLargeInteger.HighPart = ftKernel.dwHighDateTime;
  98. double kernelTime = uLargeInteger.QuadPart / 10000.0; // 100 ns Resolution to milliseconds
  99. uLargeInteger.LowPart = ftUser.dwLowDateTime;
  100. uLargeInteger.HighPart = ftUser.dwHighDateTime;
  101. double userTime = uLargeInteger.QuadPart / 10000.0;
  102. std::cout << "CPU Time: " << std::endl;
  103. std::cout << "\tKernel Time: " << std::setprecision(3) << kernelTime << std::endl;
  104. std::cout << "\tUser Time: " << std::setprecision(3) << userTime << std::endl;
  105. #endif
  106. }
  107. log4cplus::Logger logger;
  108. /*!
  109. * Initializes the logging framework and sets up logging to console.
  110. */
  111. void initializeLogger() {
  112. logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main"));
  113. logger.setLogLevel(log4cplus::INFO_LOG_LEVEL);
  114. log4cplus::SharedAppenderPtr consoleLogAppender(new log4cplus::ConsoleAppender());
  115. consoleLogAppender->setName("mainConsoleAppender");
  116. consoleLogAppender->setThreshold(log4cplus::WARN_LOG_LEVEL);
  117. consoleLogAppender->setLayout(std::auto_ptr<log4cplus::Layout>(new log4cplus::PatternLayout("%-5p - %D{%H:%M:%S} (%r ms) - %b:%L: %m%n")));
  118. logger.addAppender(consoleLogAppender);
  119. }
  120. /*!
  121. * Sets up the logging to file.
  122. */
  123. void setUpFileLogging() {
  124. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  125. log4cplus::SharedAppenderPtr fileLogAppender(new log4cplus::FileAppender(s->getOptionByLongName("logfile").getArgument(0).getValueAsString()));
  126. fileLogAppender->setName("mainFileAppender");
  127. fileLogAppender->setLayout(std::auto_ptr<log4cplus::Layout>(new log4cplus::PatternLayout("%-5p - %D{%H:%M:%S} (%r ms) - %F:%L: %m%n")));
  128. logger.addAppender(fileLogAppender);
  129. }
  130. /*!
  131. * Prints the header.
  132. */
  133. void printHeader(const int argc, const char* argv[]) {
  134. std::cout << "StoRM" << std::endl;
  135. std::cout << "-----" << std::endl << std::endl;
  136. std::cout << "Version: " << STORM_CPP_VERSION_MAJOR << "." << STORM_CPP_VERSION_MINOR << "." << STORM_CPP_VERSION_PATCH;
  137. if (STORM_CPP_VERSION_COMMITS_AHEAD != 0) {
  138. std::cout << " (+" << STORM_CPP_VERSION_COMMITS_AHEAD << " commits)";
  139. }
  140. std::cout << " build from revision " << STORM_CPP_VERSION_HASH;
  141. if (STORM_CPP_VERSION_DIRTY == 1) {
  142. std::cout << " (DIRTY)";
  143. }
  144. std::cout << std::endl;
  145. #ifdef STORM_HAVE_INTELTBB
  146. std::cout << "Linked with Intel Threading Building Blocks v" << TBB_VERSION_MAJOR << "." << TBB_VERSION_MINOR << " (Interface version " << TBB_INTERFACE_VERSION << ")." << std::endl;
  147. #endif
  148. #ifdef STORM_HAVE_GLPK
  149. std::cout << "Linked with GNU Linear Programming Kit v" << GLP_MAJOR_VERSION << "." << GLP_MINOR_VERSION << "." << std::endl;
  150. #endif
  151. #ifdef STORM_HAVE_GUROBI
  152. std::cout << "Linked with Gurobi Optimizer v" << GRB_VERSION_MAJOR << "." << GRB_VERSION_MINOR << "." << GRB_VERSION_TECHNICAL << "." << std::endl;
  153. #endif
  154. #ifdef STORM_HAVE_Z3
  155. unsigned int z3Major, z3Minor, z3BuildNumber, z3RevisionNumber;
  156. Z3_get_version(&z3Major, &z3Minor, &z3BuildNumber, &z3RevisionNumber);
  157. std::cout << "Linked with Microsoft Z3 Optimizer v" << z3Major << "." << z3Minor << " Build " << z3BuildNumber << " Rev " << z3RevisionNumber << "." << std::endl;
  158. #endif
  159. // "Compute" the command line argument string with which STORM was invoked.
  160. std::stringstream commandStream;
  161. for (int i = 0; i < argc; ++i) {
  162. commandStream << argv[i] << " ";
  163. }
  164. std::cout << "Command line: " << commandStream.str() << std::endl << std::endl;
  165. }
  166. /*!
  167. * Parses the given command line arguments.
  168. *
  169. * @param argc The argc argument of main().
  170. * @param argv The argv argument of main().
  171. * @return True iff the program should continue to run after parsing the options.
  172. */
  173. bool parseOptions(const int argc, const char* argv[]) {
  174. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  175. try {
  176. storm::settings::Settings::parse(argc, argv);
  177. } catch (storm::exceptions::OptionParserException& e) {
  178. std::cout << "Could not recover from settings error: " << e.what() << "." << std::endl;
  179. std::cout << std::endl << s->getHelpText();
  180. return false;
  181. }
  182. if (s->isSet("help")) {
  183. std::cout << storm::settings::Settings::getInstance()->getHelpText();
  184. return false;
  185. }
  186. if (s->isSet("verbose")) {
  187. logger.getAppender("mainConsoleAppender")->setThreshold(log4cplus::INFO_LOG_LEVEL);
  188. LOG4CPLUS_INFO(logger, "Enabled verbose mode, log output gets printed to console.");
  189. }
  190. if (s->isSet("debug")) {
  191. logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
  192. logger.getAppender("mainConsoleAppender")->setThreshold(log4cplus::DEBUG_LOG_LEVEL);
  193. LOG4CPLUS_INFO(logger, "Enabled very verbose mode, log output gets printed to console.");
  194. }
  195. if (s->isSet("trace")) {
  196. logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL);
  197. logger.getAppender("mainConsoleAppender")->setThreshold(log4cplus::TRACE_LOG_LEVEL);
  198. LOG4CPLUS_INFO(logger, "Enabled trace mode, log output gets printed to console.");
  199. }
  200. if (s->isSet("logfile")) {
  201. setUpFileLogging();
  202. }
  203. return true;
  204. }
  205. /*!
  206. * Performs some necessary initializations.
  207. */
  208. void setUp() {
  209. // Increase the precision of output.
  210. std::cout.precision(10);
  211. }
  212. /*!
  213. * Performs some necessary clean-up.
  214. */
  215. void cleanUp() {
  216. delete storm::utility::cuddUtilityInstance();
  217. }
  218. /*!
  219. * Creates a model checker for the given DTMC that complies with the given options.
  220. *
  221. * @param dtmc A reference to the DTMC for which the model checker is to be created.
  222. * @return A pointer to the resulting model checker.
  223. */
  224. storm::modelchecker::prctl::AbstractModelChecker<double>* createPrctlModelChecker(storm::models::Dtmc<double> const & dtmc) {
  225. // Create the appropriate model checker.
  226. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  227. std::string const chosenMatrixLibrary = s->getOptionByLongName("matrixLibrary").getArgument(0).getValueAsString();
  228. if (chosenMatrixLibrary == "gmm++") {
  229. return new storm::modelchecker::prctl::SparseDtmcPrctlModelChecker<double>(dtmc, new storm::solver::GmmxxLinearEquationSolver<double>());
  230. }
  231. // The control flow should never reach this point, as there is a default setting for matrixlib.
  232. std::string message = "No matrix library suitable for DTMC model checking has been set.";
  233. throw storm::exceptions::InvalidSettingsException() << message;
  234. return nullptr;
  235. }
  236. /*!
  237. * Creates a model checker for the given MDP that complies with the given options.
  238. *
  239. * @param mdp The Dtmc that the model checker will check
  240. * @return
  241. */
  242. storm::modelchecker::prctl::AbstractModelChecker<double>* createPrctlModelChecker(storm::models::Mdp<double> const & mdp) {
  243. // Create the appropriate model checker.
  244. return new storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double>(mdp);
  245. }
  246. /*!
  247. * Checks the PRCTL formulae provided on the command line on the given model checker.
  248. *
  249. * @param modelchecker The model checker that is to be invoked on all given formulae.
  250. */
  251. void checkPrctlFormulae(storm::modelchecker::prctl::AbstractModelChecker<double> const& modelchecker) {
  252. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  253. if (s->isSet("prctl")) {
  254. std::string const chosenPrctlFile = s->getOptionByLongName("prctl").getArgument(0).getValueAsString();
  255. LOG4CPLUS_INFO(logger, "Parsing prctl file: " << chosenPrctlFile << ".");
  256. std::list<storm::property::prctl::AbstractPrctlFormula<double>*> formulaList = storm::parser::PrctlFileParser(chosenPrctlFile);
  257. for (auto formula : formulaList) {
  258. modelchecker.check(*formula);
  259. delete formula;
  260. }
  261. }
  262. }
  263. /*!
  264. * Handles the counterexample generation control.
  265. *
  266. * @param parser An AutoParser to get the model from.
  267. */
  268. void generateCounterExample(std::shared_ptr<storm::models::AbstractModel<double>> model) {
  269. LOG4CPLUS_INFO(logger, "Starting counterexample generation.");
  270. LOG4CPLUS_INFO(logger, "Testing inputs...");
  271. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  272. // First test output directory.
  273. std::string outPath = s->getOptionByLongName("counterExample").getArgument(0).getValueAsString();
  274. if(outPath.back() != '/' && outPath.back() != '\\') {
  275. LOG4CPLUS_ERROR(logger, "The output path is not valid.");
  276. return;
  277. }
  278. std::ofstream testFile(outPath + "test.dot");
  279. if(testFile.fail()) {
  280. LOG4CPLUS_ERROR(logger, "The output path is not valid.");
  281. return;
  282. }
  283. testFile.close();
  284. std::remove((outPath + "test.dot").c_str());
  285. // Differentiate between model types.
  286. if(model->getType() != storm::models::DTMC) {
  287. LOG4CPLUS_ERROR(logger, "Counterexample generation for the selected model type is not supported.");
  288. return;
  289. }
  290. // Get the Dtmc back from the AbstractModel
  291. // Note that the ownership of the object referenced by dtmc lies at the main function.
  292. // Thus, it must not be deleted.
  293. storm::models::Dtmc<double> dtmc = *(model->as<storm::models::Dtmc<double>>());
  294. LOG4CPLUS_INFO(logger, "Model is a DTMC.");
  295. // Get specified PRCTL formulas.
  296. if(!s->isSet("prctl")) {
  297. LOG4CPLUS_ERROR(logger, "No PRCTL formula file specified.");
  298. return;
  299. }
  300. std::string const chosenPrctlFile = s->getOptionByLongName("prctl").getArgument(0).getValueAsString();
  301. LOG4CPLUS_INFO(logger, "Parsing prctl file: " << chosenPrctlFile << ".");
  302. std::list<storm::property::prctl::AbstractPrctlFormula<double>*> formulaList = storm::parser::PrctlFileParser(chosenPrctlFile);
  303. // Test for each formula if a counterexample can be generated for it.
  304. if(formulaList.size() == 0) {
  305. LOG4CPLUS_ERROR(logger, "No PRCTL formula found.");
  306. return;
  307. }
  308. // Get prctl file name without the filetype
  309. uint_fast64_t first = 0;
  310. if(chosenPrctlFile.find('/') != std::string::npos) {
  311. first = chosenPrctlFile.find_last_of('/') + 1;
  312. } else if(chosenPrctlFile.find('\\') != std::string::npos) {
  313. first = chosenPrctlFile.find_last_of('\\') + 1;
  314. }
  315. uint_fast64_t length;
  316. if(chosenPrctlFile.find_last_of('.') != std::string::npos && chosenPrctlFile.find_last_of('.') >= first) {
  317. length = chosenPrctlFile.find_last_of('.') - first;
  318. } else {
  319. length = chosenPrctlFile.length() - first;
  320. }
  321. std::string outFileName = chosenPrctlFile.substr(first, length);
  322. // Test formulas and do generation
  323. uint_fast64_t fIndex = 0;
  324. for (auto formula : formulaList) {
  325. // First check if it is a formula type for which a counterexample can be generated.
  326. if (dynamic_cast<storm::property::prctl::AbstractStateFormula<double> const*>(formula) == nullptr) {
  327. LOG4CPLUS_ERROR(logger, "Unexpected kind of formula. Expected a state formula.");
  328. delete formula;
  329. continue;
  330. }
  331. storm::property::prctl::AbstractStateFormula<double> const& stateForm = static_cast<storm::property::prctl::AbstractStateFormula<double> const&>(*formula);
  332. // Do some output
  333. std::cout << "Generating counterexample for formula " << fIndex << ":" << std::endl;
  334. LOG4CPLUS_INFO(logger, "Generating counterexample for formula " + std::to_string(fIndex) + ": ");
  335. std::cout << "\t" << formula->toString() << "\n" << std::endl;
  336. LOG4CPLUS_INFO(logger, formula->toString());
  337. // Now check if the model does not satisfy the formula.
  338. // That is if there is at least one initial state of the model that does not.
  339. // Also raise the logger threshold for the log file, so that the model check infos aren't logged (useless and there are lots of them)
  340. // Lower it again after the model check.
  341. logger.getAppender("mainFileAppender")->setThreshold(log4cplus::WARN_LOG_LEVEL);
  342. storm::storage::BitVector result = stateForm.check(*createPrctlModelChecker(dtmc));
  343. logger.getAppender("mainFileAppender")->setThreshold(log4cplus::INFO_LOG_LEVEL);
  344. if((result & dtmc.getInitialStates()).getNumberOfSetBits() == dtmc.getInitialStates().getNumberOfSetBits()) {
  345. std::cout << "Formula is satisfied. Can not generate counterexample.\n\n" << std::endl;
  346. LOG4CPLUS_INFO(logger, "Formula is satisfied. Can not generate counterexample.");
  347. delete formula;
  348. continue;
  349. }
  350. // Generate counterexample
  351. storm::models::Dtmc<double> counterExample = storm::counterexamples::PathBasedSubsystemGenerator<double>::computeCriticalSubsystem(dtmc, stateForm);
  352. LOG4CPLUS_INFO(logger, "Found counterexample.");
  353. // Output counterexample
  354. // Do standard output
  355. std::cout << "Found counterexample with following properties: " << std::endl;
  356. counterExample.printModelInformationToStream(std::cout);
  357. std::cout << "For full Dtmc see " << outFileName << "_" << fIndex << ".dot at given output path.\n\n" << std::endl;
  358. // Write the .dot file
  359. std::ofstream outFile(outPath + outFileName + "_" + std::to_string(fIndex) + ".dot");
  360. if(outFile.good()) {
  361. counterExample.writeDotToStream(outFile, true, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, true);
  362. outFile.close();
  363. }
  364. fIndex++;
  365. delete formula;
  366. }
  367. }
  368. /*!
  369. * Main entry point.
  370. */
  371. int main(const int argc, const char* argv[]) {
  372. // Register a signal handler to catch signals and display a backtrace.
  373. installSignalHandler();
  374. // Print an information header.
  375. printHeader(argc, argv);
  376. // Initialize the logging engine and perform other initalizations.
  377. initializeLogger();
  378. setUp();
  379. try {
  380. LOG4CPLUS_INFO(logger, "StoRM was invoked.");
  381. // Parse options.
  382. if (!parseOptions(argc, argv)) {
  383. // If parsing failed or the option to see the usage was set, program execution stops here.
  384. return 0;
  385. }
  386. // If requested by the user, we install a timeout signal to abort computation.
  387. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  388. uint_fast64_t timeout = s->getOptionByLongName("timeout").getArgument(0).getValueAsUnsignedInteger();
  389. if (timeout != 0) {
  390. stormSetAlarm(timeout);
  391. }
  392. // Now, the settings are received and the specified model is parsed. The actual actions taken depend on whether
  393. // the model was provided in explicit or symbolic format.
  394. if (s->isSet("explicit")) {
  395. std::string const chosenTransitionSystemFile = s->getOptionByLongName("explicit").getArgument(0).getValueAsString();
  396. std::string const chosenLabelingFile = s->getOptionByLongName("explicit").getArgument(1).getValueAsString();
  397. std::string chosenStateRewardsFile = "";
  398. if (s->isSet("stateRewards")) {
  399. chosenStateRewardsFile = s->getOptionByLongName("stateRewards").getArgument(0).getValueAsString();
  400. }
  401. std::string chosenTransitionRewardsFile = "";
  402. if (s->isSet("transitionRewards")) {
  403. chosenTransitionRewardsFile = s->getOptionByLongName("transitionRewards").getArgument(0).getValueAsString();
  404. }
  405. std::shared_ptr<storm::models::AbstractModel<double>> model = storm::parser::AutoParser::parseModel(chosenTransitionSystemFile, chosenLabelingFile, chosenStateRewardsFile, chosenTransitionRewardsFile);
  406. if (s->isSet("exportdot")) {
  407. std::ofstream outputFileStream;
  408. outputFileStream.open(s->getOptionByLongName("exportdot").getArgument(0).getValueAsString(), std::ofstream::out);
  409. model->writeDotToStream(outputFileStream);
  410. outputFileStream.close();
  411. }
  412. //Should there be a counterexample generated in case the formula is not satisfied?
  413. if(s->isSet("counterexample")) {
  414. generateCounterExample(model);
  415. } else {
  416. // Determine which engine is to be used to choose the right model checker.
  417. LOG4CPLUS_DEBUG(logger, s->getOptionByLongName("matrixLibrary").getArgument(0).getValueAsString());
  418. // Depending on the model type, the appropriate model checking procedure is chosen.
  419. storm::modelchecker::prctl::AbstractModelChecker<double>* modelchecker = nullptr;
  420. model->printModelInformationToStream(std::cout);
  421. switch (model->getType()) {
  422. case storm::models::DTMC:
  423. LOG4CPLUS_INFO(logger, "Model is a DTMC.");
  424. modelchecker = createPrctlModelChecker(*model->as<storm::models::Dtmc<double>>());
  425. checkPrctlFormulae(*modelchecker);
  426. break;
  427. case storm::models::MDP:
  428. LOG4CPLUS_INFO(logger, "Model is an MDP.");
  429. modelchecker = createPrctlModelChecker(*model->as<storm::models::Mdp<double>>());
  430. checkPrctlFormulae(*modelchecker);
  431. break;
  432. case storm::models::CTMC:
  433. LOG4CPLUS_INFO(logger, "Model is a CTMC.");
  434. LOG4CPLUS_ERROR(logger, "The selected model type is not supported.");
  435. break;
  436. case storm::models::CTMDP:
  437. LOG4CPLUS_INFO(logger, "Model is a CTMDP.");
  438. LOG4CPLUS_ERROR(logger, "The selected model type is not supported.");
  439. break;
  440. case storm::models::MA: {
  441. LOG4CPLUS_INFO(logger, "Model is a Markov automaton.");
  442. storm::models::MarkovAutomaton<double> markovAutomaton = *model->as<storm::models::MarkovAutomaton<double>>();
  443. markovAutomaton.close();
  444. storm::modelchecker::csl::SparseMarkovAutomatonCslModelChecker<double> mc(markovAutomaton);
  445. // std::cout << mc.checkExpectedTime(true, markovAutomaton->getLabeledStates("goal")) << std::endl;
  446. // std::cout << mc.checkExpectedTime(false, markovAutomaton->getLabeledStates("goal")) << std::endl;
  447. std::cout << mc.checkLongRunAverage(true, markovAutomaton.getLabeledStates("goal")) << std::endl;
  448. std::cout << mc.checkLongRunAverage(false, markovAutomaton.getLabeledStates("goal")) << std::endl;
  449. // std::cout << mc.checkTimeBoundedEventually(true, markovAutomaton->getLabeledStates("goal"), 0, 1) << std::endl;
  450. // std::cout << mc.checkTimeBoundedEventually(true, markovAutomaton->getLabeledStates("goal"), 1, 2) << std::endl;
  451. break;
  452. }
  453. case storm::models::Unknown:
  454. default:
  455. LOG4CPLUS_ERROR(logger, "The model type could not be determined correctly.");
  456. break;
  457. }
  458. if (modelchecker != nullptr) {
  459. delete modelchecker;
  460. }
  461. }
  462. } else if (s->isSet("symbolic")) {
  463. // First, we build the model using the given symbolic model description and constant definitions.
  464. std::string const& programFile = s->getOptionByLongName("symbolic").getArgument(0).getValueAsString();
  465. std::string const& constants = s->getOptionByLongName("constants").getArgument(0).getValueAsString();
  466. storm::ir::Program program = storm::parser::PrismParserFromFile(programFile);
  467. std::shared_ptr<storm::models::AbstractModel<double>> model = storm::adapters::ExplicitModelAdapter<double>::translateProgram(program, constants);
  468. model->printModelInformationToStream(std::cout);
  469. if (s->isSet("mincmd")) {
  470. if (model->getType() != storm::models::MDP) {
  471. LOG4CPLUS_ERROR(logger, "Minimal command counterexample generation is only supported for models of type MDP.");
  472. throw storm::exceptions::InternalTypeErrorException() << "Minimal command counterexample generation is only supported for models of type MDP.";
  473. }
  474. std::shared_ptr<storm::models::Mdp<double>> mdp = model->as<storm::models::Mdp<double>>();
  475. // Determine whether we are required to use the MILP-version or the SAT-version.
  476. bool useMILP = s->getOptionByLongName("mincmd").getArgumentByName("method").getValueAsString() == "milp";
  477. // Now parse the property file and receive the list of parsed formulas.
  478. std::string const& propertyFile = s->getOptionByLongName("mincmd").getArgumentByName("propertyFile").getValueAsString();
  479. std::list<storm::property::prctl::AbstractPrctlFormula<double>*> formulaList = storm::parser::PrctlFileParser(propertyFile);
  480. // Now generate the counterexamples for each formula.
  481. for (storm::property::prctl::AbstractPrctlFormula<double>* formulaPtr : formulaList) {
  482. if (useMILP) {
  483. storm::counterexamples::MILPMinimalLabelSetGenerator<double>::computeCounterexample(program, *mdp, formulaPtr);
  484. } else {
  485. storm::counterexamples::SMTMinimalCommandSetGenerator<double>::computeCounterexample(program, constants, *mdp, formulaPtr);
  486. }
  487. // Once we are done with the formula, delete it.
  488. delete formulaPtr;
  489. }
  490. } else if (s->isSet("prctl")) {
  491. // Determine which engine is to be used to choose the right model checker.
  492. LOG4CPLUS_DEBUG(logger, s->getOptionByLongName("matrixLibrary").getArgument(0).getValueAsString());
  493. // Depending on the model type, the appropriate model checking procedure is chosen.
  494. storm::modelchecker::prctl::AbstractModelChecker<double>* modelchecker = nullptr;
  495. switch (model->getType()) {
  496. case storm::models::DTMC:
  497. LOG4CPLUS_INFO(logger, "Model is a DTMC.");
  498. modelchecker = createPrctlModelChecker(*model->as<storm::models::Dtmc<double>>());
  499. checkPrctlFormulae(*modelchecker);
  500. break;
  501. case storm::models::MDP:
  502. LOG4CPLUS_INFO(logger, "Model is an MDP.");
  503. modelchecker = createPrctlModelChecker(*model->as<storm::models::Mdp<double>>());
  504. checkPrctlFormulae(*modelchecker);
  505. break;
  506. case storm::models::CTMC:
  507. LOG4CPLUS_INFO(logger, "Model is a CTMC.");
  508. LOG4CPLUS_ERROR(logger, "The selected model type is not supported.");
  509. break;
  510. case storm::models::CTMDP:
  511. LOG4CPLUS_INFO(logger, "Model is a CTMDP.");
  512. LOG4CPLUS_ERROR(logger, "The selected model type is not supported.");
  513. break;
  514. case storm::models::MA:
  515. LOG4CPLUS_INFO(logger, "Model is a Markov automaton.");
  516. break;
  517. case storm::models::Unknown:
  518. default:
  519. LOG4CPLUS_ERROR(logger, "The model type could not be determined correctly.");
  520. break;
  521. }
  522. if (modelchecker != nullptr) {
  523. delete modelchecker;
  524. }
  525. }
  526. }
  527. // Perform clean-up and terminate.
  528. cleanUp();
  529. printUsage();
  530. LOG4CPLUS_INFO(logger, "StoRM terminating.");
  531. return 0;
  532. } catch (std::exception& e) {
  533. LOG4CPLUS_FATAL(logger, "An exception was thrown. Terminating.");
  534. LOG4CPLUS_FATAL(logger, "\t" << e.what());
  535. }
  536. return 1;
  537. }