-
Notifications
You must be signed in to change notification settings - Fork 86
Changes to Storm for revised belief exploration #1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexBork
wants to merge
13
commits into
stormchecker:master
Choose a base branch
from
AlexBork:revbel-storm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
562198b
Changes to Storm for revised belief exploration
AlexBork 9461797
Change boost::optional to std::optional in BoundedUntilFormula
AlexBork 51f9fd0
Add comment about conversion to std::optional
AlexBork 89a1fb5
Merge branch 'bounded-until-optional' into revbel-storm
AlexBork 7351f26
Adjust get*BoundAsOptionalTimeBound
AlexBork 9adb1f1
Change valuetype transformer to only rational-to-double
AlexBork f31dd95
Add potential normalisation
AlexBork d3d2ce4
Change precision to be an input parameter
AlexBork aac224e
Add tests
AlexBork 6573133
Merge branch 'master' into revbel-storm
AlexBork 8347494
Remove normalisation test
AlexBork c5ea70e
Add interval instantiations
AlexBork 8a42f9d
Add test cases for intervals
AlexBork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/storm/transformer/SparseRationalModelToDoubleTransformer.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #include "SparseRationalModelToDoubleTransformer.h" | ||
|
|
||
| #include "storm/exceptions/IllegalArgumentTypeException.h" | ||
| #include "storm/models/sparse/Ctmc.h" | ||
| #include "storm/models/sparse/Dtmc.h" | ||
| #include "storm/models/sparse/MarkovAutomaton.h" | ||
| #include "storm/models/sparse/Mdp.h" | ||
| #include "storm/models/sparse/Pomdp.h" | ||
| #include "storm/models/sparse/Smg.h" | ||
| #include "storm/models/sparse/StochasticTwoPlayerGame.h" | ||
| #include "storm/storage/sparse/ModelComponents.h" | ||
| #include "storm/utility/macros.h" | ||
| #include "storm/utility/vector.h" | ||
|
|
||
| namespace storm::transformer { | ||
| std::shared_ptr<storm::models::sparse::Model<double>> sparseRationalModelToDouble( | ||
| std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> const& inputModel, double precision) { | ||
| STORM_LOG_THROW(inputModel, storm::exceptions::IllegalArgumentTypeException, "Cannot transform a null model."); | ||
| storm::storage::sparse::ModelComponents<double> convertedComponents; | ||
| convertedComponents.transitionMatrix = inputModel->getTransitionMatrix().toValueType<double>(); | ||
| if (inputModel->getType() != storm::models::ModelType::Ctmc) { | ||
| if (!convertedComponents.transitionMatrix.isProbabilistic(precision)) { | ||
| convertedComponents.transitionMatrix.divideRowsInPlace(convertedComponents.transitionMatrix.getRowSumVector()); | ||
| } | ||
| } | ||
| convertedComponents.choiceLabeling = inputModel->getOptionalChoiceLabeling(); | ||
| convertedComponents.stateLabeling = inputModel->getStateLabeling(); | ||
| convertedComponents.stateValuations = inputModel->getOptionalStateValuations(); | ||
| convertedComponents.choiceOrigins = inputModel->getOptionalChoiceOrigins(); | ||
| for (auto const& [rewardModelName, rewardModel] : inputModel->getRewardModels()) { | ||
| // Transform reward models | ||
| std::optional<std::vector<double>> optionalStateRewardVector = std::nullopt; | ||
| std::optional<std::vector<double>> optionalStateActionRewardVector = std::nullopt; | ||
| std::optional<storm::storage::SparseMatrix<double>> optionalTransitionRewardMatrix = std::nullopt; | ||
| if (rewardModel.hasStateRewards()) { | ||
| std::vector<double> resultVector; | ||
| resultVector.reserve(rewardModel.getStateRewardVector().size()); | ||
| for (auto const& oldValue : rewardModel.getStateRewardVector()) { | ||
| resultVector.push_back(storm::utility::convertNumber<double>(oldValue)); | ||
| } | ||
| optionalStateRewardVector = resultVector; | ||
| } | ||
| if (rewardModel.hasStateActionRewards()) { | ||
| std::vector<double> resultVector; | ||
| resultVector.reserve(rewardModel.getStateActionRewardVector().size()); | ||
| for (auto const& oldValue : rewardModel.getStateActionRewardVector()) { | ||
| resultVector.push_back(storm::utility::convertNumber<double>(oldValue)); | ||
| } | ||
| optionalStateActionRewardVector = resultVector; | ||
| } | ||
| if (rewardModel.hasTransitionRewards()) { | ||
| optionalTransitionRewardMatrix = rewardModel.getTransitionRewardMatrix().toValueType<double>(); | ||
| } | ||
| convertedComponents.rewardModels.emplace( | ||
| rewardModelName, storm::models::sparse::StandardRewardModel<double>( | ||
| std::move(optionalStateRewardVector), std::move(optionalStateActionRewardVector), std::move(optionalTransitionRewardMatrix))); | ||
| } | ||
| switch (inputModel->getType()) { | ||
| case storm::models::ModelType::Dtmc: | ||
| return std::make_shared<storm::models::sparse::Dtmc<double>>(storm::models::sparse::Dtmc<double>(convertedComponents)); | ||
| case storm::models::ModelType::Mdp: | ||
| return std::make_shared<storm::models::sparse::Mdp<double>>(storm::models::sparse::Mdp<double>(convertedComponents)); | ||
| case storm::models::ModelType::Ctmc: { | ||
| auto ctmc = inputModel->as<storm::models::sparse::Ctmc<storm::RationalNumber>>(); | ||
| std::vector<double> resultVector; | ||
| resultVector.reserve(ctmc->getExitRateVector().size()); | ||
| for (auto const& oldValue : ctmc->getExitRateVector()) { | ||
| resultVector.push_back(storm::utility::convertNumber<double>(oldValue)); | ||
| } | ||
| convertedComponents.exitRates = resultVector; | ||
| convertedComponents.rateTransitions = true; | ||
| return std::make_shared<storm::models::sparse::Ctmc<double>>(storm::models::sparse::Ctmc<double>(convertedComponents)); | ||
| } | ||
| case storm::models::ModelType::MarkovAutomaton: { | ||
| auto ma = inputModel->as<storm::models::sparse::MarkovAutomaton<storm::RationalNumber>>(); | ||
| std::vector<double> resultVector; | ||
| resultVector.reserve(ma->getExitRates().size()); | ||
| for (auto const& oldValue : ma->getExitRates()) { | ||
| resultVector.push_back(storm::utility::convertNumber<double>(oldValue)); | ||
| } | ||
| convertedComponents.exitRates = resultVector; | ||
| // Markov automata store probabilities in their transition matrix and rates separately in exitRates. | ||
| convertedComponents.rateTransitions = false; | ||
| convertedComponents.markovianStates = ma->getMarkovianStates(); | ||
| return std::make_shared<storm::models::sparse::MarkovAutomaton<double>>(storm::models::sparse::MarkovAutomaton<double>(convertedComponents)); | ||
| } | ||
| case storm::models::ModelType::Pomdp: { | ||
| auto pomdp = inputModel->as<storm::models::sparse::Pomdp<storm::RationalNumber>>(); | ||
| convertedComponents.observabilityClasses = pomdp->getObservations(); | ||
| convertedComponents.observationValuations = pomdp->getOptionalObservationValuations(); | ||
| return std::make_shared<models::sparse::Pomdp<double>>(models::sparse::Pomdp<double>(convertedComponents, pomdp->isCanonic())); | ||
| } | ||
| case storm::models::ModelType::Smg: { | ||
| auto smg = inputModel->as<storm::models::sparse::Smg<storm::RationalNumber>>(); | ||
| convertedComponents.statePlayerIndications = smg->getStatePlayerIndications(); | ||
| convertedComponents.playerNameToIndexMap = smg->getPlayerNamesToIndex(); | ||
| return std::make_shared<storm::models::sparse::Smg<double>>(models::sparse::Smg<double>(convertedComponents)); | ||
| } | ||
| case storm::models::ModelType::S2pg: { | ||
| auto s2pg = inputModel->as<storm::models::sparse::StochasticTwoPlayerGame<storm::RationalNumber>>(); | ||
| convertedComponents.player1Matrix = s2pg->getPlayer1Matrix(); | ||
| return std::make_shared<storm::models::sparse::StochasticTwoPlayerGame<double>>( | ||
| models::sparse::StochasticTwoPlayerGame<double>(convertedComponents)); | ||
| } | ||
| default: | ||
| STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentTypeException, | ||
| "Value type transformation is not supported for models of type " << inputModel->getType() << "."); | ||
| } | ||
| return nullptr; | ||
| } | ||
| } // namespace storm::transformer | ||
19 changes: 19 additions & 0 deletions
19
src/storm/transformer/SparseRationalModelToDoubleTransformer.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "storm/adapters/RationalNumberForward.h" | ||
| #include "storm/models/sparse/Model.h" | ||
|
|
||
| namespace storm::transformer { | ||
|
|
||
| /** | ||
| * Returns a model equivalent to @p inputModel with all probabilities, rates, and rewards converted to double. | ||
| * | ||
| * @param precision The tolerance used to determine whether the converted transition matrix needs to be normalized. Ignored for CTMCs. | ||
| * @pre inputModel is not null. | ||
| */ | ||
| std::shared_ptr<storm::models::sparse::Model<double>> sparseRationalModelToDouble( | ||
| std::shared_ptr<models::sparse::Model<storm::RationalNumber>> const& inputModel, double precision); | ||
|
|
||
| } // namespace storm::transformer |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this swtich case is extremely ugly. Is this the standard way to do this? @tquatmann ?