GridWorldProblem::GridWorldProblem() : width_(0), height_(0), x0_(0), y0_(0), goals_(0), actionCost_(0.03) { absorbing = new GridWorldState(this, -1, -1); addAllActions(); }
void ActionSet::addAllActionsFromSet(const ActionSet& actions) { if (actions.contains(ActionType::anyAction)) { addAllActions(); return; } _actions |= actions._actions; }
void ActionSet::addAction(const ActionType& action) { if (action == ActionType::anyAction) { addAllActions(); return; } _actions.set(action.getIdentifier(), true); }
GridWorldProblem::GridWorldProblem( int width, int height, int x0, int y0, PairDoubleMap* goals, double actionCost) : width_(width), height_(height), x0_(x0), y0_(y0), actionCost_(actionCost) { goals_ = new PairDoubleMap(); for (auto const & goalEntry : *goals) (*goals_)[goalEntry.first] = goalEntry.second; s0 = new GridWorldState(this, x0_, y0_); absorbing = new GridWorldState(this, -1, -1); this->addState(s0); addAllActions(); }
GridWorldProblem::GridWorldProblem(int width, int height, int x0, int y0, PairDoubleMap* goals, mlcore::Heuristic* h) : width_(width), height_(height), x0_(x0), y0_(y0) { goals_ = new PairDoubleMap(); for (auto const & goalEntry : *goals) (*goals_)[goalEntry.first] = goalEntry.second; s0 = new GridWorldState(this, x0_, y0_); absorbing = new GridWorldState(this, -1, -1); this->addState(s0); heuristic_ = h; gamma_ = 1.0; addAllActions(); }
GridWorldProblem::GridWorldProblem(const char* filename, double actionCost, double holeCost, bool allDirections) { mdplib_debug = true; std::ifstream myfile (filename); goals_ = new PairDoubleMap(); // Once the file is finished parsing, these will have correct values width_ = 0, height_ = 0; if (myfile.is_open()) { std::string line; while ( std::getline (myfile, line) ) { for (width_ = 0; width_ < line.size(); width_++) { if (line.at(width_) == 'x') { walls.insert(std::pair<int, int>(width_, height_)); } else if (line.at(width_) == '@') { holes.insert(std::pair<int, int>(width_, height_)); } else if (line.at(width_) == 'G') { goals_->insert( std::make_pair( std::pair<int,int> (width_, height_), 0.0)); } else if (line.at(width_) == 'S') { x0_ = width_; y0_ = height_; } else { assert(line.at(width_) == '.'); } } height_++; } myfile.close(); } else { std::cerr << "Invalid file " << filename << std::endl; exit(-1); } actionCost_ = actionCost; holeCost_ = holeCost; allDirections_ = allDirections; s0 = new GridWorldState(this, x0_, y0_); absorbing = new GridWorldState(this, -1, -1); this->addState(s0); this->addState(absorbing); addAllActions(); }