Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MarkovAutomatonParserTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
8
9TEST(MarkovAutomatonParserTest, NonExistingFile) {
10 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
13 STORM_TEST_RESOURCES_DIR "/nonExistingFile.not", STORM_TEST_RESOURCES_DIR "/nonExistingFile.not", STORM_TEST_RESOURCES_DIR "/nonExistingFile.not"),
14 storm::exceptions::FileIoException);
15}
16
17TEST(MarkovAutomatonParserTest, BasicParsing) {
18 // Get the parsing result.
20 STORM_TEST_RESOURCES_DIR "/tra/ma_general.tra", STORM_TEST_RESOURCES_DIR "/lab/ma_general.lab", STORM_TEST_RESOURCES_DIR "/rew/ma_general.state.rew");
21
22 // Test sizes and counts.
23 ASSERT_EQ(6ul, result.getNumberOfStates());
24 ASSERT_EQ(7ul, result.getNumberOfChoices());
25 ASSERT_EQ(12ul, result.getNumberOfTransitions());
26
27 // Test the exit rates. These have to be 0 for all non-Markovian states.
28 std::vector<double> rates = result.getExitRates();
29 ASSERT_EQ(2, result.getExitRate(0));
30 ASSERT_FALSE(result.isMarkovianState(1));
31 ASSERT_EQ(0, result.getExitRate(1));
32 ASSERT_EQ(15, result.getExitRate(2));
33 ASSERT_FALSE(result.isMarkovianState(3));
34 ASSERT_EQ(0, result.getExitRate(3));
35 ASSERT_FALSE(result.isMarkovianState(4));
36 ASSERT_EQ(0, result.getExitRate(4));
37 ASSERT_FALSE(result.isMarkovianState(5));
38 ASSERT_EQ(0, result.getExitRate(5));
39
40 // Test the labeling.
41 ASSERT_EQ(3ul, result.getStateLabeling().getNumberOfLabels());
42 ASSERT_EQ(1ul, result.getInitialStates().getNumberOfSetBits());
43 ASSERT_EQ(0ul, result.getLabelsOfState(4).size());
44 ASSERT_EQ(1ul, result.getStateLabeling().getStates("goal").getNumberOfSetBits());
45
46 // Test the state rewards.
47 ASSERT_TRUE(result.hasRewardModel());
48 double rewardSum = 0;
49 for (uint_fast64_t i = 0; i < result.getRewardModel("").getStateRewardVector().size(); i++) {
50 rewardSum += result.getRewardModel("").getStateRewardVector()[i];
51 }
52 ASSERT_EQ(1015.765099984, rewardSum);
53 ASSERT_EQ(0, result.getRewardModel("").getStateRewardVector()[0]);
54
55 // Test the transition rewards.
56 ASSERT_FALSE(result.getRewardModel("").hasTransitionRewards());
57}
58
59TEST(MarkovAutomatonParserTest, MismatchedFiles) {
60 // Test file combinations that do not match, i.e. differing number of states, transitions, etc.
61
62 // The labeling file contains a label for a non existent state.
64 STORM_TEST_RESOURCES_DIR "/lab/ma_mismatched.lab"),
65 storm::exceptions::OutOfRangeException);
66
67 // The state reward file contains a reward for a non existent state.
69 STORM_TEST_RESOURCES_DIR "/lab/ma_general.lab",
70 STORM_TEST_RESOURCES_DIR "/rew/ma_mismatched.state.rew"),
71 storm::exceptions::OutOfRangeException);
72}
TEST(MarkovAutomatonParserTest, NonExistingFile)
std::size_t getNumberOfLabels() const
Returns the number of labels managed by this object.
This class represents a Markov automaton.
bool isMarkovianState(storm::storage::sparse::state_type state) const
Retrieves whether the given state is a Markovian state.
std::vector< ValueType > const & getExitRates() const
Retrieves the vector representing the exit rates of the states.
ValueType const & getExitRate(storm::storage::sparse::state_type state) const
Retrieves the exit rate of the given state.
std::set< std::string > getLabelsOfState(storm::storage::sparse::state_type state) const
Retrieves the set of labels attached to the given state.
Definition Model.cpp:616
virtual bool hasRewardModel(std::string const &rewardModelName) const override
Retrieves whether the model has a reward model with the given name.
Definition Model.cpp:207
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
Definition Model.cpp:319
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:167
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:162
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:218
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:177
uint_fast64_t getNumberOfChoices(uint_fast64_t state) const
storm::storage::BitVector const & getStates(std::string const &label) const
Returns the labeling of states associated with the given label.
Loads a labeled Markov automaton from files.
static storm::models::sparse::MarkovAutomaton< ValueType, storm::models::sparse::StandardRewardModel< RewardValueType > > parseMarkovAutomaton(std::string const &transitionsFilename, std::string const &labelingFilename, std::string const &stateRewardFilename="", std::string const &transitionRewardFilename="", std::string const &choiceLabelingFilename="")
Parses the given Markov automaton and returns an object representing the automaton.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:99