Browse Source

store/load winning region to file

tempestpy_adaptions
Sebastian Junges 5 years ago
parent
commit
e9e9b15cb1
  1. 57
      src/storm-pomdp/analysis/WinningRegion.cpp
  2. 5
      src/storm-pomdp/analysis/WinningRegion.h

57
src/storm-pomdp/analysis/WinningRegion.cpp

@ -1,4 +1,6 @@
#include <iostream>
#include <boost/algorithm/string.hpp>
#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<uint64_t> 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<std::string> entries;
if(firstLine) {
boost::split(entries, line, boost::is_space());
std::vector<uint64_t> 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;
}
}
}

5
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<std::vector<storm::storage::BitVector>> winningRegion;
std::vector<uint64_t> observationSizes;

Loading…
Cancel
Save