Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some basic printing #37

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 84 additions & 33 deletions dense_qp/x_dense_qp_ipm.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ void CREATE_DENSE_QP_IPM_ARG(struct DENSE_QP_DIM *dim, struct DENSE_QP_IPM_ARG *
void SET_DEFAULT_DENSE_QP_IPM_ARG(enum HPIPM_MODE mode, struct DENSE_QP_IPM_ARG *arg)
{

// set common default arguments
arg->print_level = 0;

// set mode-specific default arguments
if(mode==SPEED_ABS)
{
arg->mu0 = 1e1;
Expand Down Expand Up @@ -683,29 +687,53 @@ int SOLVE_DENSE_QP_IPM(struct DENSE_QP *qp, struct DENSE_QP_SOL *qp_sol, struct
VECNRM_INF(cws->ne, &str_res_b, 0, &qp_res[1]);
VECNRM_INF(cws->nc, &str_res_d, 0, &qp_res[2]);
VECNRM_INF(cws->nc, &str_res_m, 0, &qp_res[3]);
if(arg->print_level > 0)
{
if(kk%10 == 0)
{
printf("=======================================================================================================\n");
printf("it. # res_g res_b res_d res_m alpha mu \n");
printf("=======================================================================================================\n");
}
printf("%-10d %-15e %-15e %-15e %-15e %-15e %-15e\n", kk, qp_res[0], qp_res[1], qp_res[2], qp_res[3], cws->alpha, cws->mu);
}
}

ws->iter = kk;

// max iteration number reached
if(kk == arg->iter_max)
return 1;

// min step lenght
if(cws->alpha <= arg->alpha_min)
return 2;
// max iteration number reached
if(kk == arg->iter_max) {
if (arg->print_level > 0)
printf(" \n -> ERROR: maximum number of iterations reached, exiting.\n\n");
return 1;
}

// min step lenght
if(cws->alpha <= arg->alpha_min) {
if (arg->print_level > 0)
printf(" \n -> ERROR: minimum step size reached, exiting.\n\n");
return 2;
}

// NaN in the solution
#ifdef USE_C99_MATH
if(isnan(cws->mu)) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#else
if(cws->mu != cws->mu) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#endif

// NaN in the solution
#ifdef USE_C99_MATH
if(isnan(cws->mu))
return 3;
#else
if(cws->mu != cws->mu)
return 3;
#endif

// normal return
return 0;
// normal return
if (arg->print_level > 0)
printf(" \n -> SOLUTION FOUND. \n\n");
return 0;

}

Expand Down Expand Up @@ -1044,6 +1072,15 @@ blasfeo_print_tran_dvec(cws->nc, ws->sol_step->t, 0);
VECNRM_INF(cws->nc, &str_res_d, 0, &qp_res[2]);
VECNRM_INF(cws->nc, &str_res_m, 0, &qp_res[3]);

if(arg->print_level > 0){
if(kk%10 == 0){
printf("=======================================================================================================\n");
printf("it. # res_g res_b res_d res_m alpha mu \n");
printf("=======================================================================================================\n");
}
printf("%-10d %-15e %-15e %-15e %-15e %-15e %-15e\n", kk, qp_res[0], qp_res[1], qp_res[2], qp_res[3], cws->alpha, cws->mu);
}

#if 0
printf("%e %e %e\n", cws->alpha, cws->alpha_prim, cws->alpha_dual);
#endif
Expand All @@ -1064,25 +1101,39 @@ printf("iter %3d alpha %1.3e %1.3e sigma %1.3e ndp %3d %3d itref %d %d

ws->iter = kk;

// max iteration number reached
if(kk == arg->iter_max)
return 1;

// min step lenght
if(cws->alpha <= arg->alpha_min)
return 2;

// NaN in the solution
// max iteration number reached
if(kk == arg->iter_max) {
if (arg->print_level > 0)
printf(" \n -> ERROR: maximum number of iterations reached, exiting.\n\n");
return 1;
}

// min step lenght
if(cws->alpha <= arg->alpha_min) {
if (arg->print_level > 0)
printf(" \n -> ERROR: minimum step size reached, exiting.\n\n");
return 2;
}

// NaN in the solution
#ifdef USE_C99_MATH
if(isnan(cws->mu))
return 3;
if(isnan(cws->mu)) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#else
if(cws->mu != cws->mu)
return 3;
if(cws->mu != cws->mu) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#endif

// normal return
return 0;
// normal return
if (arg->print_level > 0)
printf(" \n -> SOLUTION FOUND. \n\n");
return 0;

}

Expand Down
1 change: 1 addition & 0 deletions include/hpipm_d_dense_qp_ipm.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct d_dense_qp_ipm_arg
int abs_form; // absolute IPM formulation
int comp_res_exit; // compute residuals on exit (only for abs_form==1)
int memsize;
int print_level;
};


Expand Down
1 change: 1 addition & 0 deletions include/hpipm_d_ocp_qp_ipm.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct d_ocp_qp_ipm_arg
int comp_dual_sol; // dual solution (only for abs_form==1)
int comp_res_exit; // compute residuals on exit (only for abs_form==1 and comp_dual_sol==1)
int memsize;
int print_level;
};


Expand Down
1 change: 1 addition & 0 deletions include/hpipm_s_dense_qp_ipm.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct s_dense_qp_ipm_arg
int abs_form; // absolute IPM formulation
int comp_res_exit; // compute residuals on exit (only for abs_form==1)
int memsize;
int print_level;
};


