From e9e9b15cb1da2b9dbaa1f624504b8c00225b96c8 Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Sat, 2 May 2020 18:54:39 -0700 Subject: [PATCH] store/load winning region to file --- src/storm-pomdp/analysis/WinningRegion.cpp | 57 ++++++++++++++++++++++ src/storm-pomdp/analysis/WinningRegion.h | 5 ++ 2 files changed, 62 insertions(+) diff --git a/src/storm-pomdp/analysis/WinningRegion.cpp b/src/storm-pomdp/analysis/WinningRegion.cpp index c34ec262b..2014d773b 100644 --- a/src/storm-pomdp/analysis/WinningRegion.cpp +++ b/src/storm-pomdp/analysis/WinningRegion.cpp @@ -1,4 +1,6 @@ #include +#include +#include "storm/utility/file.h" #include "storm/storage/expressions/Expression.h" #include "storm/storage/expressions/ExpressionManager.h" #include "storm-pomdp/analysis/WinningRegion.h" @@ -157,6 +159,61 @@ namespace pomdp { return result; } + void WinningRegion::storeToFile(std::string const& path) const { + std::ofstream file; + storm::utility::openFile(path, file); + bool firstLine = true; + for (auto const& i : observationSizes) { + if(!firstLine) { + file << " "; + } else { + firstLine = false; + } + file << i; + } + file << std::endl; + for (auto const& obsWr : winningRegion) { + for (auto const& bv : obsWr) { + bv.store(file); + file << ";"; + } + file << std::endl; + } + storm::utility::closeFile(file); + } + + + WinningRegion WinningRegion::loadFromFile(std::string const& path) { + std::ifstream file; + std::vector observationSizes; + storm::utility::openFile(path, file); + std::string line; + bool firstLine = true; + uint64_t observation = 0; + WinningRegion wr({1}); + while (std::getline(file, line)) + { + std::vector entries; + if(firstLine) { + boost::split(entries, line, boost::is_space()); + std::vector observationSizes; + for(auto const& entry : entries) { + observationSizes.push_back(std::stoul(entry)); + } + wr = WinningRegion(observationSizes); + firstLine = false; + } else { + boost::split(entries, line, boost::is_any_of(";")); + entries.pop_back(); + for (std::string const& bvString : entries) { + wr.update(observation, storm::storage::BitVector::load(bvString)); + } + ++observation; + } + } + storm::utility::closeFile(file); + return wr; + } } } \ No newline at end of file diff --git a/src/storm-pomdp/analysis/WinningRegion.h b/src/storm-pomdp/analysis/WinningRegion.h index 23c294a3c..7b95fed85 100644 --- a/src/storm-pomdp/analysis/WinningRegion.h +++ b/src/storm-pomdp/analysis/WinningRegion.h @@ -24,6 +24,11 @@ namespace storm { uint64_t getNumberOfObservations() const; bool empty() const; void print() const; + + void storeToFile(std::string const& path) const; + static WinningRegion loadFromFile(std::string const& path); + + private: std::vector> winningRegion; std::vector observationSizes;