Browse Source
Further step towards Markov automata parser.
Further step towards Markov automata parser.
Former-commit-id: 33e4634743
tempestpy_adaptions
dehnert
11 years ago
12 changed files with 294 additions and 79 deletions
-
1src/models/AbstractModel.cpp
-
11src/models/AtomicPropositionsLabeling.h
-
92src/models/MarkovAutomaton.h
-
1src/parser/AtomicPropositionLabelingParser.cpp
-
6src/parser/AutoParser.h
-
47src/parser/MarkovAutomataSparseTransitionParser.h
-
28src/parser/MarkovAutomatonParser.cpp
-
29src/parser/MarkovAutomatonParser.h
-
23src/parser/MarkovAutomatonSparseTransitionParser.cpp
-
95src/parser/MarkovAutomatonSparseTransitionParser.h
-
38src/storm.cpp
-
2src/utility/StormOptions.cpp
@ -1,47 +0,0 @@ |
|||
#ifndef STORM_PARSER_MARKOVAUTOMATASPARSETRANSITIONPARSER_H_ |
|||
#define STORM_PARSER_MARKOVAUTOMATASPARSETRANSITIONPARSER_H_ |
|||
|
|||
#include "src/storage/SparseMatrix.h" |
|||
#include "src/storage/BitVector.h" |
|||
#include "Parser.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
class MarkovAutomataSparseTransitionParser { |
|||
public: |
|||
struct FirstPassResult { |
|||
|
|||
FirstPassResult() : numberOfNonzeroEntries(0), highestStateIndex(0), numberOfChoices(0) { |
|||
// Intentionally left empty. |
|||
} |
|||
|
|||
uint_fast64_t numberOfNonzeroEntries; |
|||
uint_fast64_t highestStateIndex; |
|||
uint_fast64_t numberOfChoices; |
|||
}; |
|||
|
|||
struct ResultType { |
|||
|
|||
ResultType(FirstPassResult const& firstPassResult) : transitionMatrix(firstPassResult.numberOfChoices, firstPassResult.highestStateIndex + 1), nondeterministicChoiceIndices(firstPassResult.highestStateIndex + 2), markovianChoices(firstPassResult.numberOfChoices), exitRates(firstPassResult.numberOfChoices) { |
|||
transitionMatrix.initialize(firstPassResult.numberOfNonzeroEntries); |
|||
// Intentionally left empty. |
|||
} |
|||
|
|||
storm::storage::SparseMatrix<double> transitionMatrix; |
|||
std::vector<uint_fast64_t> nondeterministicChoiceIndices; |
|||
storm::storage::BitVector markovianChoices; |
|||
std::vector<double> exitRates; |
|||
}; |
|||
|
|||
static ResultType parseMarkovAutomataTransitions(std::string const& filename, RewardMatrixInformationStruct* rewardMatrixInformation = nullptr); |
|||
|
|||
private: |
|||
static FirstPassResult firstPass(char* buf, SupportedLineEndingsEnum lineEndings, RewardMatrixInformationStruct* rewardMatrixInformation = nullptr); |
|||
static ResultType secondPass(char* buf, SupportedLineEndingsEnum lineEndings, FirstPassResult const& firstPassResult, RewardMatrixInformationStruct* rewardMatrixInformation = nullptr); |
|||
}; |
|||
|
|||
} // namespace parser |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_PARSER_MARKOVAUTOMATASPARSETRANSITIONPARSER_H_ */ |
@ -0,0 +1,28 @@ |
|||
#include "MarkovAutomatonParser.h"
|
|||
#include "AtomicPropositionLabelingParser.h"
|
|||
#include "SparseStateRewardParser.h"
|
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
storm::models::MarkovAutomaton<double> MarkovAutomatonParser::parseMarkovAutomaton(std::string const& transitionsFilename, std::string const& labelingFilename, std::string const& stateRewardFilename, std::string const& transitionRewardFilename) { |
|||
storm::parser::MarkovAutomatonSparseTransitionParser::ResultType transitionResult(storm::parser::MarkovAutomatonSparseTransitionParser::parseMarkovAutomatonTransitions(transitionsFilename)); |
|||
storm::models::AtomicPropositionsLabeling resultLabeling(storm::parser::AtomicPropositionLabelingParser(transitionResult.transitionMatrix.getColumnCount(), labelingFilename)); |
|||
|
|||
boost::optional<std::vector<double>> stateRewards; |
|||
if (stateRewardFilename != "") { |
|||
stateRewards.reset(storm::parser::SparseStateRewardParser(transitionResult.transitionMatrix.getColumnCount(), stateRewardFilename)); |
|||
} |
|||
|
|||
if (transitionRewardFilename != "") { |
|||
LOG4CPLUS_ERROR(logger, "Transition rewards are unsupported for Markov automata."); |
|||
throw storm::exceptions::WrongFormatException() << "Transition rewards are unsupported for Markov automata."; |
|||
} |
|||
|
|||
storm::models::MarkovAutomaton<double> resultingAutomaton(std::move(transitionResult.transitionMatrix), std::move(resultLabeling), std::move(transitionResult.nondeterministicChoiceIndices), std::move(transitionResult.markovianStates), std::move(transitionResult.markovianChoices), std::move(transitionResult.exitRates), std::move(stateRewards), boost::optional<storm::storage::SparseMatrix<double>>(), boost::optional<std::vector<storm::storage::VectorSet<uint_fast64_t>>>()); |
|||
|
|||
return resultingAutomaton; |
|||
} |
|||
|
|||
} // namespace parser
|
|||
} // namespace storm
|
@ -0,0 +1,29 @@ |
|||
#ifndef STORM_PARSER_MARKOVAUTOMATONPARSER_H_ |
|||
#define STORM_PARSER_MARKOVAUTOMATONPARSER_H_ |
|||
|
|||
#include "src/models/MarkovAutomaton.h" |
|||
#include "src/parser/MarkovAutomatonSparseTransitionParser.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
/*! |
|||
* A class providing the functionality to parse a labeled Markov automaton. |
|||
*/ |
|||
class MarkovAutomatonParser { |
|||
public: |
|||
|
|||
/*! |
|||
* Parses the given Markov automaton and returns an object representing the automaton. |
|||
* |
|||
* @param transitionsFilename The name of the file containing the transitions of the Markov automaton. |
|||
* @param labelingFilename The name of the file containing the labels for the states of the Markov automaton. |
|||
* @param stateRewardFilename The name of the file that contains the state reward of the Markov automaton. |
|||
* @param transitionRewardFilename The name of the file that contains the transition rewards of the Markov automaton. |
|||
*/ |
|||
static storm::models::MarkovAutomaton<double> parseMarkovAutomaton(std::string const& transitionsFilename, std::string const& labelingFilename, std::string const& stateRewardFilename, std::string const& transitionRewardFilename); |
|||
}; |
|||
} // namespace parser |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_PARSER_MARKOVAUTOMATONPARSER_H_ */ |
@ -0,0 +1,95 @@ |
|||
#ifndef STORM_PARSER_MARKOVAUTOMATONSPARSETRANSITIONPARSER_H_ |
|||
#define STORM_PARSER_MARKOVAUTOMATONSPARSETRANSITIONPARSER_H_ |
|||
|
|||
#include "src/storage/SparseMatrix.h" |
|||
#include "src/storage/BitVector.h" |
|||
#include "Parser.h" |
|||
|
|||
namespace storm { |
|||
namespace parser { |
|||
|
|||
/* |
|||
* A class providing the functionality to parse the transitions of a Markov automaton. |
|||
*/ |
|||
class MarkovAutomatonSparseTransitionParser { |
|||
public: |
|||
/* |
|||
* A structure representing the result of the first pass of this parser. It contains the number of non-zero entries in the model, the highest state index |
|||
* and the total number of choices. |
|||
*/ |
|||
struct FirstPassResult { |
|||
|
|||
FirstPassResult() : numberOfNonzeroEntries(0), highestStateIndex(0), numberOfChoices(0) { |
|||
// Intentionally left empty. |
|||
} |
|||
|
|||
// The total number of non-zero entries of the model. |
|||
uint_fast64_t numberOfNonzeroEntries; |
|||
|
|||
// The highest state index that appears in the model. |
|||
uint_fast64_t highestStateIndex; |
|||
|
|||
// The total number of choices in the model. |
|||
uint_fast64_t numberOfChoices; |
|||
}; |
|||
|
|||
/* |
|||
* A structure representing the result of the parser. It contains the sparse matrix that represents the transitions (along with a vector indicating |
|||
* at which index the choices of a given state begin) as well as the exit rates for all Markovian choices. |
|||
*/ |
|||
struct ResultType { |
|||
|
|||
ResultType(FirstPassResult const& firstPassResult) : transitionMatrix(firstPassResult.numberOfChoices, firstPassResult.highestStateIndex + 1), nondeterministicChoiceIndices(firstPassResult.highestStateIndex + 2), markovianChoices(firstPassResult.numberOfChoices), markovianStates(firstPassResult.highestStateIndex + 1), exitRates(firstPassResult.highestStateIndex + 1) { |
|||
transitionMatrix.initialize(firstPassResult.numberOfNonzeroEntries); |
|||
// Intentionally left empty. |
|||
} |
|||
|
|||
// A matrix representing the transitions of the model. |
|||
storm::storage::SparseMatrix<double> transitionMatrix; |
|||
|
|||
// A vector indicating which rows of the matrix represent the choices of a given state. |
|||
std::vector<uint_fast64_t> nondeterministicChoiceIndices; |
|||
|
|||
// A bit vector indicating which choices are Markovian. By duality, all other choices are probabilitic. |
|||
storm::storage::BitVector markovianChoices; |
|||
|
|||
// A bit vector indicating which states possess a Markovian choice. |
|||
storm::storage::BitVector markovianStates; |
|||
|
|||
// A vector that stores the exit rates for each |
|||
std::vector<double> exitRates; |
|||
}; |
|||
|
|||
/*! |
|||
* Parses the given file under the assumption that it contains a Markov automaton specified in the appropriate format. |
|||
* |
|||
* @param filename The name of the file to parse. |
|||
* @return A structure representing the result of the parser. |
|||
*/ |
|||
static ResultType parseMarkovAutomatonTransitions(std::string const& filename); |
|||
|
|||
private: |
|||
/* |
|||
* Performs the first pass on the input pointed to by the given buffer. |
|||
* |
|||
* @param buffer The buffer that cointains the input. |
|||
* @param lineEndings The line endings that are to be used while parsing. |
|||
* @return A structure representing the result of the first pass. |
|||
*/ |
|||
static FirstPassResult firstPass(char* buffer, SupportedLineEndingsEnum lineEndings); |
|||
|
|||
/* |
|||
* Performs the second pass on the input pointed to by the given buffer with the information of the first pass. |
|||
* |
|||
* @param buffer The buffer that cointains the input. |
|||
* @param lineEndings The line endings that are to be used while parsing. |
|||
* @param firstPassResult The result of the first pass performed on the same input. |
|||
* @return A structure representing the result of the second pass. |
|||
*/ |
|||
static ResultType secondPass(char* buffer, SupportedLineEndingsEnum lineEndings, FirstPassResult const& firstPassResult); |
|||
}; |
|||
|
|||
} // namespace parser |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_PARSER_MARKOVAUTOMATONSPARSETRANSITIONPARSER_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue