Skip to content

Commit

Permalink
improving reporting, added number of lp's solved.
Browse files Browse the repository at this point in the history
  • Loading branch information
aykutbulut committed Aug 13, 2014
1 parent 4865243 commit 157b177
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/ColaModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ColaModel::ColaModel() : cc_(NULL) {
total_num_cuts_ = 0;
num_supports_ = 0;
num_cuts_ = 0;
num_lp_solved_ = 0;
// this is the default beavior, user can change this using options
setHintParam(OsiDoReducePrint,true,OsiHintTry);
cc_ = new ConicConstraints();
Expand All @@ -32,6 +33,7 @@ ColaModel::ColaModel(char * data_file) : cc_(NULL) {
total_num_cuts_ = 0;
num_supports_ = 0;
num_cuts_ = 0;
num_lp_solved_ = 0;
// this is the default beavior, user can change this using options
setHintParam(OsiDoReducePrint,true,OsiHintTry);
cc_ = new ConicConstraints();
Expand Down Expand Up @@ -167,6 +169,7 @@ void ColaModel::print_stats() const {
std::cout << " Seperating hyperplane for cone " << std::setw(5) << i
<< std::setw(6) << num_cuts_[i] << std::endl;
}
std::cout << "Number of LPs solved: " << num_lp_solved_ << std::endl;
}

void ColaModel::print_solution() const {
Expand Down Expand Up @@ -195,6 +198,7 @@ ProblemStatus ColaModel::solve() {
}
// ===== End Of adding nonnegativity of leading variables
//writeMps("initial", "mps");
num_lp_solved_++;
OsiClpSolverInterface::initialSolve();
// check problem status
problem_status();
Expand Down Expand Up @@ -257,6 +261,7 @@ ProblemStatus ColaModel::solve() {
rays.empty();
}
delete sep;
num_lp_solved_++;
OsiClpSolverInterface::resolve();
// update soco_status_
problem_status();
Expand Down Expand Up @@ -285,6 +290,7 @@ ProblemStatus ColaModel::solve() {
num_cuts_[(**it).cut_generating_cone()]++;
}
// resolve the problem
num_lp_solved_++;
OsiClpSolverInterface::resolve();
// update problem status
problem_status();
Expand All @@ -301,7 +307,7 @@ ProblemStatus ColaModel::solve() {
return soco_status_;
}

ConicConstraints * ColaModel::get_conic_constraints() {
const ConicConstraints * ColaModel::get_conic_constraints() const{
return cc_;
}

Expand All @@ -328,11 +334,11 @@ void ColaModel::report_feasibility() const {
<< std::setw(15) << std::left << "lhs"
<< std::setw(15) << std::left << "lhs_real"
<< std::endl;
const double * full_sol = getColSolution();
for (int i=0; i<num_cones; ++i) {
int cone_size = cc_->cone_size(i);
const int * members = cc_->cone_members(i);
par_sol = new double[cone_size];
const double * full_sol = getColSolution();
for (int j=0; j<cone_size; ++j) {
par_sol[j] = full_sol[members[j]];
}
Expand Down
4 changes: 3 additions & 1 deletion src/ColaModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ColaModel: virtual public OsiClpSolverInterface {
ConicConstraints * cc_;
Options * options_;
ProblemStatus soco_status_;
// number of times we solve lp relaxation problem
int num_lp_solved_;
// number of cuts generated for each cone
int * num_cuts_;
// total number of cuts
Expand Down Expand Up @@ -56,7 +58,7 @@ class ColaModel: virtual public OsiClpSolverInterface {
void print_solution() const;
void report_feasibility() const;
ProblemStatus solve();
ConicConstraints * get_conic_constraints();
const ConicConstraints * get_conic_constraints() const;
Options * options();
// set solver
void setSolver(OsiSolverInterface * solver);
Expand Down
13 changes: 13 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
#include <ColaModel.hpp>

int main(int argc, char ** argv) {
clock_t overall_start_time = clock();
ColaModel * model;
model = new ColaModel();
clock_t read_start_time = clock();
model->read(argv[1]);
clock_t read_duration = clock() - read_start_time;
model->options()->set_int_option(LOG_LEVEL, 1);
clock_t solution_start_time = clock();
ProblemStatus s = model->solve();
clock_t solution_duration = clock() - solution_start_time;
clock_t overall_duration = clock() - overall_start_time;
if (s==OPTIMAL) {
model->get_conic_constraints()->dump_cones_brief();
//model->get_conic_constraints()->dump_cones();
//model->print_solution();
model->report_feasibility();
model->print_stats();
std::cout << "Obj value is " << model->getObjValue() << std::endl;
// report time
std::cout << "Time spent on reading model (in secs) " <<
double(read_duration) / double(CLOCKS_PER_SEC) << std::endl;
std::cout << "Time spent on solve function call (in secs) " <<
double(solution_duration) / double(CLOCKS_PER_SEC) << std::endl;
std::cout << "Total time spent (in secs) " <<
double(overall_duration) / double(CLOCKS_PER_SEC) << std::endl;
// const double * sol = model->getColSolution();
// for (int i=0; i<model->getNumCols(); ++i) {
// std::cout << sol[i] << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions src/Separate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ bool Separate::generate_cut(const int * cone_members,
double ssum = std::inner_product(p+2, p+cone_size, p+2, 0.0);
x1 = (sqrt((-p1+p2)*(-p1+p2)+2.0*ssum) - (-p1+p2)) / 2.0;
x2 = (sqrt((-p1+p2)*(-p1+p2)+2.0*ssum) + (-p1+p2)) / 2.0;
// improve x1 by adjusting it a little, 2x1x2-ssum=0
// x1 = ssum/(2.0*x2);
// measure lhs in RQUAD space
lhs = 2.0*p1*p2-ssum;
// generate cut from xbar
Expand Down

0 comments on commit 157b177

Please sign in to comment.