Skip to content

Commit

Permalink
Added ability for ecos_bb to set verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwang committed Nov 15, 2014
1 parent f9c59a5 commit cc635e5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
42 changes: 25 additions & 17 deletions ecos_bb/ecos_bb.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ void branch(idxint curr_node_idx, ecos_bb_pwork* prob){
idxint i, split_idx = prob->nodes[curr_node_idx].split_idx;

#if MI_PRINTLEVEL > 1
PRINTTEXT("Branching->\t");
print_node(prob, curr_node_idx);
if (prob->stgs->verbose) {
PRINTTEXT("Branching->\t");
print_node(prob, curr_node_idx);
}
#endif

/* Create right node*/
Expand Down Expand Up @@ -87,8 +89,10 @@ void branch(idxint curr_node_idx, ecos_bb_pwork* prob){
prob->nodes[curr_node_idx].status = MI_NOT_SOLVED;

#if MI_PRINTLEVEL > 1
PRINTTEXT(" Left-> \t "); print_node(prob, curr_node_idx);
PRINTTEXT(" Right->\t "); print_node(prob, prob->iter);
if (prob->stgs->verbose) {
PRINTTEXT(" Left-> \t "); print_node(prob, curr_node_idx);
PRINTTEXT(" Right->\t "); print_node(prob, prob->iter);
}
#endif
}

Expand Down Expand Up @@ -168,7 +172,7 @@ void set_prob(ecos_bb_pwork* prob, char* bool_node_id, pfloat* int_node_id){
}

#if MI_PRINTLEVEL > 1
print_ecos_h(prob);
if (prob->stgs->verbose){ print_ecos_h(prob); }
#endif

}
Expand Down Expand Up @@ -206,8 +210,8 @@ void get_bounds(idxint node_idx, ecos_bb_pwork* prob){
set_prob( prob, get_bool_node_id(node_idx,prob), get_int_node_id(node_idx, prob) );
ret_code = ECOS_solve(prob->ecos_prob);

#if MI_PRINTLEVEL > 1
print_ecos_solution(prob);
#if MI_PRINTLEVEL > 1
if (prob->stgs->verbose){ print_ecos_solution(prob); }
#endif

if (ret_code == ECOS_OPTIMAL){
Expand All @@ -230,14 +234,14 @@ void get_bounds(idxint node_idx, ecos_bb_pwork* prob){
prob->nodes[node_idx].status = MI_SOLVED_BRANCHABLE;

#if MI_PRINTLEVEL > 1
PRINTTEXT("Rounded Solution:\n");
if (prob->stgs->verbose){ PRINTTEXT("Rounded Solution:\n"); }
#endif

set_prob(prob, prob->tmp_bool_node_id, prob->tmp_int_node_id);
ret_code = ECOS_solve(prob->ecos_prob);

#if MI_PRINTLEVEL > 1
print_ecos_solution(prob);
if (prob->stgs->verbose){ print_ecos_solution(prob); }
#endif

if (ret_code == ECOS_OPTIMAL){
Expand All @@ -253,10 +257,12 @@ void get_bounds(idxint node_idx, ecos_bb_pwork* prob){
if (prob->nodes[node_idx].U < prob->global_U){

#if MI_PRINTLEVEL > 1
PRINTTEXT("New optimal solution, U: %.2f\n", prob->nodes[node_idx].U);
print_ecos_xequil(prob);
print_ecos_c(prob);
print_ecos_solution(prob);
if (prob->stgs->verbose){
PRINTTEXT("New optimal solution, U: %.2f\n", prob->nodes[node_idx].U);
print_ecos_xequil(prob);
print_ecos_c(prob);
print_ecos_solution(prob);
}
#endif

store_solution(prob);
Expand Down Expand Up @@ -301,8 +307,10 @@ void initialize_root(ecos_bb_pwork* prob){
idxint ECOS_BB_solve(ecos_bb_pwork* prob){

#if MI_PRINTLEVEL > 0
PRINTTEXT("Iter\tLower Bound\tUpper Bound\tGap\n");
PRINTTEXT("================================================\n");
if (prob->stgs->verbose){
PRINTTEXT("Iter\tLower Bound\tUpper Bound\tGap\n");
PRINTTEXT("================================================\n");
}
#endif

/* Initialize to root node and execute steps 1 on slide 6 */
Expand All @@ -319,7 +327,7 @@ idxint ECOS_BB_solve(ecos_bb_pwork* prob){
while ( should_continue(prob, curr_node_idx) ){

#if MI_PRINTLEVEL > 0
print_progress(prob);
if (prob->stgs->verbose){ print_progress(prob); }
#endif

++(prob->iter);
Expand All @@ -341,7 +349,7 @@ idxint ECOS_BB_solve(ecos_bb_pwork* prob){
load_solution(prob);

#if MI_PRINTLEVEL > 0
print_progress(prob);
if (prob->stgs->verbose){ print_progress(prob); }
#endif

return get_ret_code(prob);
Expand Down
15 changes: 15 additions & 0 deletions ecos_bb/ecos_bb_preproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ ecos_bb_pwork* ECOS_BB_setup(
/* switch off ecos prints */
prob->ecos_prob->stgs->verbose = 0;

/* settings */
prob->stgs = (settings *) MALLOC(sizeof(settings));
prob->stgs->maxit = MAXIT;
prob->stgs->gamma = GAMMA;
prob->stgs->delta = DELTA;
prob->stgs->eps = EPS;
prob->stgs->nitref = NITREF;
prob->stgs->abstol = ABSTOL;
prob->stgs->feastol = FEASTOL;
prob->stgs->reltol = RELTOL;
prob->stgs->abstol_inacc = ATOL_INACC;
prob->stgs->feastol_inacc = FTOL_INACC;
prob->stgs->reltol_inacc = RTOL_INACC;
prob->stgs->verbose = VERBOSE;

#if MI_PRINTLEVEL > 2

Expand Down Expand Up @@ -244,6 +258,7 @@ void ECOS_BB_cleanup(ecos_bb_pwork* prob, idxint num_vars_keep){
FREE(prob->z);
FREE(prob->s);
FREE(prob->best_info);
FREE(prob->stgs);
FREE(prob);
}

Expand Down
3 changes: 3 additions & 0 deletions include/ecos_bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ typedef struct ecos_bb_pwork{
idxint* Gir_new;
pfloat* h_new;

/* settings struct */
settings* stgs;

} ecos_bb_pwork;

ecos_bb_pwork* ECOS_BB_setup(
Expand Down
17 changes: 9 additions & 8 deletions test/bb_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int test_1a_bool(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 1, bool_idx, 0 , NULL);
prob->stgs->verbose = 0;

printf("Passed setup \n");

Expand Down Expand Up @@ -65,7 +66,7 @@ int test_1a_int(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 0 , NULL, 2, int_idx);

prob->stgs->verbose = 0;
printf("Passed setup \n");

ret_code = ECOS_BB_solve(prob);
Expand Down Expand Up @@ -104,7 +105,7 @@ int test_1b(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 1, bool_idx, 0 , NULL);

prob->stgs->verbose = 0;
printf("Passed setup \n");

ret_code = ECOS_BB_solve(prob);
Expand Down Expand Up @@ -143,7 +144,7 @@ int test_2(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 2, bool_idx, 0 , NULL);

prob->stgs->verbose = 0;
ret_code = ECOS_BB_solve(prob);

pass = 1;
Expand Down Expand Up @@ -181,7 +182,7 @@ int test_3(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 1, bool_idx, 0 , NULL);

prob->stgs->verbose = 0;
ret_code = ECOS_BB_solve(prob);

pass = 1;
Expand Down Expand Up @@ -219,7 +220,7 @@ int test_4(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 6, bool_idx, 0, NULL);

prob->stgs->verbose = 0;
ret_code = ECOS_BB_solve(prob);

pass = 1;
Expand Down Expand Up @@ -258,7 +259,7 @@ int test_5(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 6, bool_idx, 0, NULL);

prob->stgs->verbose = 0;
ret_code = ECOS_BB_solve(prob);

pass = 1;
Expand Down Expand Up @@ -297,7 +298,7 @@ int test_6(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 6, bool_idx, 0, NULL);

prob->stgs->verbose = 0;
printf("Obj:");
for (i=0; i<n; ++i){
printf("%f ", prob->ecos_prob->c[i]);
Expand Down Expand Up @@ -351,7 +352,7 @@ int test_7(){
feas_Gx, feas_Gp, feas_Gi,
NULL, NULL, NULL,
feas_c, feas_h, NULL, 5, bool_idx, 0, NULL);

prob->stgs->verbose = 0;
tic(&t);
ret_code = ECOS_BB_solve(prob);
pfloat msRuntime = toc(&t);
Expand Down

0 comments on commit cc635e5

Please sign in to comment.