00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 #include <acado/utils/acado_utils.hpp>
00036 #include <acado/symbolic_operator/symbolic_operator.hpp>
00037
00038
00039
00040 BEGIN_NAMESPACE_ACADO
00041
00042
00043
00044
00045 SymbolicIndexList::SymbolicIndexList(){
00046
00047 numberOfOperators = 0;
00048 comp = 0;
00049 expression = 0;
00050
00051 int run1 ;
00052 const int numberOfVariableTypes = 11 ;
00053
00054 entryExists = new BooleanType*[numberOfVariableTypes];
00055
00056 nC = 1;
00057 cExist = (BooleanType*)calloc( nC, sizeof(BooleanType) );
00058 cIdx = (int**)calloc( nC, sizeof(int*) );
00059 cDim = (uint*)calloc( nC, sizeof(uint) );
00060
00061 cExist[0] = BT_FALSE;
00062 cIdx [0] = 0;
00063 cDim [0] = 0;
00064
00065 maxNumberOfEntries = new int[numberOfVariableTypes];
00066
00067 variableCounter = 0;
00068 variableIndex = new int*[numberOfVariableTypes];
00069 variableScale = new double*[numberOfVariableTypes];
00070
00071 for( run1 = 0; run1 < numberOfVariableTypes; run1++ ){
00072
00073 maxNumberOfEntries[run1] = 0;
00074 entryExists[run1] = 0;
00075 variableIndex[run1] = 0;
00076 variableScale[run1] = 0;
00077 }
00078 }
00079
00080
00081 SymbolicIndexList::~SymbolicIndexList(){
00082
00083 int run1;
00084
00085 if( expression != NULL ){
00086 for( run1 = 0; run1 < numberOfOperators; run1++ ){
00087 delete expression[run1];
00088 }
00089 free(expression);
00090 }
00091 if( comp != NULL ){
00092 free(comp);
00093 }
00094
00095 const int numberOfVariableTypes = 11 ;
00096
00097 for( run1 = 0; run1 < numberOfVariableTypes; run1++ ){
00098
00099 if( maxNumberOfEntries[run1] > 0 ){
00100
00101 free(entryExists [run1]);
00102 free(variableIndex[run1]);
00103 free(variableScale[run1]);
00104 }
00105 }
00106
00107 free(cExist);
00108
00109 for( run1 = 0; run1 < nC; run1++ ){
00110 if( cIdx[run1] != 0 )
00111 delete[] cIdx[run1];
00112 }
00113 free(cIdx);
00114 free(cDim);
00115
00116 delete[] maxNumberOfEntries;
00117 delete[] variableIndex;
00118 delete[] variableScale;
00119 delete[] entryExists;
00120 }
00121
00122
00123
00124 SymbolicIndexList::SymbolicIndexList( const SymbolicIndexList &arg ){
00125
00126 int run1;
00127
00128 numberOfOperators = arg.numberOfOperators;
00129
00130 if( arg.expression != NULL ){
00131
00132 if( numberOfOperators > 0 ){
00133 expression = (Operator**)calloc(numberOfOperators,sizeof(Operator*));
00134 }
00135 else{
00136 expression = NULL;
00137 }
00138 for( run1 = 0; run1 < numberOfOperators; run1++ ){
00139 expression[run1] = arg.expression[run1]->clone();
00140 }
00141 }
00142 else{
00143 expression = NULL;
00144 }
00145
00146 if( arg.comp != NULL ){
00147 if( numberOfOperators > 0 ){
00148 comp = (int*)calloc(numberOfOperators,sizeof(int));
00149 }
00150 else{
00151 comp = NULL;
00152 }
00153 for( run1 = 0; run1 < numberOfOperators; run1++ ){
00154 comp[run1] = arg.comp[run1];
00155 }
00156 }
00157 else{
00158 comp = NULL;
00159 }
00160
00161 int run2 ;
00162 const int numberOfVariableTypes = 11 ;
00163
00164 entryExists = new BooleanType*[numberOfVariableTypes];
00165 variableIndex = new int*[numberOfVariableTypes];
00166 variableScale = new double*[numberOfVariableTypes];
00167
00168
00169 maxNumberOfEntries = new int[numberOfVariableTypes];
00170
00171 for( run1 = 0; run1 < numberOfVariableTypes; run1++ ){
00172
00173 maxNumberOfEntries[run1] = arg.maxNumberOfEntries[run1];
00174
00175 if( maxNumberOfEntries[run1] > 0 ){
00176 entryExists [run1] = (BooleanType*)calloc(maxNumberOfEntries[run1],
00177 sizeof(BooleanType));
00178 variableIndex [run1] = (int*)calloc(maxNumberOfEntries[run1],
00179 sizeof(int));
00180 variableScale [run1] = (double*)calloc(maxNumberOfEntries[run1],
00181 sizeof(double));
00182 }
00183 else{
00184 entryExists [run1] = 0;
00185 variableIndex[run1] = 0;
00186 variableScale[run1] = 0;
00187 }
00188 for( run2 = 0; run2 < maxNumberOfEntries[run1]; run2++ ){
00189 entryExists [run1][run2] = arg.entryExists [run1][run2];
00190 variableIndex[run1][run2] = arg.variableIndex[run1][run2];
00191 variableScale[run1][run2] = arg.variableScale[run1][run2];
00192 }
00193 }
00194
00195 nC = arg.nC;
00196 cExist = (BooleanType*)calloc( nC, sizeof(BooleanType) );
00197 cIdx = (int**)calloc( nC, sizeof(int*) );
00198 cDim = (uint*)calloc( nC, sizeof(uint) );
00199
00200 for( run1 = 0; run1 < nC; run1++ ){
00201 cExist[run1] = arg.cExist[run1];
00202 cDim[run1] = arg.cDim[run1];
00203 if( arg.cIdx[run1] != 0 ){
00204 cIdx[run1] = new int[cDim[run1]];
00205 for( run2 = 0; run2 < (int) cDim[run1]; run2++ )
00206 cIdx[run1][run2] = arg.cIdx[run1][run2];
00207 }
00208 else{
00209 cIdx[run1] = 0;
00210 }
00211 }
00212
00213 variableCounter = arg.variableCounter;
00214 }
00215
00216
00217
00218 SymbolicIndexList& SymbolicIndexList::operator=( const SymbolicIndexList &arg ){
00219
00220 if( this != &arg ){
00221
00222 int run1;
00223
00224 if( expression != NULL ){
00225 for( run1 = 0; run1 < numberOfOperators; run1++ ){
00226 delete expression[run1];
00227 }
00228 free(expression);
00229 }
00230
00231 if( comp != NULL ){
00232 free(comp);
00233 }
00234
00235 int run2 ;
00236 const int numberOfVariableTypes = 11 ;
00237
00238 for( run1 = 0; run1 < numberOfVariableTypes; run1++ ){
00239
00240 if( maxNumberOfEntries[run1] > 0 ){
00241
00242 free(entryExists [run1]);
00243 free(variableIndex[run1]);
00244 free(variableScale[run1]);
00245 }
00246 }
00247
00248 delete[] maxNumberOfEntries;
00249 delete[] variableIndex;
00250 delete[] variableScale;
00251 delete[] entryExists;
00252
00253 free(cExist);
00254
00255 for( run1 = 0; run1 < nC; run1++ ){
00256 if( cIdx[run1] != 0 )
00257 delete[] cIdx[run1];
00258 }
00259 free(cIdx);
00260 free(cDim);
00261
00262 entryExists = new BooleanType*[numberOfVariableTypes];
00263 variableIndex = new int*[numberOfVariableTypes];
00264 variableScale = new double*[numberOfVariableTypes];
00265
00266 maxNumberOfEntries = new int[numberOfVariableTypes];
00267
00268 for( run1 = 0; run1 < numberOfVariableTypes; run1++ ){
00269
00270 maxNumberOfEntries[run1] = arg.maxNumberOfEntries[run1];
00271
00272 if( maxNumberOfEntries[run1] > 0 ){
00273 entryExists [run1] = (BooleanType*)calloc(maxNumberOfEntries[run1],
00274 sizeof(BooleanType));
00275 variableIndex [run1] = (int*)calloc(maxNumberOfEntries[run1],
00276 sizeof(int));
00277 variableScale [run1] = (double*)calloc(maxNumberOfEntries[run1],
00278 sizeof(double));
00279 }
00280 else{
00281 entryExists [run1] = 0;
00282 variableIndex[run1] = 0;
00283 variableScale[run1] = 0;
00284 }
00285
00286 for( run2 = 0; run2 < maxNumberOfEntries[run1]; run2++ ){
00287 entryExists [run1][run2] = arg.entryExists [run1][run2];
00288 variableIndex[run1][run2] = arg.variableIndex[run1][run2];
00289 variableScale[run1][run2] = arg.variableScale[run1][run2];
00290 }
00291 }
00292
00293 nC = arg.nC;
00294 cExist = (BooleanType*)calloc( nC, sizeof(BooleanType) );
00295 cIdx = (int**)calloc( nC, sizeof(int*) );
00296 cDim = (uint*)calloc( nC, sizeof(uint) );
00297
00298 for( run1 = 0; run1 < nC; run1++ ){
00299 cExist[run1] = arg.cExist[run1];
00300 cDim[run1] = arg.cDim[run1];
00301 if( arg.cIdx[run1] != 0 ){
00302 cIdx[run1] = new int[cDim[run1]];
00303 for( run2 = 0; run2 < (int) cDim[run1]; run2++ )
00304 cIdx[run1][run2] = arg.cIdx[run1][run2];
00305 }
00306 else{
00307 cIdx[run1] = 0;
00308 }
00309 }
00310
00311 variableCounter = arg.variableCounter;
00312
00313 numberOfOperators = arg.numberOfOperators;
00314
00315 if( arg.expression != NULL ){
00316 if( numberOfOperators > 0 ){
00317 expression = (Operator**)calloc(numberOfOperators,sizeof(Operator*));
00318 }
00319 else{
00320 expression = NULL;
00321 }
00322 for( run1 = 0; run1 < numberOfOperators; run1++ ){
00323 expression[run1] = arg.expression[run1]->clone();
00324 }
00325 }
00326 else{
00327 expression = NULL;
00328 }
00329
00330 if( arg.comp != NULL ){
00331 if( numberOfOperators > 0 ){
00332 comp = (int*)calloc(numberOfOperators,sizeof(int));
00333 }
00334 else{
00335 comp = NULL;
00336 }
00337 for( run1 = 0; run1 < numberOfOperators; run1++ ){
00338 comp[run1] = arg.comp[run1];
00339 }
00340 }
00341 else{
00342 comp = NULL;
00343 }
00344
00345 }
00346
00347 return *this;
00348 }
00349
00350
00351
00352
00353
00354
00355
00356 int SymbolicIndexList::addOperatorPointer( Operator* intermediateOperator,
00357 int comp_ ){
00358
00359 expression = (Operator**)realloc(expression,
00360 (numberOfOperators+1)*sizeof(Operator*));
00361 expression[numberOfOperators] = intermediateOperator->clone();
00362
00363 comp = (int*)realloc(comp,(numberOfOperators+1)*sizeof(int));
00364 comp[numberOfOperators] = comp_;
00365
00366 numberOfOperators++;
00367
00368 return numberOfOperators-1;
00369 }
00370
00371
00372 returnValue SymbolicIndexList::getOperators( Operator **sub, int *comp_, int *n ){
00373
00374 while( n[0] < numberOfOperators ){
00375
00376 sub [*n] = expression[*n]->clone();
00377 comp_ [*n] = comp[*n];
00378 *n = *n+1;
00379 }
00380
00381 return SUCCESSFUL_RETURN;
00382 }
00383
00384
00385 BooleanType SymbolicIndexList::addNewElement( VariableType variableType_, int index_ ){
00386
00387 switch(variableType_){
00388
00389 case VT_DIFFERENTIAL_STATE:
00390 if( index_ >= maxNumberOfEntries[0] ){
00391
00392 entryExists[0] = (BooleanType*)realloc(entryExists[0],
00393 (index_+1)*sizeof(BooleanType));
00394 variableIndex[0] = (int*)realloc(variableIndex[0],
00395 (index_+1)*sizeof(int));
00396 variableScale[0] = (double*)realloc(variableScale[0],
00397 (index_+1)*sizeof(double));
00398
00399 int run1;
00400 for( run1 = maxNumberOfEntries[0]; run1 < index_+1; run1++ ){
00401 entryExists[0] [run1] = BT_FALSE;
00402 variableIndex[0][run1] = -1 ;
00403 variableScale[0][run1] = 1.0 ;
00404 }
00405 maxNumberOfEntries[0] = index_+1;
00406 }
00407 if( entryExists[0][index_] == BT_TRUE ){
00408 return BT_FALSE;
00409 }
00410 entryExists[0][index_] = BT_TRUE;
00411 return BT_TRUE;
00412
00413
00414 case VT_ALGEBRAIC_STATE:
00415 if( index_ >= maxNumberOfEntries[1] ){
00416
00417 entryExists[1] = (BooleanType*)realloc(entryExists[1],
00418 (index_+1)*sizeof(BooleanType));
00419 variableIndex[1] = (int*)realloc(variableIndex[1],
00420 (index_+1)*sizeof(int));
00421 variableScale[1] = (double*)realloc(variableScale[1],
00422 (index_+1)*sizeof(double));
00423
00424 int run1;
00425 for( run1 = maxNumberOfEntries[1]; run1 < index_+1; run1++ ){
00426 entryExists[1] [run1] = BT_FALSE;
00427 variableIndex[1][run1] = -1 ;
00428 variableScale[1][run1] = 1.0 ;
00429 }
00430 maxNumberOfEntries[1] = index_+1;
00431 }
00432 if( entryExists[1][index_] == BT_TRUE ){
00433 return BT_FALSE;
00434 }
00435 entryExists[1][index_] = BT_TRUE;
00436 return BT_TRUE;
00437
00438
00439 case VT_CONTROL:
00440 if( index_ >= maxNumberOfEntries[2] ){
00441
00442 entryExists[2] = (BooleanType*)realloc(entryExists[2],
00443 (index_+1)*sizeof(BooleanType));
00444 variableIndex[2] = (int*)realloc(variableIndex[2],
00445 (index_+1)*sizeof(int));
00446 variableScale[2] = (double*)realloc(variableScale[2],
00447 (index_+1)*sizeof(double));
00448
00449 int run1;
00450 for( run1 = maxNumberOfEntries[2]; run1 < index_+1; run1++ ){
00451 entryExists[2] [run1] = BT_FALSE;
00452 variableIndex[2][run1] = -1 ;
00453 variableScale[2][run1] = 1.0 ;
00454 }
00455 maxNumberOfEntries[2] = index_+1;
00456 }
00457 if( entryExists[2][index_] == BT_TRUE ){
00458 return BT_FALSE;
00459 }
00460 entryExists[2][index_] = BT_TRUE;
00461 return BT_TRUE;
00462
00463
00464 case VT_INTEGER_CONTROL:
00465 if( index_ >= maxNumberOfEntries[3] ){
00466
00467 entryExists[3] = (BooleanType*)realloc(entryExists[3],
00468 (index_+1)*sizeof(BooleanType));
00469 variableIndex[3] = (int*)realloc(variableIndex[3],
00470 (index_+1)*sizeof(int));
00471 variableScale[3] = (double*)realloc(variableScale[3],
00472 (index_+1)*sizeof(double));
00473
00474 int run1;
00475 for( run1 = maxNumberOfEntries[3]; run1 < index_+1; run1++ ){
00476 entryExists[3] [run1] = BT_FALSE;
00477 variableIndex[3][run1] = -1 ;
00478 variableScale[3][run1] = 1.0 ;
00479 }
00480 maxNumberOfEntries[3] = index_+1;
00481 }
00482 if( entryExists[3][index_] == BT_TRUE ){
00483 return BT_FALSE;
00484 }
00485 entryExists[3][index_] = BT_TRUE;
00486 return BT_TRUE;
00487
00488
00489 case VT_PARAMETER:
00490 if( index_ >= maxNumberOfEntries[4] ){
00491
00492 entryExists[4] = (BooleanType*)realloc(entryExists[4],
00493 (index_+1)*sizeof(BooleanType));
00494 variableIndex[4] = (int*)realloc(variableIndex[4],
00495 (index_+1)*sizeof(int));
00496 variableScale[4] = (double*)realloc(variableScale[4],
00497 (index_+1)*sizeof(double));
00498
00499 int run1;
00500 for( run1 = maxNumberOfEntries[4]; run1 < index_+1; run1++ ){
00501 entryExists[4] [run1] = BT_FALSE;
00502 variableIndex[4][run1] = -1 ;
00503 variableScale[4][run1] = 1.0 ;
00504 }
00505 maxNumberOfEntries[4] = index_+1;
00506 }
00507 if( entryExists[4][index_] == BT_TRUE ){
00508 return BT_FALSE;
00509 }
00510 entryExists[4][index_] = BT_TRUE;
00511 return BT_TRUE;
00512
00513
00514 case VT_INTEGER_PARAMETER:
00515 if( index_ >= maxNumberOfEntries[5] ){
00516
00517 entryExists[5] = (BooleanType*)realloc(entryExists[5],
00518 (index_+1)*sizeof(BooleanType));
00519 variableIndex[5] = (int*)realloc(variableIndex[5],
00520 (index_+1)*sizeof(int));
00521 variableScale[5] = (double*)realloc(variableScale[5],
00522 (index_+1)*sizeof(double));
00523
00524 int run1;
00525 for( run1 = maxNumberOfEntries[5]; run1 < index_+1; run1++ ){
00526 entryExists[5] [run1] = BT_FALSE;
00527 variableIndex[5][run1] = -1 ;
00528 }
00529 maxNumberOfEntries[5] = index_+1;
00530 }
00531 if( entryExists[5][index_] == BT_TRUE ){
00532 return BT_FALSE;
00533 }
00534 entryExists[5][index_] = BT_TRUE;
00535 return BT_TRUE;
00536
00537
00538 case VT_DISTURBANCE:
00539 if( index_ >= maxNumberOfEntries[6] ){
00540
00541 entryExists[6] = (BooleanType*)realloc(entryExists[6],
00542 (index_+1)*sizeof(BooleanType));
00543 variableIndex[6] = (int*)realloc(variableIndex[6],
00544 (index_+1)*sizeof(int));
00545 variableScale[6] = (double*)realloc(variableScale[6],
00546 (index_+1)*sizeof(double));
00547
00548 int run1;
00549 for( run1 = maxNumberOfEntries[6]; run1 < index_+1; run1++ ){
00550 entryExists[6] [run1] = BT_FALSE;
00551 variableIndex[6][run1] = -1 ;
00552 variableScale[6][run1] = 1.0 ;
00553 }
00554 maxNumberOfEntries[6] = index_+1;
00555 }
00556 if( entryExists[6][index_] == BT_TRUE ){
00557 return BT_FALSE;
00558 }
00559 entryExists[6][index_] = BT_TRUE;
00560 return BT_TRUE;
00561
00562
00563 case VT_TIME:
00564 if( index_ >= maxNumberOfEntries[7] ){
00565
00566 entryExists[7] = (BooleanType*)realloc(entryExists[7],
00567 (index_+1)*sizeof(BooleanType));
00568 variableIndex[7] = (int*)realloc(variableIndex[7],
00569 (index_+1)*sizeof(int));
00570 variableScale[7] = (double*)realloc(variableScale[7],
00571 (index_+1)*sizeof(double));
00572
00573 int run1;
00574 for( run1 = maxNumberOfEntries[7]; run1 < index_+1; run1++ ){
00575 entryExists[7] [run1] = BT_FALSE;
00576 variableIndex[7][run1] = -1 ;
00577 variableScale[7][run1] = 1.0 ;
00578 }
00579 maxNumberOfEntries[7] = index_+1;
00580 }
00581 if( entryExists[7][index_] == BT_TRUE ){
00582 return BT_FALSE;
00583 }
00584 entryExists[7][index_] = BT_TRUE;
00585 return BT_TRUE;
00586
00587
00588 case VT_INTERMEDIATE_STATE:
00589 if( index_ >= maxNumberOfEntries[8] ){
00590
00591 entryExists[8] = (BooleanType*)realloc(entryExists[8],
00592 (index_+1)*sizeof(BooleanType));
00593 variableIndex[8] = (int*)realloc(variableIndex[8],
00594 (index_+1)*sizeof(int));
00595 variableScale[8] = (double*)realloc(variableScale[8],
00596 (index_+1)*sizeof(double));
00597
00598 int run1;
00599 for( run1 = maxNumberOfEntries[8]; run1 < index_+1; run1++ ){
00600 entryExists[8] [run1] = BT_FALSE;
00601 variableIndex[8][run1] = -1 ;
00602 variableScale[8][run1] = 1.0 ;
00603 }
00604 maxNumberOfEntries[8] = index_+1;
00605 }
00606 if( entryExists[8][index_] == BT_TRUE ){
00607 return BT_FALSE;
00608 }
00609
00610 entryExists[8][index_] = BT_TRUE;
00611 return BT_TRUE;
00612
00613
00614 case VT_DDIFFERENTIAL_STATE:
00615 if( index_ >= maxNumberOfEntries[9] ){
00616
00617 entryExists[9] = (BooleanType*)realloc(entryExists[9],
00618 (index_+1)*sizeof(BooleanType));
00619 variableIndex[9] = (int*)realloc(variableIndex[9],
00620 (index_+1)*sizeof(int));
00621 variableScale[9] = (double*)realloc(variableScale[9],
00622 (index_+1)*sizeof(double));
00623
00624 int run1;
00625 for( run1 = maxNumberOfEntries[9]; run1 < index_+1; run1++ ){
00626 entryExists[9] [run1] = BT_FALSE;
00627 variableIndex[9][run1] = -1 ;
00628 variableScale[9][run1] = 1.0 ;
00629 }
00630 maxNumberOfEntries[9] = index_+1;
00631 }
00632 if( entryExists[9][index_] == BT_TRUE ){
00633 return BT_FALSE;
00634 }
00635 entryExists[9][index_] = BT_TRUE;
00636 return BT_TRUE;
00637
00638 case VT_ONLINE_DATA:
00639 if( index_ >= maxNumberOfEntries[10] ){
00640
00641 entryExists[10] = (BooleanType*)realloc(entryExists[10],
00642 (index_+1)*sizeof(BooleanType));
00643 variableIndex[10] = (int*)realloc(variableIndex[10],
00644 (index_+1)*sizeof(int));
00645 variableScale[10] = (double*)realloc(variableScale[10],
00646 (index_+1)*sizeof(double));
00647
00648 int run1;
00649 for( run1 = maxNumberOfEntries[10]; run1 < index_+1; run1++ ){
00650 entryExists[10] [run1] = BT_FALSE;
00651 variableIndex[10][run1] = -1 ;
00652 variableScale[10][run1] = 1.0 ;
00653 }
00654 maxNumberOfEntries[10] = index_+1;
00655 }
00656 if( entryExists[10][index_] == BT_TRUE ){
00657 return BT_FALSE;
00658 }
00659 entryExists[10][index_] = BT_TRUE;
00660 return BT_TRUE;
00661
00662 default: return BT_FALSE;
00663
00664 }
00665
00666 return BT_FALSE;
00667 }
00668
00669 BooleanType SymbolicIndexList::determineCExpressionIndices( uint dimension,
00670 uint ID ,
00671 int *idx ){
00672
00673 uint run1;
00674
00675 if( nC <= (int) ID ){
00676 uint nnn = nC;
00677 nC = ID+1;
00678 cExist = (BooleanType*)realloc(cExist,(ID+1)*sizeof(BooleanType));
00679 cIdx = (int**)realloc(cIdx,(ID+1)*sizeof(int*));
00680 cDim = (uint*)realloc(cDim,(ID+1)*sizeof(uint));
00681
00682 for( run1 = nnn; run1 < ID+1; run1++ ){
00683 cExist[run1] = BT_FALSE;
00684 cIdx[run1] = 0;
00685 cDim [run1] = 0;
00686 }
00687 }
00688
00689 if( cExist[ID] == BT_FALSE ){
00690 cDim[ID] = dimension;
00691 cIdx[ID] = new int[dimension];
00692 for( run1 = 0; run1 < dimension; run1++ ){
00693 cIdx[ID][run1] = variableCounter;
00694 idx[run1] = variableCounter;
00695 variableCounter++;
00696 }
00697 cExist[ID] = BT_TRUE;
00698 return BT_TRUE;
00699 }
00700 else{
00701 for( run1 = 0; run1 < cDim[ID]; run1++ )
00702 idx[run1] = cIdx[ID][run1];
00703 return BT_FALSE;
00704 }
00705 }
00706
00707
00708 int SymbolicIndexList::determineVariableIndex( VariableType variableType_, int index_, double scale_ ){
00709
00710 switch(variableType_){
00711
00712 case VT_DIFFERENTIAL_STATE:
00713 if( index_ >= maxNumberOfEntries[0] ){
00714
00715 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00716 return -1;
00717 }
00718 if( variableIndex[0][index_] == -1 ){
00719 variableIndex[0][index_] = variableCounter;
00720 variableScale[0][index_] = scale_;
00721 variableCounter++;
00722 return variableIndex[0][index_];
00723 }
00724 return variableIndex[0][index_];
00725
00726 case VT_ALGEBRAIC_STATE:
00727 if( index_ >= maxNumberOfEntries[1] ){
00728
00729 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00730 return -1;
00731 }
00732 if( variableIndex[1][index_] == -1 ){
00733 variableIndex[1][index_] = variableCounter;
00734 variableScale[1][index_] = scale_;
00735 variableCounter++;
00736 return variableIndex[1][index_];
00737 }
00738 return variableIndex[1][index_];
00739
00740
00741 case VT_CONTROL:
00742 if( index_ >= maxNumberOfEntries[2] ){
00743
00744 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00745 return -1;
00746 }
00747 if( variableIndex[2][index_] == -1 ){
00748 variableIndex[2][index_] = variableCounter;
00749 variableScale[2][index_] = scale_;
00750 variableCounter++;
00751 return variableIndex[2][index_];
00752 }
00753 return variableIndex[2][index_];
00754
00755
00756 case VT_INTEGER_CONTROL:
00757 if( index_ >= maxNumberOfEntries[3] ){
00758
00759 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00760 return -1;
00761 }
00762 if( variableIndex[3][index_] == -1 ){
00763 variableIndex[3][index_] = variableCounter;
00764 variableScale[3][index_] = scale_;
00765 variableCounter++;
00766 return variableIndex[3][index_];
00767 }
00768 return variableIndex[3][index_];
00769
00770
00771 case VT_PARAMETER:
00772 if( index_ >= maxNumberOfEntries[4] ){
00773
00774 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00775 return -1;
00776 }
00777 if( variableIndex[4][index_] == -1 ){
00778 variableIndex[4][index_] = variableCounter;
00779 variableScale[4][index_] = scale_;
00780 variableCounter++;
00781 return variableIndex[4][index_];
00782 }
00783 return variableIndex[4][index_];
00784
00785
00786 case VT_INTEGER_PARAMETER:
00787 if( index_ >= maxNumberOfEntries[5] ){
00788
00789 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00790 return -1;
00791 }
00792 if( variableIndex[5][index_] == -1 ){
00793 variableIndex[5][index_] = variableCounter;
00794 variableScale[5][index_] = scale_;
00795 variableCounter++;
00796 return variableIndex[5][index_];
00797 }
00798 return variableIndex[5][index_];
00799
00800
00801 case VT_DISTURBANCE:
00802 if( index_ >= maxNumberOfEntries[6] ){
00803
00804 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00805 return -1;
00806 }
00807 if( variableIndex[6][index_] == -1 ){
00808 variableIndex[6][index_] = variableCounter;
00809 variableScale[6][index_] = scale_;
00810 variableCounter++;
00811 return variableIndex[6][index_];
00812 }
00813 return variableIndex[6][index_];
00814
00815
00816 case VT_TIME:
00817 if( index_ >= maxNumberOfEntries[7] ){
00818
00819 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00820 return -1;
00821 }
00822 if( variableIndex[7][index_] == -1 ){
00823 variableIndex[7][index_] = variableCounter;
00824 variableScale[7][index_] = scale_;
00825 variableCounter++;
00826 return variableIndex[7][index_];
00827 }
00828 return variableIndex[7][index_];
00829
00830
00831 case VT_INTERMEDIATE_STATE:
00832 if( index_ >= maxNumberOfEntries[8] ){
00833
00834 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00835 return -1;
00836 }
00837 if( variableIndex[8][index_] == -1 ){
00838 variableIndex[8][index_] = variableCounter;
00839 variableScale[8][index_] = scale_;
00840 variableCounter++;
00841 return variableIndex[8][index_];
00842 }
00843 return variableIndex[8][index_];
00844
00845
00846 case VT_DDIFFERENTIAL_STATE:
00847 if( index_ >= maxNumberOfEntries[9] ){
00848
00849 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00850 return -1;
00851 }
00852 if( variableIndex[9][index_] == -1 ){
00853 variableIndex[9][index_] = variableCounter;
00854 variableScale[9][index_] = scale_;
00855 variableCounter++;
00856 return variableIndex[9][index_];
00857 }
00858 return variableIndex[9][index_];
00859
00860 case VT_ONLINE_DATA:
00861 if( index_ >= maxNumberOfEntries[10] ){
00862
00863 ACADOERROR(RET_INDEX_OUT_OF_RANGE);
00864 return -1;
00865 }
00866 if( variableIndex[10][index_] == -1 ){
00867 variableIndex[10][index_] = variableCounter;
00868 variableScale[10][index_] = scale_;
00869 variableCounter++;
00870 return variableIndex[10][index_];
00871 }
00872 return variableIndex[10][index_];
00873
00874
00875 default: return -1;
00876 }
00877
00878 return -1;
00879 }
00880
00881
00882 returnValue SymbolicIndexList::clearVariableIndexList(){
00883
00884 int run1, run2 ;
00885 const int numberOfVariableTypes = 11;
00886
00887 variableCounter = 0;
00888
00889 for( run1 = 0; run1 < numberOfVariableTypes; run1++ ){
00890 for( run2 = 0; run2 < maxNumberOfEntries[run1]; run2++ ){
00891 variableIndex [run1][run2] = -1;
00892 }
00893 }
00894
00895 return SUCCESSFUL_RETURN;
00896 }
00897
00898
00899
00900 CLOSE_NAMESPACE_ACADO
00901
00902