void computeKappa(const ElementaryCube& cube, int id) { if (computedBoundaries.find(id) != computedBoundaries.end()) { return; } computedBoundaries.insert(id); typedef std::map<ElementaryCube, int> Boundary; Boundary boundary; cube.boundary(boundary); for (Boundary::iterator bIt = boundary.begin(), bEnd = boundary.end(); bIt != bEnd; ++bIt) { const int bId = getId(bIt->first); kappaMap.push_back(boost::make_tuple(id, bId, bIt->second)); computeKappa(bIt->first, bId); } }
boost::shared_ptr<Complex> create(int colors, int defaultColor) { kappaMap.clear(); computedBoundaries.clear(); CubeIds tmpCubeIds = cubeIds; for (CubeIds::iterator it = tmpCubeIds.begin(), end = tmpCubeIds.end(); it != end; ++it) { computeKappa(it->first, it->second); } const int size = cubeIds.size(); typename Complex::Dims dims(size); for (CubeIds::iterator it = cubeIds.begin(), end = cubeIds.end(); it != end; ++it) { dims[it->second] = it->first.dimension(); } return boost::shared_ptr<Complex>(new Complex(colors, dims, kappaMap, defaultColor)); }
bool HDPSolver::dfs(mlcore::State* s, double plaus) { auto curTime = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>( curTime - beginTime_).count(); if (maxTime_ > -1 && duration > maxTime_) return false; if (plaus > minPlaus_) { return false; } if (s->checkBits(mdplib::SOLVED) || problem_->goal(s) || s->deadEnd()) { s->setBits(mdplib::SOLVED); solvedStates_.insert(s); return false; } bool neededUpdate = false; if (residual(problem_, s) > epsilon_) { neededUpdate = true; // mini-gpt adds this loop, but this actually worsens convergence. // do { // bellmanUpdate(problem_, s); // } while (residual(problem_, s) > epsilon_); // return true; } inStack_.insert(s); stateStack_.push_back(s); indices_[s] = index_; low_[s] = index_; index_++; Action* a = greedyAction(problem_, s); if (s->deadEnd()) { return false; // state is a dead-end, nothing to do } list<Successor> successors = problem_->transition(s, a); if (minPlaus_ != INT_MAX) computeKappa(successors, kappaList_); int i = 0; for (auto const & successor : successors) { State* next = successor.su_state; if (indices_.count(next) == 0) { neededUpdate |= dfs(next, plaus + kappaList_.at(i)); low_[s] = std::min(low_[s], low_[next]); } else if (inStack_.count(next) > 0) { // State is in the current connected component stack. low_[s] = std::min(low_[s], indices_[next]); } i++; } if (neededUpdate) { bellmanUpdate(problem_, s); // same as above (mini-gpt code). // do { // bellmanUpdate(problem_, s); // } while (residual(problem_, s) > epsilon_); //return true; } else if (indices_[s] == low_[s]) { // State s is the root of a connected component. while (true) { State* currentState = stateStack_.back(); stateStack_.pop_back(); inStack_.erase(currentState); currentState->setBits(mdplib::SOLVED); solvedStates_.insert(currentState); if (currentState == s) break; } } return neededUpdate; }