/* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include namespace Stats { const int MAX_ROUNDS = 100; const int MAX_TIMERS = 100; string input_filename; double opt_value[MAX_ROUNDS]; string opt_sol_status[MAX_ROUNDS]; unsigned long n_cuts_total = 0; unsigned long n_cuts_depth[MAX_CUT_DEPTH] = { 0 }; unsigned long n_generated_cuts_total = 0; unsigned long n_generated_cuts_round[MAX_CUT_DEPTH] = { 0 }; unsigned long n_generated_cuts_depth[MAX_CUT_DEPTH] = { 0 }; unsigned long trivial_lifting_m_count = 0; unsigned long trivial_lifting_m_sum = 0; unsigned long trivial_lifting_m_max = 0; unsigned long n_coefficients = 0; unsigned long n_integral_coefficients = 0; int n_timers = 0; double current_timer_start; double timers[MAX_TIMERS] = {0}; void init() { input_filename = ""; for (int i = 0; i < MAX_ROUNDS; i++) { opt_value[i] = INFINITY; opt_sol_status[i] = ""; } } void add_cut(int depth) { n_cuts_total++; n_cuts_depth[depth]++; } void add_generated_cut(int round, int depth) { n_generated_cuts_total++; n_generated_cuts_round[round]++; n_generated_cuts_depth[depth]++; } void add_trivial_lifting_m(unsigned long m) { trivial_lifting_m_count++; trivial_lifting_m_sum += m; trivial_lifting_m_max = std::max(trivial_lifting_m_max, m); } void add_coefficient(bool integral) { n_coefficients++; if(integral) n_integral_coefficients++; } void set_solution(int round, double sol, string status) { opt_value[round] = sol; opt_sol_status[round] = status; } void set_input_filename(string n) { input_filename = n; } void write_stats(string f) { FILE *out = fopen(f.c_str(), "w"); fprintf(out, "input_file:\n %s\n", input_filename.c_str()); // solution value and status fprintf(out, "sol_value:\n"); for (int i = 0; i < MAX_ROUNDS; i++) if (opt_value[i] < INFINITY) fprintf(out, " %d: %-.6f\n", i, opt_value[i]); fprintf(out, "sol_status:\n"); for (int i = 0; i < MAX_ROUNDS; i++) if (opt_value[i] < INFINITY) fprintf(out, " %d: %s\n", i, opt_sol_status[i].c_str()); // added cuts if(n_cuts_total > 0) { fprintf(out, "n_added_cuts:\n"); fprintf(out, " total:\n %ld\n", n_cuts_total); fprintf(out, " depth:\n"); for (int i = 0; i < MAX_CUT_DEPTH; i++) if (n_cuts_depth[i] > 0) fprintf(out, " %d: %ld\n", i, n_cuts_depth[i]); } // generated cuts if(n_generated_cuts_total > 0) { fprintf(out, "n_generated_cuts:\n"); fprintf(out, " total:\n %ld\n", n_generated_cuts_total); fprintf(out, " round:\n"); for (int i = 0; i < MAX_ROUNDS; i++) if (n_generated_cuts_round[i] > 0) fprintf(out, " %d: %ld\n", i, n_generated_cuts_round[i]); fprintf(out, " depth:\n"); for (int i = 0; i < MAX_CUT_DEPTH; i++) if (n_generated_cuts_depth[i] > 0) fprintf(out, " %d: %ld\n", i, n_generated_cuts_depth[i]); } // trivial lifting if(trivial_lifting_m_count > 0) { double integral_coefficients = ((double) n_integral_coefficients) / n_coefficients; double average_m = ((double) (trivial_lifting_m_sum)) / trivial_lifting_m_count; double slowdown = integral_coefficients * average_m; fprintf(out, "trivial_lifting:\n"); fprintf(out, " max_m: %ld\n", trivial_lifting_m_max); fprintf(out, " average_m: %.6lf\n", average_m); fprintf(out, " integral_coefficients: %.6lf\n", integral_coefficients); fprintf(out, " slowdown: %.6lf\n", slowdown); } if(n_timers > 0) { fprintf(out, "timers:\n"); for(int i=0; i