#include "MarkovAutomatonParser.h" #include "SparseItemLabelingParser.h" #include "SparseStateRewardParser.h" #include "NondeterministicSparseTransitionParser.h" #include "storm/storage/sparse/ModelComponents.h" #include "storm/models/sparse/StandardRewardModel.h" #include "storm/exceptions/WrongFormatException.h" #include "storm/adapters/CarlAdapter.h" namespace storm { namespace parser { template storm::models::sparse::MarkovAutomaton> MarkovAutomatonParser::parseMarkovAutomaton(std::string const& transitionsFilename, std::string const& labelingFilename, std::string const& stateRewardFilename, std::string const& transitionRewardFilename, std::string const& choiceLabelingFilename) { // Parse the transitions of the Markov Automaton. typename storm::parser::MarkovAutomatonSparseTransitionParser::Result transitionResult(storm::parser::MarkovAutomatonSparseTransitionParser::parseMarkovAutomatonTransitions(transitionsFilename)); // Build the actual transition matrix using the MatrixBuilder provided by the transitionResult. storm::storage::SparseMatrix transitionMatrix(transitionResult.transitionMatrixBuilder.build()); // Parse the state labeling. storm::models::sparse::StateLabeling resultLabeling(storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(transitionMatrix.getColumnCount(), labelingFilename)); // Cunstruct the result components storm::storage::sparse::ModelComponents> componets(std::move(transitionMatrix), std::move(resultLabeling)); componets.rateTransitions = true; componets.markovianStates = std::move(transitionResult.markovianStates); componets.exitRates = std::move(transitionResult.exitRates); // If given, parse the state rewards file. boost::optional> stateRewards; if (!stateRewardFilename.empty()) { stateRewards.reset(storm::parser::SparseStateRewardParser::parseSparseStateReward(transitionMatrix.getColumnCount(), stateRewardFilename)); } // Only parse transition rewards if a file is given. boost::optional> transitionRewards; if (!transitionRewardFilename.empty()) { transitionRewards = std::move(storm::parser::NondeterministicSparseTransitionParser::parseNondeterministicTransitionRewards(transitionRewardFilename, transitionMatrix)); } if (stateRewards || transitionRewards) { componets.rewardModels.insert(std::make_pair("", storm::models::sparse::StandardRewardModel(std::move(stateRewards), boost::none, std::move(transitionRewards)))); } // Only parse choice labeling if a file is given. boost::optional choiceLabeling; if (!choiceLabelingFilename.empty()) { componets.choiceLabeling = storm::parser::SparseItemLabelingParser::parseChoiceLabeling(transitionMatrix.getRowCount(), choiceLabelingFilename, transitionMatrix.getRowGroupIndices()); } // generate the Markov Automaton. return storm::models::sparse::MarkovAutomaton> (std::move(componets)); } template class MarkovAutomatonParser; #ifdef STORM_HAVE_CARL template class MarkovAutomatonParser; #endif } // namespace parser } // namespace storm