| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- // =====================================================================================
- //
- // Filename: stat.cc
- //
- // Description: statistics of experiment results
- //
- // Version: 1.0
- // Created: 2015年10月10日 11时11分56秒
- // Revision: none
- // Compiler: g++
- //
- // Author: Jinkun Lin, jkunlin@gmail.com
- // Organization: School of EECS, Peking University
- //
- // =====================================================================================
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <limits>
- using namespace std;
- class Director_entry {/*{{{*/
- public:
- Director_entry (string director_name) {
- string cmd = "ls " + director_name + " > " + director_name + "_tmpfile.txt";
- system(cmd.c_str());
- fstream file(director_name + "_tmpfile.txt");
- if (!file.is_open()) {
- cout << "can't open dir" << endl;
- exit(0);
- }
- string line;
- while (getline(file, line)) {
- file_name.push_back(line);
- }
- file.close();
- cmd = "rm " + director_name + "_tmpfile.txt";
- system(cmd.c_str());
- };
- vector<string>::const_iterator begin() {
- return file_name.begin();
- }
- vector<string>::const_iterator end() {
- return file_name.end();
- }
- vector<string>::size_type size() {
- return file_name.size();
- }
- using size_type = vector<string>::size_type;
- string& operator [] (size_type i) {
- return file_name[i];
- }
- private:
- vector<string> file_name;
- };/*}}}*/
- int main(int argc, char const *argv[]) {
- if (argc != 2) {
- std::cout << "usage: " << std::endl;
- return 1;
- }
- string result_dir = argv[1];
- fstream solution("solution.xls", ios::out);
- if (!solution.is_open()) {
- cout << "can't create simplification.xls" << endl;
- return 1;
- }
- solution.precision(15);
- vector<string> all_benchmark_name = {"dimacs_color_test"};
- for (auto benchmark_name : all_benchmark_name) {
- cout << "**** " << benchmark_name << " ***" << endl;
- benchmark_name = result_dir + "/" + benchmark_name;
- Director_entry benchmark(benchmark_name);
- for (auto instance_name : benchmark) {
- cout << instance_name << endl;
- Director_entry instance(benchmark_name + "/" + instance_name);
- Director_entry::size_type i = 0;
- for (; i < instance.size(); ++i) {
- string result_file_name = instance[i];
- fstream result_file(benchmark_name + "/" + instance_name + "/" + result_file_name);
- if (!result_file.is_open()) {
- cout << "result file error" << endl;
- return 1;
- }
-
- string line;
- // get last line
- while (getline(result_file, line)) {
- if (result_file.peek() == EOF) {
- break;
- }
- }
- result_file.close();
- }
- solution << instance_name;
- }
- }
- solution.close();
- string cmd = "mv solution.xls " + result_dir;
- system(cmd.c_str());
- return 0;
- }
|