Skip to content

Commit

Permalink
- fixed initial guess in optimization
Browse files Browse the repository at this point in the history
- added flag for initial guess file for externalInput 
- added flag for number of points in a subinterval in optimization                                               
 - support approximation order 1 and 5 in optimization         
- added test for initial guess in optimization
 - creat result with order 1
 - using the result for order 5 



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20561 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed May 12, 2014
1 parent 343c89f commit 94047a8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
Expand Up @@ -230,8 +230,8 @@ static inline void init_ipopt_data(OptData *optData){
for(i = 0, shift = 0; i < nsi; ++i){
for(j = 0; j < np; ++j, shift+=nv){
memcpy(data->localData[0]->realVars, optData->v[i][j], nReal*sizeof(double));
externalInputUpdate(data);
data->localData[0]->timeValue = (modelica_real) optData->time.t[i][j];
externalInputUpdate(data);

for(l = 0; l<nx; ++l)
ipop->vopt[l + shift] = optData->v[i][j][l]*optData->bounds.scalF[l];
Expand Down
12 changes: 11 additions & 1 deletion SimulationRuntime/c/optimization/DataManagement/MoveData.c
Expand Up @@ -34,6 +34,7 @@
#include "../OptimizerData.h"
#include "../OptimizerLocalFunction.h"
#include "../../simulation/results/simulation_result.h"
#include "../../simulation/options.h"

static inline void pickUpDim(OptDataDim * dim, DATA* data);
static inline void pickUpTime(OptDataTime * time, OptDataDim * dim, DATA* data);
Expand Down Expand Up @@ -87,7 +88,16 @@ int pickUpModelData(DATA* data, SOLVER_INFO* solverInfo){
*/
static inline void pickUpDim(OptDataDim * dim, DATA* data){

dim->np = 3; /*ToDo*/
char * cflags = NULL;
cflags = (char*)omc_flagValue[FLAG_OPTIZER_NP];
if(cflags){
dim->np = atoi(cflags);
if(dim->np != 1 && dim->np!=3){
warningStreamPrint(LOG_STDOUT, 0, "FLAG_OPTIZER_NP is %i. Currently optimizer support only 1 and 3.\nFLAG_OPTIZER_NP set of 3", dim->np);
dim->np = 3;
}
}else
dim->np = 3; /*ToDo*/
dim->nx = data->modelData.nStates;
dim->nu = data->modelData.nInputVars;
dim->nv = dim->nx + dim->nu;
Expand Down
3 changes: 2 additions & 1 deletion SimulationRuntime/c/optimization/eval_all/EvalG.c
Expand Up @@ -266,7 +266,8 @@ Bool evalfDiffG(Index n, double * vopt, Bool new_x, Index m, Index njac, Index *
for(i = 1; i < nsi; ++i){
for(j = 0; j < np; ++j){
for(l = 0; l < nJ; ++l){
values[k++] = 1.0;
if(l < nx)
values[k++] = 1.0;
for(ii = 0; ii < nv; ++ii)
if(J[l][ii])
values[k++] = (modelica_real)((ii == l && l < nx) ? optData->J[i][j][l][ii] - 1.0 : optData->J[i][j][l][ii]);
Expand Down
13 changes: 12 additions & 1 deletion SimulationRuntime/c/simulation/solver/external_input.c
Expand Up @@ -41,14 +41,25 @@
#include "simulation/simulation_runtime.h"
#include "simulation/solver/solver_main.h"
#include "simulation/solver/model_help.h"
#include "simulation/options.h"

int externalInputallocate(DATA* data)
{
FILE * pFile = NULL;
int n,m,c;
int i,j;

pFile = fopen("externalInput.csv","r");
{
char * cflags = NULL;
cflags = (char*)omc_flagValue[FLAG_INPUT_FILE];
if(cflags){
pFile = fopen(cflags,"r");
if(pFile == NULL)
warningStreamPrint(LOG_STDOUT, 0, "OMC can't find the file %s.",cflags);
}else
pFile = fopen("externalInput.csv","r");
}


data->simulationInfo.external_input.active = (modelica_boolean) (pFile != NULL);
n = 0;
Expand Down
12 changes: 10 additions & 2 deletions SimulationRuntime/c/util/simulation_options.c
Expand Up @@ -35,13 +35,14 @@ const char *FLAG_NAME[FLAG_MAX+1] = {

/* FLAG_CLOCK */ "clock",
/* FLAG_CPU */ "cpu",
/* FLAG_EMIT_PROTECTED */ "emit_protected",
/* FLAG_EMIT_PROTECTED */ "emit_protected",
/* FLAG_F */ "f",
/* FLAG_HELP */ "help",
/* FLAG_IIF */ "iif",
/* FLAG_IIM */ "iim",
/* FLAG_IIT */ "iit",
/* FLAG_ILS */ "ils",
/* FLAG_INPUT_FILE */ "exInputFile",
/* FLAG_INTERACTIVE */ "interactive",
/* FLAG_IOM */ "iom",
/* FLAG_IPOPT_HESSE*/ "ipopt_hesse",
Expand All @@ -60,6 +61,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
/* FLAG_OUTPUT */ "output",
/* FLAG_OVERRIDE */ "override",
/* FLAG_OVERRIDE_FILE */ "overrideFile",
/* FLAG_OPTIZER_NP */ "optimizerNP",
/* FLAG_PORT */ "port",
/* FLAG_R */ "r",
/* FLAG_S */ "s",
Expand All @@ -73,13 +75,14 @@ const char *FLAG_DESC[FLAG_MAX+1] = {

/* FLAG_CLOCK */ "selects the type of clock to use -clock=RT, -clock=CYC or -clock=CPU",
/* FLAG_CPU */ "dumps the cpu-time into the results-file",
/* FLAG_EMIT_PROTECTED */ "emits protected variables to the result-file",
/* FLAG_EMIT_PROTECTED */ "emits protected variables to the result-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get detailed information that specifies the command-line flag",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
/* FLAG_IIM */ "value specifies the initialization method",
/* FLAG_IIT */ "[double] value specifies a time for the initialization of the model",
/* FLAG_ILS */ "[int] default: 1",
/* FLAG_INPUT_FILE */ "value specifies an external file with inputs for the simulation/optimization of the model",
/* FLAG_INTERACTIVE */ "specify interactive simulation",
/* FLAG_IOM */ "value specifies the initialization optimization method",
/* FLAG_IPOPT_HESSE */ "value specifies the hessian for Ipopt",
Expand All @@ -98,6 +101,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
/* FLAG_OUTPUT */ "output the variables a, b and c at the end of the simulation to the standard output",
/* FLAG_OVERRIDE */ "override the variables or the simulation settings in the XML setup file",
/* FLAG_OVERRIDE_FILE */ "will override the variables or the simulation settings in the XML setup file with the values from the file",
/* FLAG_OPTIZER_NP */ "value specifies the number of points in a subinterval",
/* FLAG_PORT */ "value specifies interactive simulation port",
/* FLAG_R */ "value specifies a new result file than the default Model_res.mat",
/* FLAG_S */ "value specifies the solver",
Expand All @@ -119,6 +123,7 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
/* FLAG_IIT */ "value specifies a time for the initialization of the model",
/* FLAG_ILS */ "value specifies the number of steps for homotopy method (required: -iim=symbolic) or\n'start value homotopy' method (required: -iim=numeric -iom=nelder_mead_ex)",
/* FLAG_INTERACTIVE */ "specify interactive simulation",
/* FLAG_INPUT_FILE */ "value specifies an external file with inputs for the simulation/optimization of the model",
/* FLAG_IOM */ "value specifies the initialization optimization method",
/* FLAG_IPOPT_HESSE */ "value specifies the hessematrix for Ipopt(OMC, BFGS, const)",
/* FLAG_IPOPT_JAC */ "value specifies the jacobian for Ipopt(SYM, NUM, NUMDENSE)",
Expand All @@ -136,6 +141,7 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
/* FLAG_OUTPUT */ "output the variables a, b and c at the end of the simulation to the standard output\n time = value, a = value, b = value, c = value",
/* FLAG_OVERRIDE */ "override the variables or the simulation settings in the XML setup file\n e.g. var1=start1,var2=start2,par3=start3,startTime=val1,stopTime=val2,stepSize=val3,\n tolerance=val4,solver=\"see -s\",outputFormat=\"mat|plt|csv|empty\",variableFilter=\"filter\"",
/* FLAG_OVERRIDE_FILE */ "will override the variables or the simulation settings in the XML setup file with the values from the file\n note that: -overrideFile CANNOT be used with -override\n use when variables for -override are too many and do not fit in command line size\n overrideFileName contains lines of the form: var1=start1",
/* FLAG_OPTIZER_NP */ "value specifies the number of points in a subinterval. Currently support number 1 and 3.",
/* FLAG_PORT */ "value specifies interactive simulation port",
/* FLAG_R */ "value specifies a new result file than the default Model_res.mat",
/* FLAG_S */ "value specifies the solver",
Expand All @@ -156,6 +162,7 @@ const int FLAG_TYPE[FLAG_MAX] = {
/* FLAG_IIM */ FLAG_TYPE_OPTION,
/* FLAG_IIT */ FLAG_TYPE_OPTION,
/* FLAG_ILS */ FLAG_TYPE_OPTION,
/* FLAG_INPUT_FILE */ FLAG_TYPE_OPTION,
/* FLAG_INTERACTIVE */ FLAG_TYPE_FLAG,
/* FLAG_IOM */ FLAG_TYPE_OPTION,
/* FLAG_IPOPT_HESSE */ FLAG_TYPE_OPTION,
Expand All @@ -174,6 +181,7 @@ const int FLAG_TYPE[FLAG_MAX] = {
/* FLAG_OUTPUT */ FLAG_TYPE_OPTION,
/* FLAG_OVERRIDE */ FLAG_TYPE_OPTION,
/* FLAG_OVERRIDE_FILE */ FLAG_TYPE_OPTION,
/* FLAG_OPTIZER_NP */ FLAG_TYPE_OPTION,
/* FLAG_PORT */ FLAG_TYPE_OPTION,
/* FLAG_R */ FLAG_TYPE_OPTION,
/* FLAG_S */ FLAG_TYPE_OPTION,
Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/util/simulation_options.h
Expand Up @@ -49,6 +49,7 @@ enum _FLAG
FLAG_IIM,
FLAG_IIT,
FLAG_ILS,
FLAG_INPUT_FILE,
FLAG_INTERACTIVE,
FLAG_IOM,
FLAG_IPOPT_HESSE,
Expand All @@ -67,6 +68,7 @@ enum _FLAG
FLAG_OUTPUT,
FLAG_OVERRIDE,
FLAG_OVERRIDE_FILE,
FLAG_OPTIZER_NP,
FLAG_PORT,
FLAG_R,
FLAG_S,
Expand Down

0 comments on commit 94047a8

Please sign in to comment.