Browse Source

extra option for export of a matrix

Former-commit-id: 1ea9046438
tempestpy_adaptions
sjunges 9 years ago
parent
commit
86155a5a87
  1. 3
      src/settings/modules/GeneralSettings.cpp
  2. 1
      src/settings/modules/GeneralSettings.h
  3. 25
      src/storage/SparseMatrix.cpp
  4. 10
      src/storage/SparseMatrix.h
  5. 10
      src/utility/storm.h

3
src/settings/modules/GeneralSettings.cpp

@ -23,6 +23,7 @@ namespace storm {
const std::string GeneralSettings::precisionOptionName = "precision";
const std::string GeneralSettings::precisionOptionShortName = "eps";
const std::string GeneralSettings::exportDotOptionName = "exportdot";
const std::string GeneralSettings::exportMatOptionName = "exportmat";
const std::string GeneralSettings::configOptionName = "config";
const std::string GeneralSettings::configOptionShortName = "c";
const std::string GeneralSettings::explicitOptionName = "explicit";
@ -70,6 +71,8 @@ namespace storm {
.addArgument(storm::settings::ArgumentBuilder::createDoubleArgument("value", "The precision to use.").setDefaultValueDouble(1e-06).addValidationFunctionDouble(storm::settings::ArgumentValidators::doubleRangeValidatorExcluding(0.0, 1.0)).build()).build());
this->addOption(storm::settings::OptionBuilder(moduleName, exportDotOptionName, "", "If given, the loaded model will be written to the specified file in the dot format.")
.addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "The name of the file to which the model is to be written.").build()).build());
this->addOption(storm::settings::OptionBuilder(moduleName, exportMatOptionName, "", "If given, the loaded model will be written to the specified file in the mat format.")
.addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "the name of the file to which the model is to be writen.").build()).build());
this->addOption(storm::settings::OptionBuilder(moduleName, configOptionName, false, "If given, this file will be read and parsed for additional configuration settings.").setShortName(configOptionShortName)
.addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "The name of the file from which to read the configuration.").addValidationFunctionString(storm::settings::ArgumentValidators::existingReadableFileValidator()).build()).build());
this->addOption(storm::settings::OptionBuilder(moduleName, explicitOptionName, false, "Parses the model given in an explicit (sparse) representation.").setShortName(explicitOptionShortName)

1
src/settings/modules/GeneralSettings.h

@ -371,6 +371,7 @@ namespace storm {
static const std::string precisionOptionName;
static const std::string precisionOptionShortName;
static const std::string exportDotOptionName;
static const std::string exportMatOptionName;
static const std::string configOptionName;
static const std::string configOptionShortName;
static const std::string explicitOptionName;

25
src/storage/SparseMatrix.cpp

@ -1180,6 +1180,31 @@ namespace storm {
return out;
}
template<typename ValueType>
void SparseMatrix<ValueType>::printAsMatlabMatrix(std::ostream& out) const {
// Iterate over all row groups.
for (typename SparseMatrix<ValueType>::index_type group = 0; group < this->getRowGroupCount(); ++group) {
assert(this->getRowGroupSize(group) == 1);
for (typename SparseMatrix<ValueType>::index_type i = this->getRowGroupIndices()[group]; i < this->getRowGroupIndices()[group + 1]; ++i) {
typename SparseMatrix<ValueType>::index_type nextIndex = this->rowIndications[i];
// Print the actual row.
out << i << "\t(";
typename SparseMatrix<ValueType>::index_type currentRealIndex = 0;
while (currentRealIndex < this->columnCount) {
if (nextIndex < this->rowIndications[i + 1] && currentRealIndex == this->columnsAndValues[nextIndex].getColumn()) {
out << this->columnsAndValues[nextIndex].getValue() << " ";
++nextIndex;
} else {
out << "0 ";
}
++currentRealIndex;
}
out << ";" << std::endl;
}
}
}
template<typename ValueType>
std::size_t SparseMatrix<ValueType>::hash() const {
std::size_t result = 0;

10
src/storage/SparseMatrix.h

@ -761,7 +761,15 @@ namespace storm {
template<typename TPrime>
friend std::ostream& operator<<(std::ostream& out, SparseMatrix<TPrime> const& matrix);
/*!
* Prints the matrix in a dense format, as also used by e.g. Matlab.
* Notice that the format does not support multiple rows in a rowgroup.
*
* @out The stream to output to.
*/
void printAsMatlabMatrix(std::ostream& out) const;
/*!
* Returns the size of the matrix in memory measured in bytes.
*

10
src/utility/storm.h

@ -315,7 +315,15 @@ namespace storm {
}
return result;
}
template<typename ValueType>
void exportMatrixToFile(std::shared_ptr<storm::models::sparse::Model<ValueType>> model, std::string const& filepath) {
STORM_LOG_THROW(model->getType() != storm::models::ModelType::Ctmc, storm::exceptions::NotImplementedException, "This functionality is not yet implemented." );
std::ofstream ofs;
ofs.open (filepath, std::ofstream::out);
model->getTransitionMatrix().printAsMatlabMatrix(ofs);
ofs.close();
}
}

Loading…
Cancel
Save