Browse Source
			
			
			first version of explicit format export [mdps/no rewards only currently]
			
				
		first version of explicit format export [mdps/no rewards only currently]
	
		
	
			
				Former-commit-id:main078efab44d[formerlya1a444a014] Former-commit-id:321bc64e6f
				 7 changed files with 129 additions and 3 deletions
			
			
		- 
					9src/cli/entrypoints.h
 - 
					12src/settings/modules/IOSettings.cpp
 - 
					18src/settings/modules/IOSettings.h
 - 
					14src/storage/SymbolicModelDescription.cpp
 - 
					2src/storage/SymbolicModelDescription.h
 - 
					62src/utility/ExplicitExporter.cpp
 - 
					15src/utility/ExplicitExporter.h
 
@ -0,0 +1,62 @@ | 
			
		|||||
 | 
				#include "ExplicitExporter.h"
 | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				#include "src/adapters/CarlAdapter.h"
 | 
			
		||||
 | 
				#include "src/utility/macros.h"
 | 
			
		||||
 | 
				#include "src/exceptions/NotImplementedException.h"
 | 
			
		||||
 | 
				#include "src/models/sparse/Dtmc.h"
 | 
			
		||||
 | 
				#include "src/models/sparse/Mdp.h"
 | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				#include "src/models/sparse/StandardRewardModel.h"
 | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace storm { | 
			
		||||
 | 
				    namespace exporter { | 
			
		||||
 | 
				        template<typename ValueType> | 
			
		||||
 | 
				        void explicitExportSparseModel(std::ostream& os, std::shared_ptr<storm::models::sparse::Model<ValueType>> sparseModel,  std::vector<std::string> const& parameters) { | 
			
		||||
 | 
				            STORM_LOG_THROW(sparseModel->getType() == storm::models::ModelType::Mdp, storm::exceptions::NotImplementedException, "This functionality is not yet implemented." ); | 
			
		||||
 | 
				            std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp = sparseModel->template as<storm::models::sparse::Mdp<ValueType>>(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				            os << "// Exported by Storm" << std::endl; | 
			
		||||
 | 
				            os << "@type: mdp" << std::endl; | 
			
		||||
 | 
				            os << "@parameters" << std::endl; | 
			
		||||
 | 
				            for (auto const& p : parameters) { | 
			
		||||
 | 
				               os << p << " "; | 
			
		||||
 | 
				            } | 
			
		||||
 | 
				            os << std::endl; | 
			
		||||
 | 
				            os << "@nr_states" << std::endl  << mdp->getNumberOfStates() <<  std::endl; | 
			
		||||
 | 
				            os << "@model" << std::endl; | 
			
		||||
 | 
				            storm::storage::SparseMatrix<ValueType> const& matrix = mdp->getTransitionMatrix(); | 
			
		||||
 | 
				             | 
			
		||||
 | 
				            for (typename storm::storage::SparseMatrix<ValueType>::index_type group = 0; group < matrix.getRowGroupCount(); ++group) { | 
			
		||||
 | 
				                os << "state " << group; | 
			
		||||
 | 
				                for(auto const& label : mdp->getStateLabeling().getLabelsOfState(group)) { | 
			
		||||
 | 
				                    os << " " << label; | 
			
		||||
 | 
				                } | 
			
		||||
 | 
				                os << std::endl; | 
			
		||||
 | 
				                typename storm::storage::SparseMatrix<ValueType>::index_type start = matrix.getRowGroupIndices()[group]; | 
			
		||||
 | 
				                typename storm::storage::SparseMatrix<ValueType>::index_type end = matrix.getRowGroupIndices()[group + 1]; | 
			
		||||
 | 
				                 | 
			
		||||
 | 
				                for (typename storm::storage::SparseMatrix<ValueType>::index_type i = start; i < end; ++i) { | 
			
		||||
 | 
				                    // Print the actual row.
 | 
			
		||||
 | 
				                    os << "\taction"; | 
			
		||||
 | 
				                    if(mdp->hasChoiceLabeling()) { | 
			
		||||
 | 
				                        //TODO
 | 
			
		||||
 | 
				                    } | 
			
		||||
 | 
				                    os << std::endl; | 
			
		||||
 | 
				                    for(auto it = matrix.begin(i); it != matrix.end(i); ++it) { | 
			
		||||
 | 
				                        os << "\t\t" << it->getColumn() << " : " << it->getValue() << std::endl; | 
			
		||||
 | 
				                    } | 
			
		||||
 | 
				                     | 
			
		||||
 | 
				                } | 
			
		||||
 | 
				            } | 
			
		||||
 | 
				             | 
			
		||||
 | 
				        } | 
			
		||||
 | 
				         | 
			
		||||
 | 
				         | 
			
		||||
 | 
				         | 
			
		||||
 | 
				        template void explicitExportSparseModel<double>(std::ostream& os, std::shared_ptr<storm::models::sparse::Model<double>> sparseModel, std::vector<std::string> const& parameters); | 
			
		||||
 | 
				         | 
			
		||||
 | 
				        template void explicitExportSparseModel<storm::RationalNumber>(std::ostream& os, std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> sparseModel, std::vector<std::string> const& parameters); | 
			
		||||
 | 
				        template void explicitExportSparseModel<storm::RationalFunction>(std::ostream& os, std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> sparseModel, std::vector<std::string> const& parameters); | 
			
		||||
 | 
				    } | 
			
		||||
 | 
				} | 
			
		||||
@ -0,0 +1,15 @@ | 
			
		|||||
 | 
				#pragma once | 
			
		||||
 | 
				#include <iostream> | 
			
		||||
 | 
				#include <memory> | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				#include "src/models/sparse/Model.h" | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace storm { | 
			
		||||
 | 
				    namespace exporter { | 
			
		||||
 | 
				         | 
			
		||||
 | 
				        template<typename ValueType> | 
			
		||||
 | 
				        void explicitExportSparseModel(std::ostream& os, std::shared_ptr<storm::models::sparse::Model<ValueType>> sparseModel, std::vector<std::string> const& parameters); | 
			
		||||
 | 
				         | 
			
		||||
 | 
				         | 
			
		||||
 | 
				    } | 
			
		||||
 | 
				} | 
			
		||||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue