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