Browse Source

parsing fault prob

pull/3/head
Thomas Knoll 11 months ago
parent
commit
401b23fedd
  1. 28
      main.cpp
  2. 4
      util/Grid.cpp
  3. 3
      util/Grid.h
  4. 2
      util/PrismModulesPrinter.cpp
  5. 11
      util/PrismModulesPrinter.h

28
main.cpp

@ -116,22 +116,20 @@ int main(int argc, char* argv[]) {
parsingStateRewards = true;
parsingBackground = false;
continue;
} else if (line.at(0) == '-' && line.at(line.size() - 1 ) == '-' && parsingStateRewards) {
parsingStateRewards = false;
parsingEnvironmentProperties = true;
continue;
} else if(line.at(0) == '-' && line.at(line.size() - 1) == '-') {
parsingBackground = true;
continue;
}
if(!parsingBackground && !parsingStateRewards) {
// std::cout << "Reading :\t" << line << "\n";
if(!parsingBackground && !parsingStateRewards && !parsingEnvironmentProperties) {
content += line + "\n";
} else if (parsingBackground) {
// std::cout << "Background:\t" << line << "\n";
background += line + "\n";
} else if(parsingStateRewards) {
rewards += line + "\n";
} else if (line.at(0) == '-' && line.at(line.size() - 1 ) == '-' && parsingStateRewards) {
parsingStateRewards = false;
parsingEnvironmentProperties = true;
continue;
} else if (parsingEnvironmentProperties) {
properties += line + "\n";
}
@ -151,6 +149,8 @@ int main(int argc, char* argv[]) {
cells backgroundCells;
std::vector<Configuration> configurations;
std::map<coordinates, float> stateRewards;
double faultyProbability;
try {
bool ok = phrase_parse(contentIter, contentLast, contentParser, qi::space, contentCells);
// TODO if(background is not empty) {
@ -169,8 +169,20 @@ int main(int argc, char* argv[]) {
float reward = std::stof(*(++iter));
stateRewards[std::make_pair(x,y)] = reward;
}
if (!properties.empty()) {
auto faultProbabilityIdentifier = std::string("FaultProbability:");
auto start_pos = properties.find(faultProbabilityIdentifier);
if (start_pos != std::string::npos) {
auto end_pos = properties.find('\n', start_pos);
auto value = properties.substr(start_pos + faultProbabilityIdentifier.length(), end_pos - start_pos - faultProbabilityIdentifier.length());
faultyProbability = std::stod(value);
std::cout << "Probabilty" << faultyProbability << std::endl;
}
}
if(ok) {
Grid grid(contentCells, backgroundCells, gridOptions, stateRewards);
Grid grid(contentCells, backgroundCells, gridOptions, stateRewards, faultyProbability);
//grid.printToPrism(std::cout, prism::ModelType::MDP);
std::stringstream ss;
// grid.printToPrism(file, configurations ,prism::ModelType::MDP);

4
util/Grid.cpp

@ -12,8 +12,8 @@ prism::ModelType GridOptions::getModelType() const
return prism::ModelType::MDP;
}
Grid::Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map<coordinates, float> &stateRewards)
: allGridCells(gridCells), background(background), gridOptions(gridOptions), stateRewards(stateRewards)
Grid::Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map<coordinates, float> &stateRewards, const double faultyProbability)
: allGridCells(gridCells), background(background), gridOptions(gridOptions), stateRewards(stateRewards), faultyProbability(faultyProbability)
{
cell max = allGridCells.at(allGridCells.size() - 1);
maxBoundaries = std::make_pair(max.row - 1, max.column - 1);

3
util/Grid.h

@ -21,7 +21,7 @@ struct GridOptions {
class Grid {
public:
Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map<coordinates, float> &stateRewards = {});
Grid(cells gridCells, cells background, const GridOptions &gridOptions, const std::map<coordinates, float> &stateRewards = {}, const double faultyProbability = 0);
cells getGridCells();
@ -67,4 +67,5 @@ class Grid {
std::map<Color, cells> backgroundTiles;
std::map<coordinates, float> stateRewards;
double faultyProbability;
};

2
util/PrismModulesPrinter.cpp

@ -515,7 +515,7 @@ namespace prism {
return os;
}
std::ostream& PrismModulesPrinter::printModule(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &boundaries, const coordinates& initialPosition, const cells &keys, const std::map<Color, cells> &backgroundTiles, const bool agentWithView, const std::vector<float> &probabilities) {
std::ostream& PrismModulesPrinter::printModule(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &boundaries, const coordinates& initialPosition, const cells &keys, const std::map<Color, cells> &backgroundTiles, const bool agentWithView, const std::vector<float> &probabilities, const double faultyProbability) {
os << "module " << agentName << "\n";
os << "\tx" << agentName << " : [1.." << boundaries.second << "];\n";
os << "\ty" << agentName << " : [1.." << boundaries.first << "];\n";

11
util/PrismModulesPrinter.h

@ -78,7 +78,16 @@ namespace prism {
std::ostream& printBooleansForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
std::ostream& printActionsForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles);
std::ostream& printInitStruct(std::ostream &os, const AgentNameAndPositionMap &agents, const KeyNameAndPositionMap &keys, const cells &lockedDoors, const cells &unlockedDoors, prism::ModelType modelType);
std::ostream& printModule(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &boundaries, const coordinates& initialPosition, const cells &keys, const std::map<Color, cells> &backgroundTiles, const bool agentWithView, const std::vector<float> &probabilities = {});
std::ostream& printModule(std::ostream &os,
const AgentName &agentName,
const size_t &agentIndex,
const coordinates &boundaries,
const coordinates& initialPosition,
const cells &keys,
const std::map<Color, cells> &backgroundTiles,
const bool agentWithView,
const std::vector<float> &probabilities = {},
const double faultyProbability = 0);
std::ostream& printMovementActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const bool agentWithView, const float &probability = 1.0);
std::ostream& printDoneActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex);
std::ostream& printEndmodule(std::ostream &os);

Loading…
Cancel
Save