]> git.scottworley.com Git - slidingtile/blobdiff - sliding_tile_lib.cc
Tweak the default max_frontier
[slidingtile] / sliding_tile_lib.cc
index 5a4114bd89c6ab621ddec79db2476ef8e0665494..83d6297b42a57505164833b809a411d2050c13b7 100644 (file)
@@ -1,6 +1,7 @@
 #include "sliding_tile_lib.h"
 
 #include <cstdlib>
 #include "sliding_tile_lib.h"
 
 #include <cstdlib>
+#include <fstream>
 #include <istream>
 #include <map>
 #include <memory>
 #include <istream>
 #include <map>
 #include <memory>
@@ -9,6 +10,7 @@
 #include <set>
 #include <sstream>
 #include <stdexcept>
 #include <set>
 #include <sstream>
 #include <stdexcept>
+#include <string>
 #include <vector>
 
 #include <iostream>
 #include <vector>
 
 #include <iostream>
@@ -203,6 +205,15 @@ std::shared_ptr<Step> find_path(const std::string& start, const std::string& goa
   return find_path(board_start, board_goal, max_frontier);
 }
 
   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;
 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;
@@ -215,6 +226,7 @@ std::shared_ptr<Step> find_path(const Board& start, const Board& goal, unsigned
     auto cur = todo.begin()->second;
     todo.erase(todo.begin());
     if (cur->board == goal) {
     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);
       return cur;
     }
     std::vector<std::shared_ptr<Step>> successors = cur->successors(cur);