Improve output format; remove useless code

selection
Alinson S. Xavier 9 years ago
parent 85bddc4e87
commit c11e7426ba

@ -24,9 +24,6 @@
#include <onerow/cplex_helper.tpp>
#include <onerow/stats.hpp>
#include <valgrind/callgrind.h>
#include <gperftools/heap-profiler.h>
#include <onerow/gomory_cut_generator.hpp>
#include <onerow/mir_cut_generator.hpp>
#include <onerow/wedge_cut_generator.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_ */

@ -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);
}

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <cstdio>
#include <cstdlib>
#include <string>
#include <unistd.h>
#include <vector>
#include <ilcplex/cplex.h>
#include "cplex_helper.hpp"
#include "cplex_helper.tpp"
#include "stats.hpp"
#include <valgrind/callgrind.h>
#include <gperftools/heap-profiler.h>
#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.n_cols; i++)
fscanf(f, "%lf", &solution[i]);
cplexHelper.optimal_solution = solution;
}
// relaxes integrality
CPXchgprobtype(env, lp, CPXPROB_LP);
time_printf("Solving first relaxation...\n");
cplexHelper.solve(true);
if (enable_gomory_cuts)
{
time_printf("Generating Gomory cuts...\n");
cplexHelper.add_single_row_cuts<GomoryCutGenerator>();
cplexHelper.solve(true);
}
if (enable_mir_cuts)
{
time_printf("Generating MIR cuts...\n");
cplexHelper.add_single_row_cuts<MIRCutGenerator>();
cplexHelper.solve(true);
}
if (enable_wedge_cuts)
{
time_printf("Generating wedge cuts...\n");
cplexHelper.add_single_row_cuts<WedgeCutGenerator>();
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;
}

@ -19,6 +19,8 @@
#include <cassert>
#include <sys/resource.h>
#include <sys/time.h>
#include <iostream>
#include <iomanip>
#include <onerow/params.hpp>
#include <onerow/stats.hpp>
@ -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;