Skip to content

Commit

Permalink
- added LOG_IPOPT_ERROR for following max error in the optimization
Browse files Browse the repository at this point in the history
  - added example for LOG_IPOPT_ERROR



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19376 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Mar 2, 2014
1 parent 549b7c8 commit 0dcb903
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
59 changes: 42 additions & 17 deletions SimulationRuntime/c/optimization/constraints/evalfG.c
Expand Up @@ -54,6 +54,7 @@ static inline int evalG22(Number *g, IPOPT_DATA_ *iData, double *x0, int i);
static inline int evalG23(Number *g, IPOPT_DATA_ *iData, double *x0, int i);
static int diff_symColoredODE(double *v, double t, IPOPT_DATA_ *iData, double **J);
static int num_diff_symColoredODE(double *v, double t, IPOPT_DATA_ *iData, double **J);
static int printMaxError(IPOPT_DATA_ *iData, double *g,double time, double * max_err , double * tt, double *xi);

/*!
* eval s.t.
Expand All @@ -62,11 +63,11 @@ static int num_diff_symColoredODE(double *v, double t, IPOPT_DATA_ *iData, doubl
Bool evalfG(Index n, double * v, Bool new_x, int m, Number *g, void * useData)
{
IPOPT_DATA_ *iData;
//int i,k,j;
int i,k;
int i,k,j;
double *x0;
//double inf_p = 0;

double max_err = -1;
double max_err_time = -1;
double max_err_xi = -1;

iData = (IPOPT_DATA_ *) useData;
for(i=0, k=0, x0=v; i<1; ++i, x0=iData->x3){
Expand All @@ -82,22 +83,23 @@ Bool evalfG(Index n, double * v, Bool new_x, int m, Number *g, void * useData)
functionODE_(x0, x0 + iData->nx, iData->time[0], iData->dotx0, iData);
functionODE_(iData->x1, iData->u1, iData->time[1], iData->dotx1, iData);
evalG21(g + k, iData, x0, i);
//for(j = 0; j<(int)iData->nJ; ++j)
// inf_p = fmax(fabs(g[j]),inf_p);
if(ACTIVE_STREAM(LOG_IPOPT_ERROR))
printMaxError(iData,g,iData->time[1],&max_err, &max_err_time, &max_err_xi);

k += iData->nJ;

/*2*/
functionODE_(iData->x2, iData->u2, iData->time[2], iData->dotx2, iData);
evalG22(g + k, iData, x0, i);
//for(j = 0; j<(int)iData->nJ; ++j)
// inf_p = fmax(fabs(g[j]),inf_p);
if(ACTIVE_STREAM(LOG_IPOPT_ERROR))
printMaxError(iData,g,iData->time[1],&max_err, &max_err_time, &max_err_xi);
k += iData->nJ;

/*3*/
functionODE_(iData->x3, iData->u3, iData->time[3], iData->dotx3, iData);
evalG23(g + k, iData, x0, i);
//for(j = 0; j<(int)iData->nJ; ++j)
// inf_p = fmax(fabs(g[j]),inf_p);
if(ACTIVE_STREAM(LOG_IPOPT_ERROR))
printMaxError(iData,g,iData->time[1],&max_err, &max_err_time, &max_err_xi);
k += iData->nJ;
}

Expand All @@ -113,25 +115,29 @@ Bool evalfG(Index n, double * v, Bool new_x, int m, Number *g, void * useData)
/*1*/
functionODE_(iData->x1, iData->u1, iData->time[i*iData->deg + 1], iData->dotx1, iData);
evalG11(g + k, iData, x0, i);
//for(j = 0; j<(int)iData->nJ; ++j)
// inf_p = fmax(fabs(g[j]),inf_p);
if(ACTIVE_STREAM(LOG_IPOPT_ERROR))
printMaxError(iData,g,iData->time[1],&max_err, &max_err_time, &max_err_xi);
k += iData->nJ;

/*2*/
functionODE_(iData->x2, iData->u2, iData->time[i*iData->deg + 2], iData->dotx2, iData);
evalG12(g + k, iData, x0, i);
//for(j = 0; j<(int)iData->nJ; ++j)
// inf_p = fmax(fabs(g[j]),inf_p);
if(ACTIVE_STREAM(LOG_IPOPT))
printMaxError(iData,g,iData->time[1],&max_err, &max_err_time, &max_err_xi);
k += iData->nJ;

/*3*/
functionODE_(iData->x3, iData->u3, iData->time[i*iData->deg + 3], iData->dotx3, iData);
evalG13(g + k, iData, x0, i);
//for(j = 0; j<(int)iData->nJ; ++j)
// inf_p = fmax(fabs(g[j]),inf_p);
if(ACTIVE_STREAM(LOG_IPOPT_ERROR))
printMaxError(iData,g,iData->time[1],&max_err, &max_err_time, &max_err_xi);
k += iData->nJ;
}
//printf("\ninf_p = %g\n",inf_p);
if(ACTIVE_STREAM(LOG_IPOPT_ERROR)){
printf("\n\tmax_err = %g",max_err);
printf("\ttimepoint = %g",max_err_time);
printf("\tvariable = %i\n",(int)max_err_xi);
}
return TRUE;
}

Expand Down Expand Up @@ -403,6 +409,25 @@ static inline int evalG23(Number *g, IPOPT_DATA_ *iData, double *x0, int i)

}

static int printMaxError(IPOPT_DATA_ *iData, double *g,double t, double * max_err,double * tt, double *xi)
{
double inf_p ;
double tmp;
int j;

inf_p = *max_err;

for(j = 0; j<(int)iData->nJ; ++j){
tmp = fabs(g[j]);
if(tmp > inf_p){
inf_p = tmp;
*tt = t;
*xi = j;
}
}
*max_err = inf_p;
}


#undef DF_STEP
#endif
6 changes: 4 additions & 2 deletions SimulationRuntime/c/util/omc_error.c
Expand Up @@ -53,6 +53,7 @@ const char *LOG_STREAM_NAME[LOG_MAX] = {
"LOG_IPOPT_FULL",
"LOG_IPOPT_JAC",
"LOG_IPOPT_HESSE",
"LOG_IPOPT_ERROR",
"LOG_JAC",
"LOG_LS",
"LOG_LS_V",
Expand Down Expand Up @@ -83,8 +84,9 @@ const char *LOG_STREAM_DESC[LOG_MAX] = {
"additional information during initialization", /* LOG_INIT */
"information from Ipopt", /* LOG_IPOPT */
"more information from Ipopt", /* LOG_IPOPT_FULL*/
"check jacobian matrix with Ipopt", /* LOG_IPOPT_JAC*/
"check hessian matrix with Ipopt", /* LOG_IPOPT_HESSE*/
"check jacobian matrix with Ipopt", /* LOG_IPOPT_JAC*/
"check hessian matrix with Ipopt", /* LOG_IPOPT_HESSE*/
"print max error in the optimization", /* LOG_IPOPT_ERROR*/
"outputs the jacobian matrix used by dassl", /* LOG_JAC */
"logging for linear systems", /* LOG_LS */
"verbose logging of linear systems", /* LOG_LS_V */
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/util/omc_error.h
Expand Up @@ -85,6 +85,7 @@ enum LOG_STREAM
LOG_IPOPT_FULL,
LOG_IPOPT_JAC,
LOG_IPOPT_HESSE,
LOG_IPOPT_ERROR,
LOG_JAC,
LOG_LS,
LOG_LS_V,
Expand Down

0 comments on commit 0dcb903

Please sign in to comment.