00001
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <iostream>
00051 #include "OSiLWriter.h"
00052 #include "OSnl2osil.h"
00053 #include "OSErrorClass.h"
00054
00055 #include "CoinHelperFunctions.hpp"
00056
00057
00058 #include "nlp.h"
00059 #include "getstub.h"
00060 #include "r_opn.hd"
00061 #include "opcode.hd"
00062
00063
00064 #ifdef HAVE_CMATH
00065 # include <cmath>
00066 #else
00067 # ifdef HAVE_CMATH_H
00068 # include <cmath.h>
00069 # endif
00070 #endif
00071
00072
00073
00074 #define R_OPS ((ASL_fg*)asl)->I.r_ops_
00075 #define OBJ_DE ((ASL_fg*)asl)->I.obj_de_
00076 #define VAR_E ((ASL_fg*)asl)->I.var_e_
00077 #define CON_DE ((ASL_fg*)asl)->I.con_de_
00078
00079 efunc *r_ops_int[N_OPS];
00080
00081 #include <asl.h>
00082
00083 using std::cerr;
00084 using std::cout;
00085 using std::endl;
00086
00087 #ifdef HAVE_STDINT_H
00088 #include <stdint.h>
00089 #endif
00090
00091
00092
00093 OSnl2osil::OSnl2osil(std::string nlfilename){
00094
00095 asl = ASL_alloc( ASL_read_fg);
00096 stub = &nlfilename[ 0];
00097
00098
00099 nl = jac0dim(stub, (fint)strlen(stub));
00100
00101 A_vals = (real *)Malloc(nzc*sizeof(real));
00102
00103 #ifdef AMPLDEBUG
00104 cout << "number of nonzeros = " << nzc << endl;
00105 cout << "number of variable = " << n_var << endl;
00106 cout << "number of constraints = " << n_con << endl;
00107 cout << "number of objs = " << n_obj << endl;
00108 cout << "number of ranges = " << nranges << endl;
00109 cout << "number of equations = " << n_eqn << endl;
00110
00111 #endif
00112 #ifdef AMPLDEBUG
00113 cout << "Start f_read()" << endl;
00114 #endif
00115 X0 = (real *)Malloc( n_var*sizeof(real));
00116 if(N_OPS > 0){
00117 for(int i = 0; i < N_OPS; i++){
00118 r_ops_int[i] = (efunc*)(unsigned long)i;
00119
00120 }
00121 R_OPS = r_ops_int;
00122 want_derivs = 0;
00123 fg_read(nl, 0);
00124 R_OPS = 0;
00125 }
00126 }
00127
00128 OSnl2osil::~OSnl2osil(){
00129 osinstance->instanceData->linearConstraintCoefficients->start->bDeleteArrays = false;
00130 osinstance->instanceData->linearConstraintCoefficients->rowIdx->bDeleteArrays = false;
00131 osinstance->instanceData->linearConstraintCoefficients->value->bDeleteArrays = false;
00132 delete osinstance;
00133 osinstance = NULL;
00134 free( X0);
00135 free( A_vals);
00136 ASL_free(&asl);
00137
00138 }
00139
00140 OSnLNode* OSnl2osil::walkTree (expr *e){
00141 OSnLNode *nlNodePoint;
00142 OSnLNodeVariable *nlNodeVariablePoint;
00143 OSnLNodeNumber *nlNodeNumberPoint;
00144 efunc *op;
00145 expr **ep;
00146 int opnum;
00147 int i;
00148
00149 int j = ((expr_v *)e - VAR_E) - osinstance->getVariableNumber() ;
00150
00151 op = e->op;
00152 opnum = Intcast op;
00153
00154
00155 try{
00156 switch( opnum) {
00157 case OPPLUS:
00158
00159 nlNodePoint = new OSnLNodePlus();
00160 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00161 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00162 return nlNodePoint;
00163
00164 case OPSUMLIST:
00165 i = 0;
00166
00167 nlNodePoint = new OSnLNodeSum();
00168 nlNodePoint->inumberOfChildren = e->R.ep - e->L.ep;
00169 nlNodePoint->m_mChildren = new OSnLNode*[ e->R.ep - e->L.ep];
00170 for (ep = e->L.ep; ep < e->R.ep; *ep++)
00171 nlNodePoint->m_mChildren[i++] = walkTree ( *ep);
00172 return nlNodePoint;
00173
00174 case MAXLIST:
00175 i = 0;
00176
00177 nlNodePoint = new OSnLNodeMax();
00178 nlNodePoint->inumberOfChildren = e->R.ep - e->L.ep;
00179 nlNodePoint->m_mChildren = new OSnLNode*[ e->R.ep - e->L.ep];
00180 for (ep = e->L.ep; ep < e->R.ep; *ep++)
00181 nlNodePoint->m_mChildren[i++] = walkTree ( *ep);
00182 return nlNodePoint;
00183
00184 case OPMINUS:
00185 nlNodePoint = new OSnLNodeMinus();
00186 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00187 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00188 return nlNodePoint;
00189
00190 case OPUMINUS:
00191 nlNodePoint = new OSnLNodeNegate();
00192 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00193 return nlNodePoint;
00194
00195 case OPMULT:
00196
00197 nlNodePoint = new OSnLNodeTimes();
00198 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00199 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00200 return nlNodePoint;
00201
00202 case OPDIV:
00203 nlNodePoint = new OSnLNodeDivide();
00204 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00205 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00206 return nlNodePoint;
00207
00208 case OPPOW:
00209
00210 nlNodePoint = new OSnLNodePower();
00211 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00212 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00213 return nlNodePoint;
00214
00215
00216 case OP1POW:
00217
00218
00219 nlNodePoint = new OSnLNodePower();
00220 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00221 nlNodeNumberPoint = new OSnLNodeNumber();
00222 nlNodeNumberPoint->value = e->R.en->v;
00223 nlNodePoint->m_mChildren[1] = nlNodeNumberPoint;
00224 return nlNodePoint;
00225
00226 case OP2POW:
00227
00228
00229
00230
00231
00232
00233 nlNodePoint = new OSnLNodeSquare();
00234 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00235 return nlNodePoint;
00236
00237 case OPCPOW:
00238
00239
00240 nlNodePoint = new OSnLNodePower();
00241 nlNodeNumberPoint = new OSnLNodeNumber();
00242 nlNodeNumberPoint->value = e->L.en->v;
00243 nlNodePoint->m_mChildren[0] = nlNodeNumberPoint;
00244 nlNodePoint->m_mChildren[1] = walkTree (e->R.e);
00245 return nlNodePoint;
00246
00247 case OP_log:
00248 nlNodePoint = new OSnLNodeLn();
00249 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00250 return nlNodePoint;
00251
00252 case OP_sqrt:
00253 nlNodePoint = new OSnLNodeSqrt();
00254 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00255 return nlNodePoint;
00256
00257 case OP_cos:
00258 nlNodePoint = new OSnLNodeCos();
00259 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00260 return nlNodePoint;
00261
00262 case OP_sin:
00263 nlNodePoint = new OSnLNodeSin();
00264 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00265 return nlNodePoint;
00266
00267 case OP_exp:
00268 nlNodePoint = new OSnLNodeExp();
00269 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00270 return nlNodePoint;
00271
00272 case ABS:
00273 nlNodePoint = new OSnLNodeAbs();
00274 nlNodePoint->m_mChildren[0] = walkTree (e->L.e);
00275 return nlNodePoint;
00276
00277 case OPNUM:
00278
00279 nlNodeNumberPoint = new OSnLNodeNumber;
00280
00281 nlNodeNumberPoint->value = (double) ((expr_n*)e)->v;
00282 return nlNodeNumberPoint;
00283
00284 case OPVARVAL:
00285
00286
00287 if( j >= 0 ){
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 if(j < ncom0){
00299 struct cexp *common = ((const ASL_fg *) asl) -> I.cexps_ + j ;
00300
00301
00302
00303 int nlin = common -> nlin;
00304
00305
00306 if( nlin > 0) {
00307 nlNodePoint = new OSnLNodeSum();
00308 nlNodePoint->inumberOfChildren = nlin + 1;
00309 nlNodePoint->m_mChildren = new OSnLNode*[ nlin + 1];
00310
00311
00312 linpart *L = common -> L;
00313 for(int kj = 0; kj < nlin; kj++) {
00314
00315
00316
00317
00318
00319
00320
00321 nlNodePoint->m_mChildren[ kj] = new OSnLNodeVariable;
00322 nlNodeVariablePoint = (OSnLNodeVariable*)nlNodePoint->m_mChildren[ kj];
00323 nlNodeVariablePoint->coef = L [kj]. fac;
00324 nlNodeVariablePoint->idx = ((uintptr_t) (L [kj].v.rp) - (uintptr_t) VAR_E) / sizeof (expr_v);
00325 }
00326 nlNodePoint->m_mChildren[ nlin] = walkTree( common->e);
00327 return nlNodePoint;
00328 }
00329 else return walkTree( common->e);
00330 }
00331 else{
00332 struct cexp1 *common = ((const ASL_fg *) asl) -> I.cexps1_ + (j - ncom0);
00333
00334
00335
00336 int nlin = common -> nlin;
00337
00338
00339 if( nlin > 0) {
00340 nlNodePoint = new OSnLNodeSum();
00341 nlNodePoint->inumberOfChildren = nlin + 1;
00342 nlNodePoint->m_mChildren = new OSnLNode*[ nlin + 1];
00343
00344
00345 linpart *L = common -> L;
00346 for(int kj = 0; kj < nlin; kj++) {
00347
00348
00349
00350
00351
00352
00353
00354 nlNodePoint->m_mChildren[ kj] = new OSnLNodeVariable;
00355 nlNodeVariablePoint = (OSnLNodeVariable*)nlNodePoint->m_mChildren[ kj];
00356 nlNodeVariablePoint->coef = L [kj]. fac;
00357 nlNodeVariablePoint->idx = ((uintptr_t) (L [kj].v.rp) - (uintptr_t) VAR_E) / sizeof (expr_v);
00358 }
00359 nlNodePoint->m_mChildren[ nlin] = walkTree( common->e);
00360 return nlNodePoint;
00361 }
00362 else return walkTree( common->e);
00363 }
00364 }
00365
00366 nlNodeVariablePoint = new OSnLNodeVariable;
00367 nlNodeVariablePoint->idx = e->a;
00368 nlNodeVariablePoint->coef = 1.0;
00369 return nlNodeVariablePoint;
00370 break;
00371 default:
00372 std::ostringstream outStr;
00373 std::string error;
00374 outStr << endl;
00375 outStr << endl;
00376 error = "ERROR: An unsupported operator found, AMPL operator number = " ;
00377 outStr << error;
00378 outStr << opnum;
00379 outStr << endl;
00380 error = outStr.str();
00381 throw ErrorClass( error );
00382 }
00383 }
00384 catch(const ErrorClass& eclass){
00385 throw;
00386 }
00387 }
00388
00389
00390 bool OSnl2osil::createOSInstance(){
00391 osinstance = new OSInstance();
00392 int i, j;
00393
00394
00395 osinstance->setInstanceDescription("Generated from AMPL nl file");
00396
00397
00398
00399
00400
00401 std::string colName;
00402 char vartype = 'C';
00403 osinstance->setVariableNumber( n_var);
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 int lower;
00426 int upper;
00427 lower = 0;
00428 upper = nlvb - nlvbi;
00429 #ifdef AMPLDEBUG
00430 std::cout << "LOWER = " << lower << std::endl;
00431 std::cout << "UPPER = " << upper << std::endl;
00432 #endif
00433 for(i = lower; i < upper; i++){
00434 vartype = 'C';
00435 osinstance->addVariable(i, var_name(i),
00436 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00437 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00438 vartype);
00439 }
00440
00441 lower = nlvb - nlvbi;
00442 upper = (nlvb - nlvbi) + nlvbi;
00443 upper = nlvb;
00444 #ifdef AMPLDEBUG
00445 std::cout << "LOWER = " << lower << std::endl;
00446 std::cout << "UPPER = " << upper << std::endl;
00447 #endif
00448 for(i = lower; i < upper; i++){
00449 vartype = 'I';
00450 osinstance->addVariable(i, var_name(i),
00451 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00452 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00453 vartype);
00454 }
00455
00456 lower = nlvb;
00457 upper = nlvb + (nlvc - (nlvb + nlvci)) ;
00458 upper = nlvc - nlvci;
00459 #ifdef AMPLDEBUG
00460 std::cout << "LOWER = " << lower << std::endl;
00461 std::cout << "UPPER = " << upper << std::endl;
00462 #endif
00463 for(i = lower; i < upper; i++){
00464 vartype = 'C';
00465 osinstance->addVariable(i, var_name(i),
00466 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00467 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00468 vartype);
00469 }
00470
00471
00472 lower = nlvc - nlvci;
00473 upper = nlvc - nlvci + nlvci;
00474 upper = nlvc;
00475 #ifdef AMPLDEBUG
00476 std::cout << "LOWER = " << lower << std::endl;
00477 std::cout << "UPPER = " << upper << std::endl;
00478 #endif
00479 for(i = lower; i < upper; i++){
00480 vartype = 'I';
00481 osinstance->addVariable(i, var_name(i),
00482 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00483 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00484 vartype);
00485 }
00486
00487 lower = nlvc;
00488 upper = nlvc + ( nlvo - (nlvc + nlvoi) );
00489 upper = nlvo - nlvoi;
00490 #ifdef AMPLDEBUG
00491 std::cout << "LOWER = " << lower << std::endl;
00492 std::cout << "UPPER = " << upper << std::endl;
00493 #endif
00494 for(i = lower; i < upper; i++){
00495 vartype = 'C';
00496 osinstance->addVariable(i, var_name(i),
00497 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00498 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00499 vartype);
00500 }
00501
00502 lower = nlvo - nlvoi;
00503 upper = nlvo - nlvoi + nlvoi;
00504 upper = nlvo ;
00505 #ifdef AMPLDEBUG
00506 std::cout << "LOWER = " << lower << std::endl;
00507 std::cout << "UPPER = " << upper << std::endl;
00508 #endif
00509 for(i = lower; i < upper; i++){
00510 vartype = 'I';
00511 osinstance->addVariable(i, var_name(i),
00512 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00513 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00514 vartype);
00515 }
00516
00517
00518
00519
00520 lower = CoinMax(nlvc, nlvo);
00521 upper = CoinMax(nlvc, nlvo) + nwv;
00522 #ifdef AMPLDEBUG
00523 std::cout << "LOWER = " << lower << std::endl;
00524 std::cout << "UPPER = " << upper << std::endl;
00525 #endif
00526 for(i = lower; i < upper; i++){
00527 vartype = 'C';
00528 osinstance->addVariable(i, var_name(i),
00529 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00530 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00531 vartype);
00532 }
00533
00534
00535 lower = CoinMax(nlvc, nlvo) + nwv;
00536 upper = CoinMax(nlvc, nlvo) + nwv + (n_var - (CoinMax(nlvc, nlvo) + niv + nbv + nwv) );
00537 upper = n_var - niv - nbv;
00538 #ifdef AMPLDEBUG
00539 std::cout << "LOWER = " << lower << std::endl;
00540 std::cout << "UPPER = " << upper << std::endl;
00541 #endif
00542 for(i = lower; i < upper; i++){
00543 vartype = 'C';
00544 osinstance->addVariable(i, var_name(i),
00545 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00546 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00547 vartype);
00548 }
00549
00550
00551 lower = n_var - niv - nbv;
00552 upper = n_var - niv - nbv + nbv;
00553 upper = n_var - niv ;
00554 #ifdef AMPLDEBUG
00555 std::cout << "LOWER = " << lower << std::endl;
00556 std::cout << "UPPER = " << upper << std::endl;
00557 #endif
00558 for(i = lower; i < upper; i++){
00559 vartype = 'B';
00560 osinstance->addVariable(i, var_name(i),
00561 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00562 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00563 vartype);
00564 }
00565
00566
00567
00568 lower = n_var - niv;
00569 upper = n_var - niv + niv;
00570 upper = n_var;
00571 #ifdef AMPLDEBUG
00572 std::cout << "LOWER = " << lower << std::endl;
00573 std::cout << "UPPER = " << upper << std::endl;
00574 #endif
00575 for(i = lower; i < upper; i++){
00576 vartype = 'I';
00577 osinstance->addVariable(i, var_name(i),
00578 LUv[2*i] > -OSDBL_MAX ? LUv[2*i] : -OSDBL_MAX,
00579 LUv[2*i+1] < OSDBL_MAX ? LUv[2*i+1] : OSDBL_MAX,
00580 vartype);
00581 }
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 double objWeight = 1.0;
00598
00599 std::string objName="";
00600 SparseVector* objectiveCoefficients = NULL;
00601
00602 osinstance->setObjectiveNumber( n_obj) ;
00603 for(i = 0; i < n_obj; i++){
00604 int n_obj_coef = 0;
00605 for(og = Ograd[i]; og; og = og->next){
00606 if (og->coef != 0) n_obj_coef++;
00607 }
00608 objectiveCoefficients = new SparseVector( n_obj_coef);
00609 int i_obj_coef = -1;
00610 for(og = Ograd[i]; og; og = og->next){
00611 if (fabs(og->coef) > OS_EPS) {
00612 i_obj_coef++;
00613 objectiveCoefficients->values[i_obj_coef] = og->coef;
00614 objectiveCoefficients->indexes[i_obj_coef] = og->varno;
00615 }
00616 }
00617 osinstance->addObjective(-n_obj + i, objName,
00618 (objtype[i] == 1)?"max":"min",
00619 objconst( i), objWeight, objectiveCoefficients) ;
00620 delete objectiveCoefficients;
00621 objectiveCoefficients = NULL;
00622 }
00623
00624
00625
00626 osinstance->setConstraintNumber( n_con);
00627
00628 double constant = 0.0;
00629 std::string rowName;
00630 for(i = 0; i < n_con; i++)
00631 {
00632 osinstance->addConstraint(i, con_name(i),
00633 LUrhs[2*i] > -OSDBL_MAX ? LUrhs[2*i] : -OSDBL_MAX,
00634 LUrhs[2*i+1] < OSDBL_MAX ? LUrhs[2*i+1] : OSDBL_MAX,
00635 constant);
00636 }
00637
00638
00639
00640 int colStart, colEnd, nCoefSqueezed;
00641 nCoefSqueezed = 0;
00642
00643 #ifdef AMPLDEBUG
00644 cout << "A-matrix elements: ";
00645 for (i = 0; i < A_colstarts[ n_var]; i++)
00646 cout << A_vals[i] << " ";
00647 cout << endl;
00648 cout << "A-matrix rowinfo: ";
00649 for (i = 0; i < A_colstarts[ n_var]; i++)
00650 cout << A_rownos[i] << " ";
00651 cout << endl;
00652 cout << "A-matrix colstart: ";
00653 for (i = 0; i <= n_var; i++)
00654 cout << A_colstarts[i] << " ";
00655 cout << endl;
00656 #endif
00657
00658 colEnd = 0;
00659 for (i = 0; i < n_var; i++)
00660 {
00661 colStart = colEnd;
00662 colEnd = A_colstarts[i+1];
00663 #ifdef AMPLDEBUG
00664 cout << "col " << i << " from " << colStart << " to " << colEnd - 1 << endl;
00665 #endif
00666 for (j = colStart; j < colEnd; j++)
00667 {
00668 if (fabs(A_vals[ j]) > OS_EPS)
00669 { A_vals[ j-nCoefSqueezed] = A_vals[ j];
00670 A_rownos[ j-nCoefSqueezed] = A_rownos[j];
00671 }
00672 else {
00673 #ifdef AMPLDEBUG
00674 cout << "squeeze out element " << j << endl;
00675 #endif
00676 nCoefSqueezed++;
00677 }
00678 }
00679 A_colstarts[i+1] = A_colstarts[i+1] - nCoefSqueezed;
00680 }
00681
00682 #ifdef AMPLDEBUG
00683 cout << "A-matrix elements: ";
00684 for (i = 0; i < A_colstarts[ n_var]; i++)
00685 cout << A_vals[i] << " ";
00686 cout << endl;
00687 cout << "A-matrix rowinfo: ";
00688 for (i = 0; i < A_colstarts[ n_var]; i++)
00689 cout << A_rownos[i] << " ";
00690 cout << endl;
00691 cout << "A-matrix colstart: ";
00692 for (i = 0; i <= n_var; i++)
00693 cout << A_colstarts[i] << " ";
00694 cout << endl;
00695 cout << "A-matrix nonzeroes: " << A_colstarts[ n_var] << "; nsqueezed: " << nCoefSqueezed << endl;
00696 #endif
00697
00698 if(A_colstarts[ n_var] > 0){
00699 osinstance->setLinearConstraintCoefficients(A_colstarts[ n_var], true,
00700 A_vals, 0, A_colstarts[n_var] - 1,
00701 A_rownos, 0, A_colstarts[n_var] - 1,
00702 A_colstarts, 0, n_var);
00703 }
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729 if((nlc + nlo) > 0){
00730 OSnLNode* m_treeRoot;
00731
00732
00733 osinstance->instanceData->nonlinearExpressions->numberOfNonlinearExpressions = nlc + nlo;
00734 osinstance->instanceData->nonlinearExpressions->nl = new Nl*[ nlc + nlo ];
00735 int iNLidx = 0;
00736
00737 if(nlc > 0){
00738 while (iNLidx < nlc) {
00739 m_treeRoot = walkTree ((CON_DE + iNLidx)->e);
00740 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx] = new Nl();
00741 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->idx = iNLidx;
00742 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree = new OSExpressionTree();
00743 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree->m_treeRoot = m_treeRoot;
00744 iNLidx++;
00745
00746 }
00747 }
00748
00749 if(nlo > 0){
00750 while ( iNLidx < nlc + nlo){
00751 m_treeRoot = walkTree ((OBJ_DE + iNLidx - nlc)->e);
00752
00753 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx] = new Nl();
00754 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->idx = -1 - (iNLidx - nlc);
00755 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree = new OSExpressionTree();
00756 osinstance->instanceData->nonlinearExpressions->nl[ iNLidx]->osExpressionTree->m_treeRoot = m_treeRoot;
00757 iNLidx++;
00758
00759 }
00760 }
00761
00762
00763
00764 }
00765
00766
00767
00768
00769
00770 #ifdef AMPLDEBUG
00771 OSiLWriter osilwriter;
00772 std::cout << "WRITE THE INSTANCE" << std::endl;
00773 osilwriter.m_bWhiteSpace = true;
00774 std::cout << osilwriter.writeOSiL( osinstance) << std::endl;
00775 std::cout << "DONE WRITE THE INSTANCE" << std::endl;
00776
00777 std::cout << osinstance->printModel() << std::endl;
00778
00779 #endif
00780
00781 return true;
00782 }