stat.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // =====================================================================================
  2. //
  3. // Filename: stat.cc
  4. //
  5. // Description: statistics of experiment results
  6. //
  7. // Version: 1.0
  8. // Created: 2015年10月10日 11时11分56秒
  9. // Revision: none
  10. // Compiler: g++
  11. //
  12. // Author: Jinkun Lin, jkunlin@gmail.com
  13. // Organization: School of EECS, Peking University
  14. //
  15. // =====================================================================================
  16. #include <iostream>
  17. #include <fstream>
  18. #include <sstream>
  19. #include <string>
  20. #include <vector>
  21. #include <limits>
  22. using namespace std;
  23. class Director_entry {/*{{{*/
  24. public:
  25. Director_entry (string director_name) {
  26. string cmd = "ls " + director_name + " > " + director_name + "_tmpfile.txt";
  27. system(cmd.c_str());
  28. fstream file(director_name + "_tmpfile.txt");
  29. if (!file.is_open()) {
  30. cout << "can't open dir" << endl;
  31. exit(0);
  32. }
  33. string line;
  34. while (getline(file, line)) {
  35. file_name.push_back(line);
  36. }
  37. file.close();
  38. cmd = "rm " + director_name + "_tmpfile.txt";
  39. system(cmd.c_str());
  40. };
  41. vector<string>::const_iterator begin() {
  42. return file_name.begin();
  43. }
  44. vector<string>::const_iterator end() {
  45. return file_name.end();
  46. }
  47. vector<string>::size_type size() {
  48. return file_name.size();
  49. }
  50. using size_type = vector<string>::size_type;
  51. string& operator [] (size_type i) {
  52. return file_name[i];
  53. }
  54. private:
  55. vector<string> file_name;
  56. };/*}}}*/
  57. int main(int argc, char const *argv[]) {
  58. if (argc != 2) {
  59. std::cout << "usage: " << std::endl;
  60. return 1;
  61. }
  62. string result_dir = argv[1];
  63. fstream solution("solution.xls", ios::out);
  64. if (!solution.is_open()) {
  65. cout << "can't create simplification.xls" << endl;
  66. return 1;
  67. }
  68. solution.precision(15);
  69. vector<string> all_benchmark_name = {"dimacs_color_test"};
  70. for (auto benchmark_name : all_benchmark_name) {
  71. cout << "**** " << benchmark_name << " ***" << endl;
  72. benchmark_name = result_dir + "/" + benchmark_name;
  73. Director_entry benchmark(benchmark_name);
  74. for (auto instance_name : benchmark) {
  75. cout << instance_name << endl;
  76. Director_entry instance(benchmark_name + "/" + instance_name);
  77. Director_entry::size_type i = 0;
  78. for (; i < instance.size(); ++i) {
  79. string result_file_name = instance[i];
  80. fstream result_file(benchmark_name + "/" + instance_name + "/" + result_file_name);
  81. if (!result_file.is_open()) {
  82. cout << "result file error" << endl;
  83. return 1;
  84. }
  85. string line;
  86. // get last line
  87. while (getline(result_file, line)) {
  88. if (result_file.peek() == EOF) {
  89. break;
  90. }
  91. }
  92. result_file.close();
  93. }
  94. solution << instance_name;
  95. }
  96. }
  97. solution.close();
  98. string cmd = "mv solution.xls " + result_dir;
  99. system(cmd.c_str());
  100. return 0;
  101. }