Skip to content

Commit

Permalink
- improve output format
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19429 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Mar 4, 2014
1 parent ac1dc0d commit 6479476
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
32 changes: 19 additions & 13 deletions SimulationRuntime/c/optimization/constraints/evalfG.c
Expand Up @@ -54,7 +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);
static int printMaxError(IPOPT_DATA_ *iData, double *g,double time, double * max_err , double * tt, int *xi);

/*!
* eval s.t.
Expand All @@ -67,7 +67,7 @@ Bool evalfG(Index n, double * v, Bool new_x, int m, Number *g, void * useData)
double *x0;
double max_err = -1;
double max_err_time = -1;
double max_err_xi = -1;
int max_err_xi = -1;

iData = (IPOPT_DATA_ *) useData;
for(i=0, k=0, x0=v; i<1; ++i, x0=iData->x3){
Expand Down Expand Up @@ -134,9 +134,11 @@ Bool evalfG(Index n, double * v, Bool new_x, int m, Number *g, void * useData)
k += iData->nJ;
}
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);

if(max_err_xi < iData->nx)
printf("\nmax error for |%s(%g) - collocation_poly| = %g\n",iData->data->modelData.realVarsData[max_err_xi].info.name,max_err_time,max_err);
else
printf("\nmax error for |cosntrain[%i](%g)| = %g\n",iData->data->modelData.realVarsData[max_err_xi].info.name, max_err_time, max_err);
}
return TRUE;
}
Expand Down Expand Up @@ -409,23 +411,27 @@ 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)
static int printMaxError(IPOPT_DATA_ *iData, double *g,double t, double * max_err, double * tt, int *xi)
{
double inf_p ;
double tmp;
int j;

inf_p = *max_err;

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

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


Expand Down
Expand Up @@ -172,6 +172,7 @@ int allocateIpoptData(IPOPT_DATA_ *iData)
iData->Hg[i] = (short*) calloc(iData->nv, sizeof(short));

iData->dt = (double*)malloc((iData->nsi) *sizeof(double));
iData->input_name = (char**)malloc(iData->nv*sizeof(char*));

if(iData->nc > 0)
for(i = iData->nx; i<ng; i+=iData->nJ)
Expand Down Expand Up @@ -284,6 +285,7 @@ int freeIpoptData(IPOPT_DATA_ *iData)
free(iData->pFile);
}

free(iData->input_name);
free(iData);
iData = NULL;
return 0;
Expand Down Expand Up @@ -708,7 +710,8 @@ static int optimizer_bounds_setings(DATA *data, IPOPT_DATA_ *iData)
{
int i, j;
modelica_boolean *tmp = (modelica_boolean*)malloc(iData->nv*sizeof(modelica_boolean));
char **tmpname = (char**)malloc(iData->nv*sizeof(char*));
char **tmpname = iData->input_name;

double *start = iData->start_u;

for(i =0;i<iData->nx;++i){
Expand Down Expand Up @@ -789,7 +792,6 @@ static int optimizer_bounds_setings(DATA *data, IPOPT_DATA_ *iData)
}

free(tmp);
free(tmpname);
return 0;
}

Expand Down Expand Up @@ -845,7 +847,7 @@ static int optimizer_print_step(IPOPT_DATA_ *iData)
if(j < iData->nx)
fprintf(iData->pFile[j], "%s_%i,", iData->data->modelData.realVarsData[j].info.name, k);
else if(j < iData->nv)
fprintf(iData->pFile[j], "%s_%i,", "u", k);
fprintf(iData->pFile[j], "%s_%i,", "u", iData->input_name[j-iData->nx]);
}
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/optimization/ipoptODEstruct.h
Expand Up @@ -205,6 +205,8 @@ typedef struct IPOPT_DATA_
double *eps;

modelica_boolean preSim;
char ** input_name;

/*Debuger*/
FILE **pFile;
long index_debug_iter;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/optimization/mainOptimizer/ipoptODE.c
Expand Up @@ -196,7 +196,7 @@ static int res2file(IPOPT_DATA_ *iData,SOLVER_INFO* solverInfo)
pFile = fopen("optimizeInput.csv", "wt");
fprintf(pFile, "%s ", "time");
for(i=0; i< iData->nu; ++i){
sprintf(buffer, "Input%i", i+1);
sprintf(buffer, "%s", iData->input_name[i]);
fprintf(pFile, "%s ", buffer);
}
fprintf(pFile, "%s", "\n");
Expand Down

0 comments on commit 6479476

Please sign in to comment.