Expand Down
1 change: 1 addition & 0 deletions include/hpipm_s_ocp_qp_ipm.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct s_ocp_qp_ipm_arg
int comp_dual_sol; // dual solution (only for abs_form==1)
int comp_res_exit; // compute residuals on exit (only for abs_form==1 and comp_dual_sol==1)
int memsize;
int print_level;
};


Expand Down
101 changes: 76 additions & 25 deletions ocp_qp/x_ocp_qp_ipm.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ void CREATE_OCP_QP_IPM_ARG(struct OCP_QP_DIM *dim, struct OCP_QP_IPM_ARG *arg, v
void SET_DEFAULT_OCP_QP_IPM_ARG(enum HPIPM_MODE mode, struct OCP_QP_IPM_ARG *arg)
{

// set common default arguments
arg->print_level = 1;

// set mode-specific default arguments
if(mode==SPEED_ABS)
{
arg->mu0 = 1e1;
Expand Down Expand Up @@ -970,29 +974,54 @@ int SOLVE_OCP_QP_IPM(struct OCP_QP *qp, struct OCP_QP_SOL *qp_sol, struct OCP_QP
VECNRM_INF(cws->ne, &str_res_b, 0, &qp_res[1]);
VECNRM_INF(cws->nc, &str_res_d, 0, &qp_res[2]);
VECNRM_INF(cws->nc, &str_res_m, 0, &qp_res[3]);

if(arg->print_level > 0)
{
if(kk%10 == 0)
{
printf("=======================================================================================================\n");
printf("it. # res_g res_b res_d res_m alpha mu \n");
printf("=======================================================================================================\n");
}
printf("%-10d %-15e %-15e %-15e %-15e %-15e %-15e\n", kk, qp_res[0], qp_res[1], qp_res[2], qp_res[3], cws->alpha, cws->mu);
}
}

ws->iter = kk;

// max iteration number reached
if(kk == arg->iter_max)
return 1;

// min step lenght
if(cws->alpha <= arg->alpha_min)
return 2;

// NaN in the solution
#ifdef USE_C99_MATH
if(isnan(cws->mu))
return 3;
#else
if(cws->mu != cws->mu)
return 3;
#endif
// max iteration number reached
if(kk == arg->iter_max) {
if (arg->print_level > 0)
printf(" \n -> ERROR: maximum number of iterations reached, exiting.\n\n");
return 1;
}

// min step lenght
if(cws->alpha <= arg->alpha_min) {
if (arg->print_level > 0)
printf(" \n -> ERROR: minimum step size reached, exiting.\n\n");
return 2;
}

// NaN in the solution
#ifdef USE_C99_MATH
if(isnan(cws->mu)) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#else
if(cws->mu != cws->mu) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#endif

// normal return
return 0;
// normal return
if (arg->print_level > 0)
printf(" \n -> SOLUTION FOUND. \n\n");
return 0;

}

Expand All @@ -1009,7 +1038,7 @@ int SOLVE_OCP_QP_IPM(struct OCP_QP *qp, struct OCP_QP_SOL *qp_sol, struct OCP_QP
VECNRM_INF(cws->nc, &str_res_d, 0, &qp_res[2]);
VECNRM_INF(cws->nc, &str_res_m, 0, &qp_res[3]);

//printf("\niter %d\t%e\t%e\t%e\t%e\n", -1, qp_res[0], qp_res[1], qp_res[2], qp_res[3]);
// printf("\niter %d\t%e\t%e\t%e\t%e\n", -1, qp_res[0], qp_res[1], qp_res[2], qp_res[3]);

REAL itref_qp_norm[4] = {0,0,0,0};
REAL itref_qp_norm0[4] = {0,0,0,0};
Expand Down Expand Up @@ -1420,8 +1449,16 @@ exit(1);
VECNRM_INF(cws->nc, &str_res_d, 0, &qp_res[2]);
VECNRM_INF(cws->nc, &str_res_m, 0, &qp_res[3]);

//printf("\niter %d\t%e\t%e\t%e\t%e\n", kk, qp_res[0], qp_res[1], qp_res[2], qp_res[3]);

if(arg->print_level > 0)
{
if(kk%10 == 0)
{
printf("=======================================================================================================\n");
printf("it. # res_g res_b res_d res_m alpha mu \n");
printf("=======================================================================================================\n");
}
printf("%-10d %-15e %-15e %-15e %-15e %-15e %-15e\n", kk, qp_res[0], qp_res[1], qp_res[2], qp_res[3], cws->alpha, cws->mu);
}
}

ws->iter = kk;
Expand All @@ -1433,23 +1470,37 @@ exit(1);
#endif

// max iteration number reached
if(kk == arg->iter_max)
if(kk == arg->iter_max) {
if (arg->print_level > 0)
printf(" \n -> ERROR: maximum number of iterations reached, exiting.\n\n");
return 1;
}

// min step lenght
if(cws->alpha <= arg->alpha_min)
if(cws->alpha <= arg->alpha_min) {
if (arg->print_level > 0)
printf(" \n -> ERROR: minimum step size reached, exiting.\n\n");
return 2;
}

// NaN in the solution
#ifdef USE_C99_MATH
if(isnan(cws->mu))
if(isnan(cws->mu)) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#else
if(cws->mu != cws->mu)
if(cws->mu != cws->mu) {
if (arg->print_level > 0)
printf(" \n -> ERROR: NaN detected, exiting.\n\n");
return 3;
}
#endif

// normal return
if (arg->print_level > 0)
printf(" \n -> SOLUTION FOUND. \n\n");
return 0;

}
Expand Down