From c11e7426ba822fd787487510df300b234a3c12fa Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Sat, 29 Apr 2017 10:01:55 -0400 Subject: [PATCH] Improve output format; remove useless code --- onerow/benchmark/src/main.cpp | 3 - onerow/library/include/onerow/params.hpp | 6 +- onerow/library/src/cplex_helper.cpp | 29 ++-- onerow/library/src/main.cpp | 169 ----------------------- onerow/library/src/stats.cpp | 5 +- 5 files changed, 22 insertions(+), 190 deletions(-) delete mode 100644 onerow/library/src/main.cpp diff --git a/onerow/benchmark/src/main.cpp b/onerow/benchmark/src/main.cpp index 20a5d69..8118379 100644 --- a/onerow/benchmark/src/main.cpp +++ b/onerow/benchmark/src/main.cpp @@ -24,9 +24,6 @@ #include #include -#include -#include - #include #include #include diff --git a/onerow/library/include/onerow/params.hpp b/onerow/library/include/onerow/params.hpp index 7746378..2f1340c 100644 --- a/onerow/library/include/onerow/params.hpp +++ b/onerow/library/include/onerow/params.hpp @@ -27,7 +27,7 @@ const long REDUCE_FACTOR_COEFFICIENT = 1000000; const int MAX_CUT_DEPTH = 200; -const int ETA_UPDATE_INTERVAL = 1; +const int ETA_UPDATE_INTERVAL = 300; const unsigned int MAX_CUT_BUFFER_SIZE = 100; const double COEFFICIENT_SAFETY_MARGIN = 0.00001; @@ -35,7 +35,7 @@ const double COEFFICIENT_SAFETY_MARGIN = 0.00001; #define INTERSECTION_CUT_USE_DOUBLE #define ENABLE_TRIVIAL_LIFTING -#define ENABLE_EXTENDED_STATISTICS -//#define PRETEND_TO_ADD_CUTS +// #define ENABLE_EXTENDED_STATISTICS +// #define PRETEND_TO_ADD_CUTS #endif /* PARAMS_HPP_ */ diff --git a/onerow/library/src/cplex_helper.cpp b/onerow/library/src/cplex_helper.cpp index 307e6f8..6731ab0 100644 --- a/onerow/library/src/cplex_helper.cpp +++ b/onerow/library/src/cplex_helper.cpp @@ -290,7 +290,7 @@ int CplexHelper::solve(bool should_end_round) CPXgetstatstring(env, status, buffer); CPXgetobjval(env, lp, &objval); - time_printf(" %.6lf [%s] \n", objval, buffer); + time_printf(" %.6lf [%s] \n", objval, buffer); assert(status == 1); @@ -464,7 +464,7 @@ void CplexHelper::print_solution(double *x) { for (int i = 0; i < n_cols; i++) if (fabs(x[i]) > ZERO_CUTOFF) - time_printf(" x%d = %.6lf\n", i, x[i]); + time_printf(" x%d = %.6lf\n", i, x[i]); } void CplexHelper::eta_reset() @@ -476,12 +476,15 @@ void CplexHelper::eta_print() { while (true) { - sleep(ETA_UPDATE_INTERVAL); + for(int i = 0; i < ETA_UPDATE_INTERVAL; i++) + { + if(eta_count >= eta_total) goto FINISHED; + sleep(1); + } if (eta_count == 0) { - printf("\r\r%3.0f%% ETA: unknown\r", 0.0); - fflush(stdout); + time_printf("%3.0f%% ETA: unknown\n", 0.0); continue; } @@ -497,15 +500,13 @@ void CplexHelper::eta_print() time_t eta_date = eta_start + eta; tm *ttm = localtime(&eta_date); - printf("\r%3.0f%% ", 100.0 * eta_count / eta_total); - printf("ETA: %04d-%02d-%02d %02d:%02d:%02d %d / %d\r", - ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday, - ttm->tm_hour, ttm->tm_min, ttm->tm_sec, - eta_count, eta_total); - fflush(stdout); + time_printf("%3.0f%% ETA: %04d-%02d-%02d %02d:%02d:%02d %d / %d\n", + 100.0 * eta_count / eta_total, + ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday, + ttm->tm_hour, ttm->tm_min, ttm->tm_sec, + eta_count, eta_total); } - - printf("\r \r"); +FINISHED:; } void CplexHelper::find_good_rows() @@ -529,5 +530,5 @@ void CplexHelper::find_good_rows() delete row; } - time_printf(" %d rows found\n", n_good_rows, n_rows); + time_printf(" %d rows found\n", n_good_rows, n_rows); } diff --git a/onerow/library/src/main.cpp b/onerow/library/src/main.cpp deleted file mode 100644 index 5fd4133..0000000 --- a/onerow/library/src/main.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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 "cplex_helper.hpp" -#include "cplex_helper.tpp" -#include "stats.hpp" - -#include -#include - -#include "gomory_cut_generator.hpp" -#include "mir_cut_generator.hpp" -#include "wedge_cut_generator.hpp" - -using namespace std; - -char *input_filename = 0; -char *stats_filename = 0; -char *sol_filename = 0; -bool enable_gomory_cuts = false; -bool enable_wedge_cuts = false; -bool enable_mir_cuts = false; - -int c; -extern char *optarg; -char usage[] = "usage: %s [-gmw] -f model.mps [-s stats.yaml]\n"; - -void read_params(int argc, char **argv) -{ - while ((c = getopt(argc, argv, "gwmf:s:x:")) != -1) - { - switch (c) - { - case 'g': - enable_gomory_cuts = true; - break; - case 'w': - enable_wedge_cuts = true; - break; - case 'm': - enable_mir_cuts = true; - break; - case 'f': - input_filename = optarg; - break; - case 's': - stats_filename = optarg; - break; - case 'x': - sol_filename = optarg; - break; - } - } - - if (!input_filename) - { - fprintf(stderr, "%s: missing model filename\n", argv[0]); - fprintf(stderr, usage, argv[0]); - exit(1); - } -} - -int main(int argc, char **argv) -{ - read_params(argc, argv); - - Stats::init(); - - int status; - CPXENVptr env = CPXopenCPLEX(&status); - CPXLPptr lp = CPXcreateprob(env, &status, ""); - CplexHelper cplexHelper(env, lp); - - CPXsetlogfile(env, NULL); - CPXsetintparam(env, CPX_PARAM_PREIND, CPX_OFF); // disable presolve - CPXsetintparam(env, CPX_PARAM_DATACHECK, CPX_ON); // check consistency - CPXsetintparam(env, CPX_PARAM_NUMERICALEMPHASIS, CPX_ON); // numerical precision - - Stats::set_input_filename(string(input_filename)); - - // reads input file - time_printf("Reading input file: %s...\n", input_filename); - status = CPXreadcopyprob(env, lp, input_filename, NULL); - if (status) - { - fprintf(stderr, "could not read input file (%d)\n", status); - return 1; - } - - cplexHelper.read_columns(); - - // read solution - if(sol_filename) - { - time_printf("Reading solution file: %s...\n", sol_filename); - FILE *f = fopen(sol_filename, "r"); - if(!f) - { - fprintf(stderr, "Could not open solution file (%s).", sol_filename); - return 1; - } - - double *solution = new double[cplexHelper.n_cols]; - for(int i=0; i(); - cplexHelper.solve(true); - } - - if (enable_mir_cuts) - { - time_printf("Generating MIR cuts...\n"); - cplexHelper.add_single_row_cuts(); - cplexHelper.solve(true); - } - - if (enable_wedge_cuts) - { - time_printf("Generating wedge cuts...\n"); - cplexHelper.add_single_row_cuts(); - cplexHelper.solve(true); - } - - if(stats_filename != 0) - { - time_printf("Writting stats: %s...\n", stats_filename); - Stats::write_stats(string(stats_filename)); - } - - time_printf("Done.\n"); - CPXcloseCPLEX(&env); - - return 0; - -} diff --git a/onerow/library/src/stats.cpp b/onerow/library/src/stats.cpp index 8d42ff2..7ee900f 100644 --- a/onerow/library/src/stats.cpp +++ b/onerow/library/src/stats.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -189,7 +191,7 @@ namespace Stats { timers[n_timers] = get_current_time() - current_timer_start; - time_printf("Ending timer %d: %.2lfs\n ", n_timers+1, timers[n_timers]); + time_printf("Ending timer %d: %.2lfs\n", n_timers+1, timers[n_timers]); current_timer_start = 0; n_timers++; @@ -215,6 +217,7 @@ void time_printf(const char *fmt, ...) if(initial_time == 0) initial_time = get_current_time(); + std::cout << std::setw(40) << Stats::input_filename << " "; printf("[%10.2lf] ", get_current_time() - initial_time); va_list args;