#include "sliding_tile_lib.h"
#include <cstdlib>
+#include <fstream>
#include <istream>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <stdexcept>
+#include <string>
#include <vector>
#include <iostream>
return find_path(board_start, board_goal, max_frontier);
}
+static void show_memory_stats() {
+ std::ifstream statm{"/proc/self/statm"};
+ if (statm.is_open()) {
+ std::string statm_data;
+ std::getline(statm, statm_data);
+ std::cerr << "Memory stats: " << statm_data << std::endl;
+ }
+}
+
std::shared_ptr<Step> find_path(const Board& start, const Board& goal, unsigned max_frontier) {
InvertedBoard invgoal = goal.invert();
std::multimap<int, std::shared_ptr<Step>> todo;
auto cur = todo.begin()->second;
todo.erase(todo.begin());
if (cur->board == goal) {
+ show_memory_stats();
return cur;
}
std::vector<std::shared_ptr<Step>> successors = cur->successors(cur);