Browse Source

Added die example from PRISM. Added SparseStateRewardParser. Small fix to main.

main
dehnert 12 years ago
parent
commit
504bcb97a6
  1. 2
      src/mrmc.cpp
  2. 74
      src/parser/SparseStateRewardParser.cpp
  3. 32
      src/parser/SparseStateRewardParser.h

2
src/mrmc.cpp

@ -100,7 +100,7 @@ bool parseOptions(const int argc, const char* argv[]) {
std::cout << "Could not recover from settings error: " << e.what() << "." << std::endl;
std::cout << std::endl << mrmc::settings::help;
delete s;
return 1;
return false;
}
if (s->isSet("help")) {

74
src/parser/SparseStateRewardParser.cpp

@ -0,0 +1,74 @@
/*!
* SparseStateRewardParser.cpp
*
* Created on: 23.12.2012
* Author: Christian Dehnert
*/
#include "src/parser/SparseStateRewardParser.h"
#include "src/exceptions/WrongFileFormatException.h"
#include "src/exceptions/FileIoException.h"
#include "src/utility/OsDetection.h"
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <clocale>
#include <iostream>
#include <errno.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <locale.h>
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
extern log4cplus::Logger logger;
namespace mrmc {
namespace parser {
/*!
* Reads a state reward file and puts the result in a state reward vector.
*
* @param stateCount The number of states.
* @param filename The filename of the state reward file.
* @return A pointer to the created state reward vector.
*/
SparseStateRewardParser::SparseStateRewardParser(uint_fast64_t stateCount, std::string const & filename)
: stateRewards(nullptr) {
// Open file.
MappedFile file(filename.c_str());
char* buf = file.data;
char separator[] = " \r\n\t";
// Create state reward vector with given state count.
this->stateRewards = std::shared_ptr<std::vector<double>>(new std::vector<double>(stateCount));
{
// Now parse state reward assignments.
uint_fast64_t state;
double reward;
// Iterate over states.
while (buf[0] != '\0') {
// Parse state number and reward value.
state = checked_strtol(buf, &buf);
reward = strtod(buf, &buf);
if (reward < 0.0) {
LOG4CPLUS_ERROR(logger, "Expected positive probability but got \"" << std::string(buf, 0, 16) << "\".");
throw mrmc::exceptions::WrongFileFormatException() << "State reward file specifies illegal reward value.";
}
(*this->stateRewards)[state] = reward;
buf = trimWhitespaces(buf);
}
}
}
} //namespace parser
} //namespace mrmc

32
src/parser/SparseStateRewardParser.h

@ -0,0 +1,32 @@
#ifndef MRMC_PARSER_SPARSESTATEREWARDPARSER_H_
#define MRMC_PARSER_SPARSESTATEREWARDPARSER_H_
#include "boost/integer/integer_mask.hpp"
#include "src/parser/Parser.h"
#include <memory>
#include <vector>
namespace mrmc {
namespace parser {
/*!
* @brief Load state reward file and return vector of state rewards.
*/
class SparseStateRewardParser : Parser {
public:
SparseStateRewardParser(uint_fast64_t stateCount, std::string const &filename);
std::shared_ptr<std::vector<double>> getStateRewards() {
return this->stateRewards;
}
private:
std::shared_ptr<std::vector<double>> stateRewards;
};
} // namespace parser
} // namespace mrmc
#endif /* MRMC_PARSER_SPARSESTATEREWARDPARSER_H_ */
Loading…
Cancel
Save